WinMove difference between script & executable Topic is solved

Report problems with documented functionality
TomL
Posts: 16
Joined: 12 Jan 2016, 21:02

WinMove difference between script & executable

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

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
      }
   }
}
joefiesta
Posts: 497
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: WinMove difference between script & executable

20 Aug 2018, 08:04

I tested your script. It works just perfectly fine for me. Both the Compiled and Uncompiled versions.
I run Win 7 Pro, 32 bit. Running AHK version 1.1.28.00.
TomL
Posts: 16
Joined: 12 Jan 2016, 21:02

Re: WinMove difference between script & executable

20 Aug 2018, 08:20

It appears I'm running 1.1.29.00, not 11.29.01
It figure's I'd notice it after I post the problem.

Thanks joefiesta for the feedback. I saw your post when I went to delete mine.
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: WinMove difference between script & executable

20 Aug 2018, 08:21

could it have something to do with UAC or running as admin?

TomL
Posts: 16
Joined: 12 Jan 2016, 21:02

Re: WinMove difference between script & executable  Topic is solved

20 Aug 2018, 09:03

Just to clarify, version 1.1.29.00 caused WinMove to not work correctly in some situations. Version 1.1.29.01 fixed the problem.

Maybe someone will find my test code useful as example code for how to detect when a window is created.
Asmodeus
Posts: 57
Joined: 19 Oct 2015, 15:53

Re: WinMove difference between script & executable

21 Aug 2018, 05:43

TomL wrote:Maybe someone will find my test code useful as example code for how to detect when a window is created.
thanks, I use your code with WinClose instead of WinMove to get rid of a nag screen.
I believe there is no way to hinder the window creation itself; if I am mistaken plz let me know, as I'd prefer not to see the nag at all :roll: ...

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 21 guests