ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Skrommel's Software

OnMessage(0x218,"FunctionName") question

(1/2) > >>

SvenBent:
Sorry if I'm posting in the wrong place. but I have a question with AHK and Skrommels seems to be fond of that.

I'm trying to get the "going to standby" message from windows in my AHK scripts by using the OnMessage() command.
but it seems like my function ever gets called


--- Code: Autohotkey ---#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.SetBatchLines -1  OnMessage(0x218, "WM_POWERBROADCAST")Return WM_POWERBROADCAST(wParam, lParam)        {        msgbox test        }
Is there some preparations I need to do to be able to get that message ?

MilesAhead:
If you use the expression form of the function as in the example you can test "Name" for blank on failure.


--- Code: Autohotkey ---Name := OnMessage(MsgNumber, "FunctionName")If (! Name){  MsgBox Message Registration Failed  ExitApp}; do stuff if it worked
Edit:  Also even though the docs say you do not need to have all the params in the function definition I have found stuff works better if I use all four.

If your registration code does return the expected function name then it may be something with Windows where the change of state is not broadcasting a message for some reason.  But esp. when first trying to get code to work it is good to check the return codes for errors or wrap the code in try catch so that errors are reported.

Edit2:  Skrommel has not been around in a while so I took the liberty of sticking in my $.02.  :)

Edit3:  Also try setting DetectHiddenWindows, On before calling OnMessage since you are not using a Gui.

Edit4:  AHK uses an implied window handle called LastFound.  See the examples for OnMessage and DetectHiddenWindows.  A standard trick is to call WinExist() with a blank param to set LastFound to the handle of the current AHK program.  That's the most likely cause.

A better resource is: https://autohotkey.com/boards/index.php
see the "ask for help" board.  You will get a better explanation than the one I gave I am sure.  That's where I go when I get stuck on something AHK.  :)

SvenBent:
Thank you for your feedback. any advise are gratly welcome as im desperate lol

I tried AHK forum "Ask for help" but nothing i spend a few days on the IRC channels to no prevail. I've been googling around for at least a week now, and still anything I try, of other peoples script just fails on both my computers ( work win7 64  & home Win10)  i did however get 0x11  to work so it would react on logoff but that si at east i know something is working right.

i tried you script

--- ---#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetBatchLines -1


Name := OnMessage(MsgNumber, "FunctionName")
If (! Name)
{
  MsgBox Message Registration Failed
  ExitApp
}response: Message Registration Failed

i added "DllCall("RegisterSuspendResumeNotification", "ptr", A_ScriptHwnd, "uint", 0)" in front of the on message
response: Message Registration Failed

I added a small gui in fron of the above
response: Message Registration Failed

Then i added detecthidden windows
response: Message Registration Failed

Final code was this

--- ---#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetBatchLines -1


DetectHiddenWindows, on

Gui, New
Gui, Add, Text,, This is text:
Gui, Show

DllCall("RegisterSuspendResumeNotification", "ptr", A_ScriptHwnd, "uint", 0)
Name := OnMessage(MsgNumber, "FunctionName")
If (! Name)
{
  MsgBox Message Registration Failed
  ExitApp
}

MilesAhead:
The call with "FunctionName" is not to be taken literally.  That is how it is written in the help.

I got Message Registration Succeeded with this.


--- Code: Autohotkey ---#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.; #Warn  ; Enable warnings to assist with detecting common errors.SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.DetectHiddenWindows, onLastFound := WinExist() DllCall("RegisterSuspendResumeNotification", "ptr", A_ScriptHwnd, "uint", 0)Name := OnMessage(0x218, "myfunc")If (! Name){  MsgBox Message Registration Failed  ExitApp}MsgBox Message Registration SucceededExitApp myfunc(wParam, lParam, msg, hwnd){    MsgBox myfunc was called}

SvenBent:
Adding in more and more stuff Igot it to work then i started to removde stuff and got it al lthe way down to this




--- ---#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetBatchLines 1


Gui +LastFound
OnMessage(0x218, "WM_POWERBROADCAST")

return



WM_POWERBROADCAST(wparam, lparam)
{
msgbox %wparam% %lparam%
}

which works.  so just the Gui +Lastfound made it all work perfectly

I also tried your new script and i got message registration succeed



WOOOT time to put it in aaction and eliminate some looping check on A_timeIdle



Thank you for getting me on the right track

Navigation

[0] Message Index

[#] Next page

Go to full version