WinMove for files Explorer

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Chronos
Posts: 2
Joined: 02 Mar 2016, 13:57

WinMove for files Explorer

02 Mar 2016, 15:08

Hello,
This is probably a typical beginner question, but I did not found any answer in the forum (I didn't look at the 249 pages ...).
I cannot open and then move the Windows (7 or 10, I tested in both) files explorer, when the same exact script works for other applications (eg. notepad).
Here is the script, that I intend to use in a larger one to organize my work space :

Code: Select all

^j::
	Run, explorer.exe
	WinWait, ahk_exe explorer.exe
	WinActivate, ahk_exe explorer.exe
	WinMove, ahk_exe explorer.exe, ,30,30
Return
This script actually open the files explorer but don't move it.
I'm using the "ahk_exe" Process name as reported by Window Spy for Explorer.exe. I cannot use the Window Title because it is dependant on the active directory.
Any help will be welcome !
Bye.
wizardzedd
Posts: 319
Joined: 23 Jan 2016, 23:03

Re: WinMove for files Explorer

02 Mar 2016, 16:28

winWait
If a matching window comes into existence, the command will not wait for Seconds to expire. Instead, it will immediately set ErrorLevel to 0, update the Last Found Window, and the script will continue executing.
Since explorer.exe is a very common window, it finds it immediately and continues with the rest of code even though the window doesn't exist yet.

Code: Select all

^j::
	Run, explorer.exe
	winget, Count, Count, ahk_exe explorer.exe
	cCount:=Count ; current count
	while(Count >= cCount) { 
		if(A_Index > 100) ; 5 second timeout
			return
		sleep, 50
		winget, cCount, Count, ahk_exe explorer.exe
	}
	WinMove, A, , 30, 30 ; moves active win
Return
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: WinMove for files Explorer

02 Mar 2016, 21:39

The desktop and taskbar (and on some versions of Windows, the Start button) are all top-level windows which belong to explorer.exe. For example, this returns "Start" (the Start button) on my Windows 7 system:

Code: Select all

WinGetTitle title, ahk_exe explorer.exe
MsgBox % title
You need to be more specific. For example, use ahk_class CabinetWClass instead of - or in addition to - ahk_exe explorer.exe.
Chronos
Posts: 2
Joined: 02 Mar 2016, 13:57

Re: WinMove for files Explorer

06 Mar 2016, 12:02

Hi Wizzardzedd and Lexikos,
Many thanks. That works now :thumbup: ... and shows me that I have a lot to learn!
Best regards
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: WinMove for files Explorer

19 Oct 2019, 08:40

EDIT: I found a answer to my problem at the end of my post.

Hello, I've come across the same problem and I wanted to ask if any one knows why being more specific as Lexikos stated does not work in this situation:

I am identifying the Data folder name adding both ahk_class CabinetWClass and ahk_exe Explorer.exe
but I tested many times and the window is simply not recognised by WinExist()
While on the other hand, when I am LESS SPECIFIC - which is my question - it works ??

What's wrong with Explorer that makes it unreliable even when super precise like shown above ?
EDIT: With other window types like chrome windows for example - the same method will retrieve window info correctly. Only Explorer.exe windows seem to be involved in the identification problem.
EDIT2: all the info I use is from AHK's bult-in Window Spy

output results of WinGetPos and WinGet,v, MinMax
[Data ahk_class CabinetWClass]
x=1219
y=375
w=1139
h=637
MinMax=0
[Data ahk_class CabinetWClass ahk_exe Explorer.exe]
x=
y=
w=
h=
MinMax=

Final Edit - Partial answer to my question:
AHK's built-in Window Spy tells me this info when I get the explorer window info:
Data
ahk_class CabinetWClass
ahk_exe Explorer.EXE
ahk_pid 9788
But when using WinExist("Data ahk_class CabinetWClass ahk_exe Explorer.EXE"), the function return null.
Unexpectedly, I need to modify Window Spy's output to ALL LOWER CHARACTERS no caps allowed like so:
Data ahk_class CabinetWClass ahk_exe explorer.exe
I am using SetTitleMatchMode RegEx and the doc says :
"Window titles are case sensitive, except when using the i) modifier in a RegEx pattern."
So if I want to do something like WinExist(winTitleRegEx) i need to add this: WinExist("i)" winTitleRegEx) or how would you do it ?

Code: Select all

For winTitle in mySavedWindows {
		winTitleRegEx:="i)" . winTitle
		if (hWnd := WinExist(winTitleRegEx)) {
Doesn't work
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: WinMove for files Explorer

19 Oct 2019, 16:59

Window titles and classes are case sensitive, except when using RegEx with i).

ahk_exe paths are not case sensitive, except when using RegEx without i), because RegEx is case-sensitive by default.

Each component is a separate RegEx pattern, and the strings "ahk_class" and "ahk_exe" are delimiters, not included in the patterns. You must insert i) immediately before the process name.
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: WinMove for files Explorer

19 Oct 2019, 22:42

Thank you very much for your reply @lexikos this makes sense now and I understand why I was getting errors. Have a good day

EDIT: tested and this works perfectly as you said:
[i)Data ahk_class i)CabinetWClass ahk_exe i)Explorer.EXE]
x=440
y=69
w=1044
h=603
MinMax=0

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jaka1, mikeyww and 183 guests