Jump to content

I don't seem to understand how WM_NOTIFY works


Recommended Posts

Hi everyone,

I'm relatively new to AutoIT, but I recently found myself facing the WM_NOTIFY function and don't seem to actually catch up how it does work ...

First, i've been following this guide from the Wiki : Tutorial on GUIRegisterMsg

And so i've decided to try on my own, and as an example, to catch BN_CLICKED with the WM_NOTIFY function.

Here is my actual code ( that has been created from pieces of code I gathered around the net ) :

#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>
#include <GUIConstantsEX.au3>

 $MyGUI = GUICreate("MyGUI",200,200,200,200)
 $iBtn = GUICtrlCreateButton("MyButton",20,20,50,50)
 $iBtn2 = GUICtrlCreateButton("MyButton2",70,70,50,50)
 GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY,"WM_NOTIFY")

 While 1
 $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        Exit 
    EndSwitch
 WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
Switch _WinAPI_LoWord($wParam)
        Case $iBtn
                Switch _WinAPI_HiWord($wParam)
                        Case $BN_CLICKED
                        MsgBox(48,'$iBtn','This button was clicked !')
                        Return $GUI_RUNDEFMSG
                EndSwitch
        Case $iBtn2
                Switch _WinAPI_HiWord($wParam)
                        Case $BN_CLICKED
                        MsgBox(48,'$iBtn2','This button was clicked !')
                        Return $GUI_RUNDEFMSG
                EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc

I only have to hover the button to trigger the WM_NOTIFY, but I'm willing to trigger it only on CLICK of these buttons.

From what I've gathered on MSDN, BN_CLICKED is recieved from WM_COMMAND message, but in this example I don't specify WM_COMMAND ... 

I've seen som WM_NOTIFY function that are using a Structure, how do I know what type of data to insert on this structure ( I can't seem to find it on MSDN for some of them ) ?

Is it possible for me to find a full documentation for real beginners about this on the WEB, or do I have to actually check every example on the WEB and adapt them to make it works like I need it to work ?

Thanks in advance for your answers,

Valzul.

Link to comment
Share on other sites

I created a script that demos how to use the windows messages to find out what control is being actioned. See the link in my signature to it, it might give you some ideas.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks BrewManNH !

I sure will be learning from your demo ! :)

Is it possible to handle every notification code using your definition of _WM_EXTRACTOR ? : 

Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0x0000FFFF)
    Local $hCtrl = $lParam
    #forceref $hWnd, $iMsg, $wParam, $lParam

Is this way of defining the function used for another purpose ? Or is it a different way to code the same functionnality as your _WM_EXTRACTOR ?  :

#forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code)

( The example above was taken from this post of users's Vision : https://www.autoitscript.com/forum/topic/105993-listview-wm_notify/ )

Valzul.

Link to comment
Share on other sites

Theoretically you can add cases for every type of Window's message in the extractor function.

I'm not sure of the point of the struct in that code, the windows message handler already supplies the $lparam, so putting it into the struct and then retrieving it on the next line doesn't seem to make sense to me, but I'm not sure what was being done in that code.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...