OnMessage v. a custom WndProc

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 2269
Joined: 19 Dec 2016, 01:58
Location: UK

OnMessage v. a custom WndProc

20 Apr 2017, 01:13

Does OnMessage receive messages, e.g. from AutoHotkey GUI controls, that an ordinary WndProc wouldn't?

I provide 2 scripts, the first, the OnMessage script receives WM_LBUTTONDOWN from a GUI and 0x5555 messages, the second, the WndProc script only receives the 0x5555 messages.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
Drugwash
Posts: 241
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: OnMessage v. a custom WndProc

20 Apr 2017, 07:59

Using A_ScriptHwnd is not gonna cut it. Here's how it does work:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
jeeswg
Posts: 2269
Joined: 19 Dec 2016, 01:58
Location: UK

Re: OnMessage v. a custom WndProc

20 Apr 2017, 08:46

Many thanks Drugwash, in your new version of the script, the WndProc now receives the WM_LBUTTONDOWN message from the GUI but fails to receive the 0x5555 message directed at A_ScriptHwnd.

It seems that OnMessage acts like a WndProc, and receives messages sent to the main window (A_ScriptHwnd)/its controls and windows/controls created via the Gui command, and possibly some other windows.

Maybe this is *obvious* but I read the documentation on OnMessage and didn't notice such a simple description of what it does.
User avatar
Drugwash
Posts: 241
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: OnMessage v. a custom WndProc

20 Apr 2017, 09:07

You should probably direct the custom message to the same hGui as well. That's a hidden, empty GUI as long as there's no GUI element added by the script and most likely everything directed to the script is processed internally. It's been a long time since I skimmed through AHK 1.0 sources and even so I have no real knowledge of the C/C++ language, so can't help with an explanation as to why things go the way they go.

Try this:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by Drugwash on 20 Apr 2017, 09:10, edited 1 time in total.
just me
Posts: 4685
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: OnMessage v. a custom WndProc

20 Apr 2017, 09:09

The script's hidden main window belongs to the class AutoHotkey and has it's own window procedure.
Remaining with AHK 1.1.25.02 until v2 will become beta.
User avatar
jeeswg
Posts: 2269
Joined: 19 Dec 2016, 01:58
Location: UK

Re: OnMessage v. a custom WndProc

20 Apr 2017, 09:33

Just to be clear to anyone reading, the script's 'main window', A_ScriptHwnd, is the one you see when you do 'right-click tray icon, Open', ListLines/ListVars/ListHotkeys/KeyHistory etc.

Code: [Select all] [Download] GeSHi © Codebox Plus

q:: ;show the script's main window
DetectHiddenWindows, On
WinShow, % "ahk_id " A_ScriptHwnd
WinActivate, % "ahk_id " A_ScriptHwnd
return


Out of interest, showing the main window, if it hasn't been shown before, shows an empty Edit control. Also, 'right-click tray icon, Open' appears to be equivalent to ListLines, if the window hasn't been shown yet (via ListLines/ListVars/ListHotkeys/KeyHistory or Open), otherwise it appears to work like WinShow.
lexikos
Posts: 5410
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: OnMessage v. a custom WndProc

20 Apr 2017, 22:46

AutoHotkey calls message monitors registered by OnMessage only for messages that the program can detect. Obviously.

More specifically, that includes messages sent to the script's main window or any AutoHotkeyGUI, since those use a custom window proc. It does not include messages *sent* to any other window.

Messages which are *posted* to any window created in AutoHotkey's main thread are also monitored. Posted messages pass through the message loop (they are returned by GetMessage()), whereas sent messages are dispatched by the inner workings of the message functions.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], blad4, Lapas, Odlanir, RunarSF and 39 guests