Jump to content

Recommended Posts

Posted

Hi all,

Here is a one way to deal with some combobox events:

#include <GuiConstants.au3>

Global Const $WM_COMMAND = 0x0111

$Gui = GuiCreate("ComboBox Handler Example")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

$ComboBox = GUICtrlCreateCombo("", 20, 80)
GUICtrlSetData(-1, "Some text|More text|another text")

;Just for checking the combo focus
GUICtrlCreateInput("", 20, 120)

GUISetState()

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

Func WM_COMMAND($hWndGUI, $MsgID, $WParam, $LParam)
    If Not BitAND(WinGetState($hWndGUI), 2) Then Return $GUI_RUNDEFMSG
    
    Local $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word
    Local $iCode = BitShift($wParam, 16) ; Hi Word
    
    Switch $iIDFrom
        Case $ComboBox
            Switch $iCode
                Case 1
                    Local $sComboData = GUICtrlRead($iIDFrom)
                    Local $sComboIndex = ControlCommand($hWndGUI, "", $iIDFrom, "FindString", $sComboData)
                    PrintF("ComboBox selected: [Index = " & $sComboIndex & "], Text = " &  $sComboData)
                Case 3
                    PrintF("ComboBox has focus")
                Case 4
                    PrintF("ComboBox lost focus")
                Case 5, 6
                    PrintF("ComboBox changed/updated: " & GUICtrlRead($iIDFrom))
                Case 7
                    PrintF("ComboBox is Opened")
                Case 8
                    PrintF("ComboBox is Closed")
                Case Else
                    PrintF($iCode)
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc

Func PrintF($sStr, $Line=@ScriptLineNumber)
    ConsoleWrite(@LF & "+======================================================" & @LF & _
                "--> Script Line (" & $Line & "):" & @LF & "!" & @TAB & $sStr & @LF & _
                "+======================================================")
EndFunc

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted
  Quote

look in the help each UDF that has a xxxx_Create you'll find the event handler

It's in the last AutoIt release? i use 3.8.2.1.

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

  • 7 years later...

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
  • Recently Browsing   0 members

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