Jump to content

Windows Message Codes question


shEiD
 Share

Recommended Posts

A simple example (cannibalized the GUIRegisterMsg example):

#include <WindowsConstants.au3>

$Form1 = GUICreate("test", 190, 100, -1, -1)
$Input1 = GUICtrlCreateInput("", 20, 20, 150, 21)
$Button1 = GUICtrlCreateButton("button", 60, 60, 75, 25)
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUISetState(@SW_SHOW)

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

Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    $hCtrl = $lParam
    ConsoleWrite("GUIHWnd" & @TAB & ":" & $hWnd & @LF & _
            "MsgID" & @TAB & ":" & $Msg & @LF & _
            "wParam" & @TAB & ":" & $wParam & @LF & _
            "lParam" & @TAB & ":" & $lParam & @LF & _
            "Code" & @TAB & ":" & $nNotifyCode & @LF & _
            "CtrlID" & @TAB & ":" & $nID & @LF & _
            "CtrlHwnd:" & $hCtrl & @LF & @LF)
EndFunc   ;==>MY_WM_COMMAND

Questions:

How do I match the codes generated by MY_WM_COMMAND() to the codes the "Windows Message Codes" list in AutoIt's help file? I mean the codes results in the example do not match neither "$wParam" nor "Code" values..?

martin points to msdn library for more info on notifications, but I can't find the list of codes anywhere on msdn. Sorry, I'm not used to msdn library. Let's say I go to Edit Control then to Notifications > EN_CHANGE - there is no code value provided there :x

Where can I find a complete list of windows message codes?

Thanks in advance.

Edited by shEiD
Link to comment
Share on other sites

  • Moderators

shEiD,

How do I match the codes generated by MY_WM_COMMAND() to the codes the "Windows Message Codes" list in AutoIt's help file?

You cannot. The codes in the Help file are the top-level messages of which WM_COMMAND is one - you can see it in the list as "WM_COMMAND 0x0111".

What you get in the 4 handler parameters is information such as the handle of the GUI which sent the message, the specific sub-message that was sent, the handle and/or ControlID of the control that was actioned, etc... These can be simple values (as shown by the $hCtrl = $lParam line), set in the Hi/Lo parts of a doubleword (as shown by the $nNotifyCode and $nID lines) or even a pointer to a larger structure with many elements. You have to know how each top-level message treats its parameters to know how to get the details from them - MSDN is your friend here. :x

Notifications > EN_CHANGE - there is no code value provided there

Yes, one of many annoying aspects of MSDN. However, the AutoIt Devs have been very kind and most of the constants are in the relevant Constants.au3 #include file so you do not have to worry about the numeric value - for example, $EN_CHANGE is in EditConstants.au3 and is actually 0x300. :P

I hope that helps. I have been toying for a while with producing something for the Wiki which sets out the more common messages and how to get the important values from the parameters - perhaps I will finally produce it this spring. But do not hold your breath! :shifty:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thank You for answers, I spent hours on this yesterday :x

You cannot. The codes in the Help file are the top-level messages of which WM_COMMAND is one - you can see it in the list as "WM_COMMAND 0x0111".

What you get in the 4 handler parameters is information such as the handle of the GUI which sent the message, the specific sub-message that was sent, the handle and/or ControlID of the control that was actioned, etc...

I figured out that yesterday by trying to work out how some examples do it and how could I use them to do what I wanna do.

You have to know how each top-level message treats its parameters to know how to get the details from them - MSDN is your friend here.

When I could not find the codes in msdn it made me think that I'm not understanding this correctly. It's messed up, why would they not provide the codes? Or do they, and I just don't know how to find them?

Yes, one of many annoying aspects of MSDN. However, the AutoIt Devs have been very kind and most of the constants are in the relevant Constants.au3 #include file so you do not have to worry about the numeric value - for example, $EN_CHANGE is in EditConstants.au3 and is actually 0x300.

I found them in #includes, but it seems not all of them, that made me confused even more... I needed "on change" notification for Input control, but could not find it. Would $EN_CHANGE = 0x300 from EditConstants.au3 be ok to use with Input control?

I hope that helps. I have been toying for a while with producing something for the Wiki which sets out the more common messages and how to get the important values from the parameters - perhaps I will finally produce it this spring. But do not hold your breath! :lol:

Thank You, it helps so much, at least I know I'm not mad :P Explanation of this would be awesome, hope you'll be able to do it :shifty:

Good for endless hours of exploring and learning :nuke: : MSDN: About Messages and Message Queues.

Thanks, will try to read that, though I'm completely new to this, so it'll be long and hard I guess. Your description does not inspire confidence :(

I needed to catch notifications for 2 things in my gui:

1. change in the Input control (data in another control reacts "live" on the text being entered in the Input control,

2. click on listview item, ie: on click I check if any items are selected, or there are no selections.

Here is how I managed to acomplish these two things:

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") ; for input
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; for listview items

Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $id = BitAND($wParam, 0x0000FFFF)
    If $id = 4 Or $id = 5 Then
        If $nNotifyCode = 768 Then
            ; code
            ConsoleWrite("input control changed" & @CRLF)
        EndIf
    EndIf
EndFunc   ;==>MY_WM_COMMAND

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $iIDFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $iIDFrom
        Case $ListView22
            Switch $iCode
                Case $NM_CLICK
                    Switch _GUICtrlListView_GetSelectedCount($ListView22)
                        Case 0
                            ConsoleWrite("no items selected" & @CRLF)
                        Case Else
                            ConsoleWrite("items selected" & @CRLF)
                    EndSwitch
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_NOTIFY

Maybe there is a better way to do this?

Edited by shEiD
Link to comment
Share on other sites

  • Moderators

shEiD,

Would $EN_CHANGE = 0x300 from EditConstants.au3 be ok to use with Input control?

An Input is actually an Edit control forced into single line mode - so it is exactly what you need! :P

And your message handlers look fine to me. Everyone has their own way of ordering the parameters - as long as you confirm the value of the ones you need to check the actual code you use is not that important. What is important is not staying in the handler any longer than you must - no blocking functions, or even very long ones. :x

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...