Jump to content

Windows Messages - Combo DropDownList


DarkBoost
 Share

Recommended Posts

Hi I am finding it difficult to locate in the Help Document and even in Google Searches how to execute a (GUIRegisterMsg) function when an adjustment is made via a ComboBox or DropDownList. I thought it would be something as simple as ==> GUIRegisterMsg($WM_DROPDOWNLIST, "My_Function") <== but yeah this doesn't exist.

Anyone know the answer?

Thanks,

Link to comment
Share on other sites

Look at windows message WM_COMMAND, that's the one that gets fired off when you change the combobox drop down state.

Here's a demo program that I posted some time ago, but I added a ComboBox to show what messages are received.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MenuConstants.au3>
GUIRegisterMsg($WM_COMMAND, "_WM_EXTRACTOR")
GUIRegisterMsg($WM_SYSCOMMAND, "_WM_EXTRACTOR")
GUIRegisterMsg($WM_HSCROLL, "_WM_EXTRACTOR")
$GUI = GUICreate("Test GUI", 200, 200, -1, -1, BitOR($WS_THICKFRAME, $gui_ss_default_gui))
$Button = GUICtrlCreateButton("Test", 20, 20)
$Button2 = GUICtrlCreateButton(" Another Test ", 20, 100)
$Slider = GUICtrlCreateSlider(20, 60, 150)
$hSlider = GUICtrlGetHandle($Slider)
$Combo = GUICtrlCreateCombo("", 80, 20, 40)
GUICtrlSetData($Combo, "1|2|3|4|5")
GUISetState()
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $Button
            MsgBox(0, "", "You pressed the button marked TEST")
        Case $Button2
            MsgBox(0, "", "You pressed the button marked 'Another Test'")
    EndSwitch
WEnd
Func _WM_EXTRACTOR($hWnd, $iMsg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0x0000FFFF)
    Local $hCtrl = $lParam
    #forceref $hWnd, $iMsg, $wParam, $lParam
    Switch $iMsg
        Case $WM_HSCROLL
            Switch $lParam
                Case $hSlider
                    ConsoleWrite("+Slider moved to: " & GUICtrlRead($Slider) & @LF)
            EndSwitch
        Case $WM_VSCROLL
        Case $WM_COMMAND
            Switch $nID
                Case $Button
                    ConsoleWrite(">Button Test pressed" & @LF)
                Case $Button2
                    ConsoleWrite(">Button Another Test pressed" & @LF)
                Case Else
                    MsgBox(0, "MY_WM_COMMAND", "GUIHWnd" & @TAB & ":" & $hWnd & @LF & _
                            "MsgID" & @TAB & ":" & $msg & @LF & _
                            "wParam" & @TAB & ":" & $wParam & @LF & _
                            "lParam" & @TAB & ":" & $lParam & @LF & @LF & _
                            "WM_COMMAND - Infos:" & @LF & _
                            "-----------------------------" & @LF & _
                            "Code" & @TAB & ":" & $nNotifyCode & @LF & _
                            "CtrlID" & @TAB & ":" & $nID & @LF & _
                            "CtrlHWnd" & @TAB & ":" & $hCtrl)
            EndSwitch
        Case $WM_SYSCOMMAND
            Switch $wParam
                Case $SC_CLOSE
                    ConsoleWrite("!Exit pressed" & @LF)
                    Exit
                Case $SC_RESTORE
                    ConsoleWrite("!Restore window" & @LF)
                Case $SC_MINIMIZE
                    ConsoleWrite("!Minimize Window" & @LF)
                Case $SC_MOUSEMENU + 3
                    ConsoleWrite("!System menu pressed" & @LF)
                Case $SC_MOVE
                    ConsoleWrite("!System menu Move Option pressed" & @LF)
                    Return 0
                Case $SC_SIZE
                    ConsoleWrite("!System menu Size Option pressed" & @LF)
                    Return 0
                Case $SC_MOUSEMENU + 2 ; This and the following case statements are only valid when the GUI is resizable
                    ConsoleWrite("!Right side of GUI clicked" & @LF)
                    Return 0
                Case $SC_MOUSEMENU + 1
                    ConsoleWrite("!Left side of GUI clicked" & @LF)
                    Return 0
                Case $SC_MOUSEMENU + 8
                    ConsoleWrite("!Lower Right corner of GUI clicked" & @LF)
                    Return 0
                Case $SC_MOUSEMENU + 7
                    ConsoleWrite("!Lower Left corner of GUI clicked" & @LF)
                    Return 0
                Case $SC_MOUSEMENU + 6
                    ConsoleWrite("!Bottom side of GUI clicked" & @LF)
                    Return 0
                Case Else
                    MsgBox(0, "MY_SYSCOMMAND", "GUIHWnd" & @TAB & ":" & $hWnd & @LF & _
                            "MsgID" & @TAB & ":" & $msg & @LF & _
                            "wParam" & @TAB & ":" & $wParam & @LF & _
                            "lParam" & @TAB & ":" & $lParam & @LF & @LF & _
                            "WM_COMMAND - Infos:" & @LF & _
                            "-----------------------------" & @LF & _
                            "Code" & @TAB & ":" & $nNotifyCode & @LF & _
                            "CtrlID" & @TAB & ":" & $nID & @LF & _
                            "CtrlHWnd" & @TAB & ":" & $hCtrl)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_EXTRACTOR

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

Currently I am using the WM_COMMAND and how (with my limited knowledge in this area) I understand this it's basically collecting all the scripts data which passes through the systems memory and then executes the assigned function. All the "WM_" Message Codes are simply preset filters to collect data from a particular GUI Object which does not seem to include a Combo/DropDownLists. From your example it looks like its manually filtering the WM_COMMAND by checking if the data passed is not a WM_HSCROLL, WM_VSCROLL, WM_SYSCOMMAND then only executing the function when anything else triggers this which would only leave the remaining ComboBox?

I apologise for my noobness, just trying to understand... this is an area I rarely use and lack the understanding to solve myself!

Link to comment
Share on other sites

You'll notice when you run it that whenever you do anything to/with the Combobox, it fires off a WM_COMMAND message. The msgbox that pops up tells you what message is received and from which control. The only reason the msgbox pops up in this demo is because I haven't defined any of the messages from the combobox to indicate anything in this script.

You'll have to see what the messages are from the combo for each action you're trying to monitor, and then write your script to interpret these messages.

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

Yes, otherwise the demo script wouldn't work, they have to be consistent or else the whole Windows messaging system is useless.

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