WinMove difference between script & executable
Posted: 20 Aug 2018, 07:02
I'm working on a program that will 'snap' a just created window to the edge of the screen. The WinMove command is used to move the window and is issued within a function invoked when the HSHELL_WINDOWCREATED message is received. If a compiled version of the program is running, the WinMove command moves the window as expected. If the script is not compiled the WinMove command fails, causing the program to end without any message (icon remains visible in tray but disappears when the mouse arrow is moved over it).
Here is a small test program that exhibits the problem. While the script is running, the WinOpened() function will be invoked anytime a window is created. If the created window is a file's "Properties" window (left click on a file in the File Explorer program and select "Properties"), the WinOpened() function will change the window's title to "<%Title%>" to indicate the script detected the window and then issue the WinMove command to move the window to screen location (100,100).
Only checked with AHK version 1.1.29.01
Here is a small test program that exhibits the problem. While the script is running, the WinOpened() function will be invoked anytime a window is created. If the created window is a file's "Properties" window (left click on a file in the File Explorer program and select "Properties"), the WinOpened() function will change the window's title to "<%Title%>" to indicate the script detected the window and then issue the WinMove command to move the window to screen location (100,100).
Only checked with AHK version 1.1.29.01
Code: Select all
#Persistent
;Register shell hook
DetectHiddenWindows, On ;Access this processes' hidden window
Process, Exist ;Get its process ID
hwnd := WinExist( "ahk_pid " . ErrorLevel ) ;Get its hwnd
;Get message when a window created
DllCall("RegisterShellHookWindow", "UInt", hwnd )
msgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
;Call function when message received
OnMessage( msgNum, "winOpened" ) ;Register function to invoke
;Perform actions on just created window
winOpened( wParam, lParam )
{
If( wParam = 1 ) ; 1 = HSHELL_WINDOWCREATED
{
WinGet, hwnd, ID, A ;hwnd of just created window
;Act only on a File Explorer's file properties window
WinGetTitle, winTitle, ahk_id %hwnd%
if( InStr( winTitle, "Properties" ) )
{
;Change the title of the window (always works)
WinSetTitle, ahk_id %hwnd%, , <%winTitle%>
;Move the window (Only works if a compiled script)
WinMove, ahk_id %hwnd%, , 100, 100
}
}
}