Pass variable to OnMessage Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Dest938572
Posts: 3
Joined: 28 Dec 2015, 06:02

Pass variable to OnMessage

04 Sep 2019, 10:08

Hello!
I need to use some variables inside OnMessage handlers.
Here is example:
Why does myVar is empty?

Code: Select all

myVar = "hello world"

Gui, New, hwndhGui AlwaysOnTop Resize
GuiControl, Font, hwndhGui
Gui, Show, H120 x700 y200

OnMessage(0x201, "WM_LBUTTONDOWN")

return


;MouseClick handler
WM_LBUTTONDOWN()
{
	OutputDebug myVar: %myVar%
}

User avatar
boiler
Posts: 17399
Joined: 21 Dec 2014, 02:44

Re: Pass variable to OnMessage  Topic is solved

04 Sep 2019, 10:13

You would have to make myVar global if you want its value to be available inside functions.
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: Pass variable to OnMessage

04 Sep 2019, 10:41

Or you could do like this:

Code: Select all

myVar = "hello world"

Gui, New, hwndhGui AlwaysOnTop Resize
GuiControl, Font, hwndhGui
Gui, Show, H120 x700 y200

OnMessage( 0x201, Func("WM_LBUTTONDOWN").Bind(myVar) )
return


;MouseClick handler
WM_LBUTTONDOWN(text)
{
   MsgBox, %text%
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Mateusz53, mikeyww and 302 guests