one time settimer in onmessage function will create a dead loop

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tuzi
Posts: 223
Joined: 27 Apr 2016, 23:40

one time settimer in onmessage function will create a dead loop

Post by tuzi » 29 Nov 2021, 02:33

[Moderator's note: Topic moved from Bug Reports.]

ahk 1.1.33.10
win10 x64

In the following example, the count does not increase when the mouse stays on the gui and doesn't move anymore.

Code: Select all

Gui Show, w100 h100, Window
OnMessage(0x200, "WM_MOUSEMOVE")
return

GuiClose:
ExitApp
return

WM_MOUSEMOVE()
{
	static zzz

	aaa:
		zzz++
		ToolTip, %zzz%
	return
}
But in the following example, the count keeps increasing even if the mouse doesn't move anymore.

Code: Select all

Gui Show, w100 h100, Window
OnMessage(0x200, "WM_MOUSEMOVE")
return

GuiClose:
ExitApp
return

WM_MOUSEMOVE()
{
	static zzz

	SetTimer, aaa, -100
	return

	aaa:
		zzz++
		ToolTip, %zzz%
	return
}

User avatar
thqby
Posts: 391
Joined: 16 Apr 2021, 11:18
Contact:

Re: one time settimer in onmessage function will create a dead loop

Post by thqby » 29 Nov 2021, 03:22

Because the pop-up tooltip window triggers a new message.
The above example is the same.

tuzi
Posts: 223
Joined: 27 Apr 2016, 23:40

Re: one time settimer in onmessage function will create a dead loop

Post by tuzi » 29 Nov 2021, 09:40

thqby wrote:
29 Nov 2021, 03:22
Because the pop-up tooltip window triggers a new message.
The above example is the same.
@thqby

如果 tooltip 触发一个新的 WM_MOUSEMOVE 那第1个例子计数就应该不停的增加啊。
但只有第2个例子,鼠标不动的时候,计数会不停增加。

If tooltip triggers a new WM_MOUSEMOVE then the count should keep increasing in the first example when the mouse is not moving.
But only in the second example, the count keeps increasing when the mouse is not moving.

just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: one time settimer in onmessage function will create a dead loop

Post by just me » 29 Nov 2021, 17:06

In your first example the message handler is still running when the tooltip is displayed.
If a message arrives while its function is still running due to a previous arrival of the same message, by default the function will not be called again; instead, the message will be treated as unmonitored.

https://www.autohotkey.com/docs/commands/OnMessage.htm#Remarks

tuzi
Posts: 223
Joined: 27 Apr 2016, 23:40

Re: one time settimer in onmessage function will create a dead loop

Post by tuzi » 11 Dec 2021, 12:00

@just me
if in example 1 the message handler is still running when the tooltip is displayed. why the counter will not increasing when the mouse is no longer moving on the GUI ?

i understand in example 1, when the mouse is moving on the GUI, the counter will increasing.

But I don't understand why the counter in example 2 will keeps increasing when the mouse is no longer moving on the GUI.

:(

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: one time settimer in onmessage function will create a dead loop

Post by swagfag » 25 Jan 2022, 05:48

i think @just me already explained it super succinctly and clearly

in the top example u have:
  • u nudge the mouse onto the GUI and leave it stationary
  • windows generates the WM_MOUSEMOVE message
  • ahk receives the WM_MOUSEMOVE message and starts processing it
  • ahk checks internally if u have registered any msghandlers
  • u have, so it calls into ur OnMessage function
  • the onmsg function starts running
  • it creates a ToolTip control/window (this generates a ton of new window messages, WM_CREATE, WM_ACTIVATE, WM_WHOEVENKNOWSWHATELSE and among which WM_MOUSEMOVE apparently). since the onmsg function is already processing an WM_MOUSEMOVE, any newly generated ones that ahk receives are dropped
  • the tooltip is now visible, and there is no longer a stream of messages being generated
  • the function ends and returns
  • and thats it, u get one tooltip

in the bottom example u have:
  • u nudge the mouse onto the GUI and leave it stationary
  • windows generates the WM_MOUSEMOVE message
  • ahk receives the WM_MOUSEMOVE message and starts processing it
  • ahk checks internally if u have registered any msghandlers
  • u have, so it calls into ur OnMessage function
  • the onmsg function sets up a one-off delayed timer, and returns
  • some milliseconds pass. the mouse cursor is still stationary over the GUI
  • the delayed timer now fires
  • it creates a ToolTip control/window (this generates a ton of new window messages, WM_CREATE, WM_ACTIVATE, WM_WHOEVENKNOWSWHATELSE and among which WM_MOUSEMOVE apparently)
  • the tooltip is now visible, and there is no longer a stream of messages being generated
  • ahk receives the WM_MOUSEMOVE message and starts processing it
  • ahk checks internally if u have registered any msghandlers
  • u have, so it interrupts ur still-running timer subroutine(of which only the line returnremains to be executed, but still - conceptually there could have been more lines following that) and calls into ur OnMessage function
  • the onmsg function sets up a one-off delayed timer, and returns
  • ur just-interrupted timer subroutine is now allowed run to completion
  • some milliseconds pass. the mouse cursor is still stationary over the GUI
  • the delayed timer now fires
  • it creates a ToolTip control/window (this generates a ton of new window messages, WM_CREATE, WM_ACTIVATE, WM_WHOEVENKNOWSWHATELSE and among which WM_MOUSEMOVE apparently)
  • the tooltip is now visible, and there is no longer a stream of messages being generated
  • ahk receives the WM_MOUSEMOVE message and starts processing it
  • ....... and so on and so on

Post Reply

Return to “Ask for Help (v1)”