I'd be grateful were someone to convert this 'ComObject' code

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
UserNameForAH_Board
Posts: 50
Joined: 02 Jan 2018, 15:55

I'd be grateful were someone to convert this 'ComObject' code

19 Apr 2022, 11:18

Dear all

This forum thread discusses ways of 'refreshing' file explorer windows. One of those ways is as follows. I'd be grateful were someone to convert it to the new syntax.

Code: Select all

Windows := ComObjCreate("Shell.Application").Windows
Windows.Item(ComObject(0x13, 8)).Refresh()
for Window in Windows
  if (Window.Name !== "Internet Explorer")
    Window.Refresh()
User avatar
boiler
Posts: 16999
Joined: 21 Dec 2014, 02:44

Re: I'd be grateful were someone to convert this 'ComObject' code

19 Apr 2022, 16:38

It seems that it can be this simple:

Code: Select all

for Window in ComObject("Shell.Application").Windows
	if (Window.Name != "Internet Explorer")
		Window.Refresh()

If someone can explain why that's not adequate, please do.
neogna2
Posts: 591
Joined: 15 Sep 2016, 15:44

Re: I'd be grateful were someone to convert this 'ComObject' code

16 Sep 2022, 15:24

boiler wrote:
19 Apr 2022, 16:38
If someone can explain why that's not adequate, please do.
Adequate depends on the goal. Your code refreshes all open Explorer windows but not the desktop.

To refresh both Explorer windows and desktop use iseahound's v2 version posted today. The line that contains (0x13, 8) is for desktop refresh. (Background on that here.)
lexikos
Posts: 9593
Joined: 30 Sep 2013, 04:07
Contact:

Re: I'd be grateful were someone to convert this 'ComObject' code

16 Sep 2022, 20:18

For anyone who finds this topic while looking for help "to convert this 'ComObject' code" and not necessarily to refresh Explorer windows, the answers can easily be found by searching v2-changes for the function names.

ComValue(vt, value) creates a wrapper object. ... This replaces ComObjParameter(vt, value), ComObject(vt, value) and any other names that were used with a variant type and value as parameters.
Source: Changes from v1.1 | AutoHotkey v2
ComObject(CLSID) creates a ComObject; i.e. this is the new ComObjCreate.
Source: Changes from v1.1 | AutoHotkey v2
Renamed:
  • ComObjCreate() → ComObject, which is a class now
Source: Changes from v1.1 | AutoHotkey v2

That is all you need to do; rename the functions. You do not even need to change !==, which was originally a typo but is now case-sensitive not-equal.
iseahound
Posts: 1450
Joined: 13 Aug 2016, 21:04
Contact:

Re: I'd be grateful were someone to convert this 'ComObject' code

02 Jul 2023, 19:22

Ooh I never posted these then?

Code: Select all

UpdateWindows()
{
    _ttm := A_TitleMatchMode
    SetTitleMatchMode 'RegEx'
    for window in WinGetList("ahk_class ExploreWClass|CabinetWClass|Progman")
        PostMessage 0x111 , 41504 ,,, window
    SetTitleMatchMode _ttm
}

RefreshExplorer() { ; by teadrinker on D437 @ tiny.cc/refreshexplorer
   local Windows := ComObject("Shell.Application").Windows
   Windows.Item(ComValue(0x13, 8)).Refresh()
   for Window in Windows
      if (Window.Name != "Internet Explorer")
         Window.Refresh()
}
User avatar
zabbn
Posts: 50
Joined: 30 Apr 2020, 03:34
Location: Germany

Re: I'd be grateful were someone to convert this 'ComObject' code

16 Apr 2024, 15:50

Thank you. Unfortunately, both of these give me

Error: Unexpected reserved word.

Text: in Windows if (Window.Name != "Internet Explorer") Window.Refresh() regKeyPath:=…
Line: 1643
File: C:\Users\XXX\global_V2.ahk

The program will exit.


But only if I #include this file 'global_V2.ahk' in the script of question.
If I use your code in a separate file (without #include), it works. How can one explain that?
gregster
Posts: 9037
Joined: 30 Sep 2013, 06:48

Re: I'd be grateful were someone to convert this 'ComObject' code

16 Apr 2024, 16:42

zabbn wrote:
16 Apr 2024, 15:50
Thank you. Unfortunately, both of these give me

Error: Unexpected reserved word.

Text: in Windows if (Window.Name != "Internet Explorer") Window.Refresh() regKeyPath:=…
Line: 1643
File: C:\Users\XXX\global_V2.ahk

The program will exit.


But only if I #include this file 'global_V2.ahk' in the script of question.
If I use your code in a separate file (without #include), it works. How can one explain that?
Where is that file coming from?
Looks strange that in Windows if (Window.Name != "Internet Explorer") Window.Refresh() regKeyPath:=… seems to be seen as a single line - but it would explain the error message, I guess.
I would check the contents of the file for missing line breaks.
User avatar
zabbn
Posts: 50
Joined: 30 Apr 2020, 03:34
Location: Germany

Re: I'd be grateful were someone to convert this 'ComObject' code

17 Apr 2024, 06:54

Absolutely, why didn't I think of that... Thank you very much for your response and sorry for the now obviously off-topic bump.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: hisrRB57 and 66 guests