Run code when window appear or resizes

Propose new features and changes
User avatar
Almost_there
Posts: 404
Joined: 30 Sep 2014, 10:32

Run code when window appear or resizes

23 Oct 2014, 11:23

Hi.

Cannot write a topic long enough to make sense, so please read.

When writing simple javascripts for the web browser, you can include function that runs when a spesific action takes place, such as when a window change it size.

Therefore I would love if there was possible to make a function run only when resizing a window like this:

Code: Select all

#OnWindowChangeSize, Notepad
 ; This code runs once after Notepad program window has being resized 
return
Of course I can make a timer to check every n'te millisecond and then take action. However having #OnWindow... followed by some action to wait for, will make it so much easier to write smaller scripts.

Other similar functions (not as in scripting) could be:
  • #OnWindowMaximize
  • #OnWindowMinimize
  • #OnWindowAppear (if it was minimized, or program just started up)
  • #OnWindowMove
  • #OnWindowDisappear
  • #OnWindowsLoseFocus
  • #OnWindowsGetFocus
Thanks
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Run code when window appear or resizes

23 Oct 2014, 12:38

can probably do this with a ShellHook

User avatar
fincs
Posts: 527
Joined: 30 Sep 2013, 14:17
Location: Seville, Spain
Contact:

Re: Run code when window appear or resizes

23 Oct 2014, 13:05

As guest3456 said, this can be implemented easily in script:

Code: Select all

#Persistent
DllCall("RegisterShellHookWindow", "ptr", A_ScriptHwnd)
OnMessage(DllCall("RegisterWindowMessage", "str", "SHELLHOOK"), "MyShellHook")

MyShellHook(eventType, argument)
{
    return 0
}
fincs
Windows 11 Pro (Version 22H2) | AMD Ryzen 7 3700X with 32 GB of RAM | AutoHotkey v2.0.0 + v1.1.36.02
Get SciTE4AutoHotkey v3.1.0 - [My project list]
User avatar
joedf
Posts: 8953
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Run code when window appear or resizes

23 Oct 2014, 15:37

I have been looking to catch the maximize event a long time ago..
but the tooltip doesnt change when dragging or maximize

Code: Select all

#Persistent
gui +resize +hwndhGUI
gui,show,w345 h345
return

guiclose:
exitapp

DllCall("RegisterShellHookWindow", "ptr", hGUI)
OnMessage(DllCall("RegisterWindowMessage", "str", "SHELLHOOK"), "MyShellHook")

MyShellHook(eventType, argument)
{
tooltip %A_now%
    return 0
}
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
Almost_there
Posts: 404
Joined: 30 Sep 2014, 10:32

Re: Run code when window appear or resizes

01 Nov 2014, 11:44

Hi.

I appreciate your answer very much. But I'm afraid I'm just too much newbie to Autohotkey to fully understand how to implement in my script.

Code: Select all


#IfWinActive, myProgramWindow

!a::
 ; my code goes here
return

; I want to modify this to call up a MsgBox when "Notepad" start running.
DllCall("RegisterShellHookWindow", "ptr", hGUI)
OnMessage(DllCall("RegisterWindowMessage", "str", "SHELLHOOK"), "MyShellHook")


Thanks
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Run code when window appear or resizes

01 Nov 2014, 13:22

joedf wrote:I have been looking to catch the maximize event a long time ago..
but the tooltip doesnt change when dragging or maximize
Min/Max works only when minimizing and restoring from minimized state as far as I undstand.
User avatar
joedf
Posts: 8953
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Run code when window appear or resizes

01 Nov 2014, 13:44

what about window sizing... I was dragging the sides... But still the tool tip doesn't appear...
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Run code when window appear or resizes

01 Nov 2014, 13:57

As I understand there must be another hook that does not call CallNextHookEx so we never receive the message, see here.
User avatar
joedf
Posts: 8953
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Run code when window appear or resizes

01 Nov 2014, 14:35

Oh ok.... Hmmm :P thanks
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
Almost_there
Posts: 404
Joined: 30 Sep 2014, 10:32

Re: Run code when window appear or resizes

01 Nov 2014, 14:48

Cannot find enough documentation to get this to work. Can you alter tis code so that it runs as intended?

Code: Select all

DllCall("RegisterShellHookWindow", "ptr", A_ScriptHwnd)
OnMessage(DllCall("RegisterWindowMessage", "str", "SHELLHOOK"), "MyShellHook")

MyShellHook(eventType, argument)
{
    MsgBox, Message to appear soon as Notepad window appear
    return 0
}
User avatar
Almost_there
Posts: 404
Joined: 30 Sep 2014, 10:32

Re: Run code when window appear or resizes

15 Jun 2016, 15:36

Bump
Hope you don't arrest me for awakening this zoombie thread.

The time I wrote the thread I hadn't learn about making Gui's, and now reading the same thread get me assume the question was about Authohotkey GUI's.

The intention (an example) was to detect when image size of window Notepad.exe changes. A working example if possible.
If that is not possible to achieve using Autohotkey, I always have the trusted timers that works fine too.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Run code when window appear or resizes

16 Jun 2016, 16:48

You don't understand the code because you have a slight misconception there.
The code above sends a Message (calls the function you defined using OnMessage) whenever a Message is send to any Window.
What exactly is passed using the 2 parameters of the script.
If you have problems using a ShellHook please post in the Ask for Help forum.
Recommends AHK Studio
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: Run code when window appear or resizes

28 Jul 2017, 20:26

Depending on your task, you could do ControlGetPos and then loop something that says If Width & heigth greater than X.. do Y. :)

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 60 guests