Manipulate an Explorer window found by COM Shell.Application Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
roysubs
Posts: 426
Joined: 29 Sep 2018, 16:37

Manipulate an Explorer window found by COM Shell.Application

15 Oct 2018, 14:46

jeeswg has a fantastic page here that goes through some Explorer options.
https://autohotkey.com/boards/viewtopic.php?t=31755

There is a bit of code that is really interesting to me.
This snippet correctly sees each Explorer window, but what I want to know is how I then get a handle on each window to perform an AutoHotkey command on them.
e.g. Say I have 4 explorer window, and the for window in ComObj loop goes through them.
With the first explorer window captured, I want to do something, like WinMinimize or WinActivate, how is that done?

Code: Select all

q:: ;get the path for folders/special folders/Control Panel items
for window in ComObjCreate("Shell.Application").Windows
	try MsgBox % window.Document.Folder.Self.Path
return
I tried shoving a WinActivate in there, but it does nothing

Code: Select all

q:: ;get the path for folders/special folders/Control Panel items
for window in ComObjCreate("Shell.Application").Windows
	try MsgBox % window.Document.Folder.Self.Path
	WinActivate
return
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Manipulate an Explorer window found by COM Shell.Application

15 Oct 2018, 14:54

The key thing is to get the hWnd. Cheers.

Code: Select all

for oWin in ComObjCreate("Shell.Application").Windows
	WinMinimize, % "ahk_id " oWin.HWND
Btw in your script you'd probably need curly braces, to put both lines into the same code block. You could use SoundBeep or MsgBox etc to confirm this.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Manipulate an Explorer window found by COM Shell.Application  Topic is solved

15 Oct 2018, 14:59

jesswg already replied, but I was working on this example for you:


Example: If Recycle Bin window is open, then Maximize it.

Code: Select all

#SingleInstance, Force

q::
	For Window In ComObjCreate("Shell.Application").Windows {
		WindowHwnd := Window.Hwnd
		WindowPath := Window.Document.Folder.Self.Path

		If (WindowPath = "::{645FF040-5081-101B-9F08-00AA002F954E}") { ; Recycle Bin
			WinMaximize, % "ahk_id " WindowHwnd
			Break
		}
	}
return
roysubs
Posts: 426
Joined: 29 Sep 2018, 16:37

Re: Manipulate an Explorer window found by COM Shell.Application

15 Oct 2018, 15:31

Thanks very much guys, this is really useful for me, and seeing how to manipulate on system things like the Recycle Bin is very useful to know, ta.
roysubs
Posts: 426
Joined: 29 Sep 2018, 16:37

Re: Manipulate an Explorer window found by COM Shell.Application

15 Oct 2018, 18:01

On this object approach, normally to jump to a folder in Explorer, I do:

Code: Select all

Send, ^d   ; to get to the address bar
Send, C:\MyFolder
But I note you referencing the Path of the object here:

Code: Select all

WindowHwnd := Window.Hwnd
WindowPath := Window.Document.Folder.Self.Path
Is there a way to tell the Explorer instance to change folder in a more elegant way than manually jumping to the address bar by poking at the Window.Document.Folder.Self.Path and how would that look to do that?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Manipulate an Explorer window found by COM Shell.Application

15 Oct 2018, 18:17

See JEE_ExpWinSetDir, here:
Explorer window interaction (folder windows/Desktop, file/folder enumeration/selection/navigation/creation) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=35041
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo and 217 guests