RefreshExplorer() : Refresh all open Windows explorer + Desktop

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

RefreshExplorer() : Refresh all open Windows explorer + Desktop

13 May 2020, 11:19

Better version by @teadrinker
 

Code: Select all

RefreshExplorer() { ; by teadrinker on D437 @ tiny.cc/refreshexplorer
   local Windows := ComObjCreate("Shell.Application").Windows
   Windows.Item(ComObject(0x13, 8)).Refresh()
   for Window in Windows
      if (Window.Name != "Internet Explorer")
         Window.Refresh()
}
 
Older version:

Code: Select all

RefreshExplorer() {                ; By SKAN on D35D @ tiny.cc/refreshexplorer
Local Window
   ComObjCreate("Shell.Application").Windows.Item(ComObject(0x13,8)).Refresh()
   For  Window in ComObjCreate("Shell.Application").Windows
   If ( Window.Name="Windows Explorer" or Window.Name="File Explorer" ) 
        Window.Refresh()
}


Same effect as pressing F5 button on Desktop, Windows Explorer and Internet Explorer. (Omitted IE from the function, though)
My Scripts and Functions: V1  V2
iseahound
Posts: 1451
Joined: 13 Aug 2016, 21:04
Contact:

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

13 May 2020, 19:15

How does it compare to this archaic function?

Code: Select all

UpdateWindows()
{
    Code := ( InStr( "WIN_2003,WIN_XP,WIN_2000" , A_OSVERSION ) ) ? 28931 : 41504
    SetTitleMatchMode RegEx
    WinGet WindowList , List , ahk_class ExploreWClass|CabinetWClass|Progman
    Loop %WindowList%
        PostMessage 0x111 , %Code% ,  ,  , % "ahk_id" WindowList%A_Index%
    SetTitleMatchMode 1
}
and this one:

Code: Select all

; SHGetSetSettings works with structure full of bitfields; allocate space for it
VarSetCapacity(SHELLSTATE, 32, 0)
; get the current value of the show/hide setting and store it in the structure
DllCall("Shell32\SHGetSetSettings", "Ptr", &SHELLSTATE, "UInt", SSF_SHOWALLOBJECTS := 0x0001, "Int", false)
; invert the setting
NumPut(NumGet(SHELLSTATE) ^ (1 << 0), SHELLSTATE,, "Int")
; set the new setting from the value in the structure
DllCall("Shell32\SHGetSetSettings", "Ptr", &SHELLSTATE, "UInt", SSF_SHOWALLOBJECTS, "Int", true)
; get Explorer to send SHCNE_ASSOCCHANGED to all windows, which has the nice side effect of refreshing 'em
DllCall("Shell32\SHChangeNotify", "Int", SHCNE_ASSOCCHANGED := 0x8000000, "UInt", 0, "Ptr", 0, "Ptr", 0)
https://www.reddit.com/r/AutoHotkey/comments/4w31kq/toggle_hidden_filesdir_on_off/
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

14 May 2020, 01:07

You're on topic :thumbup:.
I wrote RefreshExplorer() as a helper for my upcoming SHELLSTATE() (a wrapper for SHGetSetSettings)

iseahound wrote: How does it compare to this archaic function?
Spoiler
I googled its origin: Toggle Hidden Files, System Files and File Extensions

It should be faster.. ahk_class should include WorkerW, I suppose.
RefreshExplorer() is slower but more effective, IMO.

iseahound wrote:and this one:
Spoiler
SHCNE_ASSOCCHANGED is brutal for this trivial task. I had suggested it only to update icon cache.
SHCNE_UPDATEITEM should be sufficient and I will update this topic with a wrapper for it.

Also, SHCNE_ASSOCCHANGED wouldn't work with Show/Hide hidden files

BTW, don't rely on SSF constants. The following should be better.
The list is a tad incomplete as I'm unable to figure constant names for 0x8, 0x40 and 0x80

Code: Select all

; Flags
ShowAllObjects       := 0x1
ShowExtensions       := 0x2         ; HideFileExt
NoConfirmRecycle     := 0x4
ShowCompColor        := 0x10        ; ShowCompColor
DoubleClickInWebView := 0x20
DontPrettyPath       := 0x100       ; DontPrettyPath
MapNetDrvBtn         := 0x400       ; MapNetDrvBtn
ShowInfoTip          := 0x800       ; ShowInfoTip
HideIcons            := 0x1000      ; HideIcons
WebView              := 0x2000      ; WebView
Filter               := 0x4000      ; Filter
ShowSuperHidden      := 0x8000      ; ShowSuperHidden
NoNetCrawling        := 0x10000
AutoCheckSelect      := 0x800000    ; AutoCheckSelect

; Exflags
SeparateProcess      := 0x100000    ; SeparateProcess
StartPanelOn         := 0x200000
IconsOnly            := 0x1000000   ; IconsOnly
ShowTypeOverlay      := 0x2000000   ; ShowTypeOverlay
ShowStatusBar        := 0x4000000   ; ShowStatusBar   (Win 8+)

; The names in comment are keys found in
; HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced

My Scripts and Functions: V1  V2
iseahound
Posts: 1451
Joined: 13 Aug 2016, 21:04
Contact:

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

03 Feb 2021, 17:52

SKAN wrote:
14 May 2020, 01:07
RefreshExplorer() is slower but more effective, IMO.
I finally did some testing and RefreshExplorer() is faster and more effective!
neogna2
Posts: 598
Joined: 15 Sep 2016, 15:44

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

04 Mar 2021, 17:00

Thanks for this function @SKAN! Could you explain what this line does

Code: Select all

ComObjCreate("Shell.Application").Windows.Item(ComObject(0x13,8)).Refresh()
I suspect it is related to https://www.autohotkey.com/docs/commands/ComObjType.htm#vt but I don't grasp what it does in this function. In a quick test it appears we can leave that line out and the Explorer windows refresh anyway.
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

05 Mar 2021, 00:49

neogna2 wrote:
04 Mar 2021, 17:00
Thanks for this function @SKAN! Could you explain what this line does

Code: Select all

ComObjCreate("Shell.Application").Windows.Item(ComObject(0x13,8)).Refresh()
That line refreshes the Desktop.
👍
neogna2
Posts: 598
Joined: 15 Sep 2016, 15:44

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

05 Mar 2021, 09:20

SKAN wrote:
05 Mar 2021, 00:49
That line refreshes the Desktop.
Oh ok. I'd like to learn how you pick an item from the ShellWindows object directly like that, rather than looping over all its items. What is this Item(ComObject(0x13,8)) syntax?

Am I on the right track here:
ComObjActive says this format ParamObj := ComObject(VarType, Value , Flags) "Creates an object representing a typed value to be passed as a parameter or return value"
0x13 is VarType "32-bit unsigned int"
8 is... the constant index position of the Desktop item, detected through trial and error?
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

05 Mar 2021, 09:36

neogna2 wrote:
05 Mar 2021, 09:20
What is this Item(ComObject(0x13,8)) syntax?
I don't remember.
The original was by @teadrinker
https://www.autohotkey.com/boards/viewtopic.php?style=17&p=326440#p326440

:)
neogna2
Posts: 598
Joined: 15 Sep 2016, 15:44

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

05 Mar 2021, 11:12

A code mystery, I like it :) teadrinker's script has the line desktop := IShellWindows.Item(ComObj(19, 8)) ; VT_UI4, SCW_DESKTOP and the comment string SCW_DESKTOP traces back to a 2012 lexikos post. I think it might be a typo for SWC_DESKTOP from ShellWindowTypeConstants.
If this is the correct interpretation of those constants
SWC_EXPLORER = 0x0
SWC_BROWSER = 0x00000001
SWC_3RDPARTY = 0x00000002
SWC_CALLBACK = 0x00000004
SWC_DESKTOP = 0x00000008

then that explains the value 8
teadrinker
Posts: 4362
Joined: 29 Mar 2015, 09:41
Contact:

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

05 Mar 2021, 12:36

SKAN wrote:

Code: Select all

If ( Window.Name="Windows Explorer" or Window.Name="File Explorer" )
This will only work if the system language is English. These values are language dependent.
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

06 Mar 2021, 16:51

teadrinker wrote:
05 Mar 2021, 12:36
SKAN wrote:

Code: Select all

If ( Window.Name="Windows Explorer" or Window.Name="File Explorer" )
This will only work if the system language is English. These values are language dependent.
Is display language different form system language?
I changed my display language from English US (Win 10) to Tamil and it doesn't seem to make any difference.
The Window.Name is still File Explorer.
teadrinker
Posts: 4362
Joined: 29 Mar 2015, 09:41
Contact:

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

06 Mar 2021, 17:03

SKAN wrote: Is display language different form system language?
I honestly don't know.

On Windows 7 I see:
 
 Image

On Windows 10:

Image
 
System language is Russian.
Last edited by teadrinker on 06 Mar 2021, 17:10, edited 1 time in total.
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

06 Mar 2021, 17:56

Thanks for the info @teadrinker

IE window has a window.type while file explorer windows doesn't.
The following seems to work:

Code: Select all

RefreshExplorer() {           ; By SKAN on D35D/D437 @ tiny.cc/refreshexplorer
Local 
   ComObjCreate("Shell.Application").Windows.Item(ComObject(0x13,8)).Refresh()
   For   Window in ComObjCreate("Shell.Application").Windows
     Try Window.Type
     Catch
         Window.Refresh()
}
teadrinker
Posts: 4362
Joined: 29 Mar 2015, 09:41
Contact:

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

06 Mar 2021, 19:08

Why not like this:

Code: Select all

RefreshExplorer() {
   local
   Windows := ComObjCreate("Shell.Application").Windows
   Windows.Item(ComObject(0x13, 8)).Refresh()
   for Window in Windows
      if (Window.Name != "Internet Explorer")
         Window.Refresh()
}
Last edited by teadrinker on 06 Mar 2021, 19:34, edited 1 time in total.
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

06 Mar 2021, 19:16

teadrinker wrote:
06 Mar 2021, 19:08
Why not like this:
Spoiler
COM object is created only once.. Very nice! :thumbup:
So, Window.Name is Internet Explorer for all languages!
teadrinker
Posts: 4362
Joined: 29 Mar 2015, 09:41
Contact:

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

06 Mar 2021, 19:22

SKAN wrote: So, Window.Name is Internet Explorer for all languages!
Exactly! :)
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

06 Mar 2021, 19:38

@teadrinker

Thanks. I have updated the first post.
👍
UserNameForAH_Board
Posts: 54
Joined: 02 Jan 2018, 15:55

Re: RefreshExplorer() : Refresh all open Windows explorer + Desktop

18 Apr 2022, 15:39

If any one could get any of these methods to work for AHK version 2, I'd be grateful. I myself made an abortive attempt at converting the following method (that method being one of the ones posted above).

Code: Select all

; SHGetSetSettings works with structure full of bitfields; allocate space for it
VarSetCapacity(SHELLSTATE, 32, 0)
; get the current value of the show/hide setting and store it in the structure
DllCall("Shell32\SHGetSetSettings", "Ptr", &SHELLSTATE, "UInt", SSF_SHOWALLOBJECTS := 0x0001, "Int", false)
; invert the setting
NumPut(NumGet(SHELLSTATE) ^ (1 << 0), SHELLSTATE,, "Int")
; set the new setting from the value in the structure
DllCall("Shell32\SHGetSetSettings", "Ptr", &SHELLSTATE, "UInt", SSF_SHOWALLOBJECTS, "Int", true)
; get Explorer to send SHCNE_ASSOCCHANGED to all windows, which has the nice side effect of refreshing 'em
DllCall("Shell32\SHChangeNotify", "Int", SHCNE_ASSOCCHANGED := 0x8000000, "UInt", 0, "Ptr", 0, "Ptr", 0)
Here is as far as I got (and even what I have may be incorrect):

Code: Select all

; SHGetSetSettings works with structure full of bitfields; allocate space for it
SHELLSTATE := Buffer(32, 0)

; get the current value of the show/hide setting and store it in the structure
DllCall("Shell32\SHGetSetSettings", "Ptr", &SHELLSTATE, "UInt", SSF_SHOWALLOBJECTS := 0x0001, "Int", false)

; invert the setting
NumPut("Int", NumGet(SHELLSTATE, "Int") ^ (1 << 0), SHELLSTATE)

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: dox and 61 guests