Jump to content

Event of ComboEx not received?


Bot
 Share

Recommended Posts

Hello,

Here is the code I copied from the AutoIT manual. When the $hCombo has no additional style, the code works fine. But after I added a style $CBS_DROPDOWNLIST which set the state the combo to read-only, then the events $CBEN_ENDEDITA, $CBEN_ENDEDITW are missing. So how can I know if the user has selected an item from the control's drop-down list?

Thanks

#include <GuiComboBoxEx.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

Opt('MustDeclareVars', 1)

$Debug_CB = False ; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work

Global $hCombo

_Main()

Func _Main()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("ComboBoxEx Create", 400, 300)
    $hCombo = _GUICtrlComboBoxEx_Create ($hGUI, "This is a test|Line 2", 2, 2, 394, 268, $CBS_DROPDOWNLIST)
    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    _GUICtrlComboBoxEx_AddString ($hCombo, "Some More Text")
    _GUICtrlComboBoxEx_InsertString ($hCombo, "Inserted Text", 1)

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hCombo
            Switch $iCode
                Case $CBEN_BEGINEDIT ; Sent when the user activates the drop-down list or clicks in the control's edit box.
                    _DebugPrint("$CBEN_BEGINEDIT" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    Return 0
                Case $CBEN_DELETEITEM
                    _DebugPrint("$CBEN_DELETEITEM" & _GetComboBoxEx($ilParam))
                    Return 0
                Case $CBEN_DRAGBEGINA, $CBEN_DRAGBEGINW
                    Local $tInfo = DllStructCreate($tagNMCBEDRAGBEGIN, $ilParam)
                    If DllStructGetData($tInfo, "ItemID") Then _DebugPrint("$CBEN_DRAGBEGIN" & _GetComboBoxEx($ilParam))
                    _DebugPrint("$CBEN_DRAGBEGIN" & @LF & "--> hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @LF & _
                            "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @LF & _
                            "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @LF & _
                            "-->ItemID:" & @TAB & DllStructGetData($tInfo, "ItemID") & @LF & _
                            "-->Text:" & @TAB & DllStructGetData($tInfo, "Text"))
                    ; return is ignored
                Case $CBEN_ENDEDITA, $CBEN_ENDEDITW ; Sent when the user has concluded an operation within the edit box or has selected an item from the control's drop-down list.
                    Local $tInfo = DllStructCreate($tagNMCBEENDEDIT, $ilParam)
                    _DebugPrint("$CBEN_ENDEDIT" & @LF & "--> hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @LF & _
                            "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @LF & _
                            "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @LF & _
                            "-->fChanged:" & @TAB & DllStructGetData($tInfo, "fChanged") & @LF & _
                            "-->NewSelection:" & @TAB & DllStructGetData($tInfo, "NewSelection") & @LF & _
                            "-->Text:" & @TAB & DllStructGetData($tInfo, "Text") & @LF & _
                            "-->Why:" & @TAB & DllStructGetData($tInfo, "Why"))
                    Return False ; accept the notification and allow the control to display the selected item
;~                  Return True  ; otherwise
                Case $CBEN_GETDISPINFOA, $CBEN_GETDISPINFOW ; Sent to retrieve display information about a callback item
                    _DebugPrint("$CBEN_GETDISPINFO" & _GetComboBoxEx($ilParam))
                    Return 0
                Case $CBEN_INSERTITEM
                    Local $tInfo = DllStructCreate($tagNMCOMBOBOXEX, $ilParam)
                    Local $tBuffer = DllStructCreate("wchar Text[" & DllStructGetData($tInfo, "TextMax") & "]", DllStructGetData($tInfo, "Text"))
                    _DebugPrint("$CBEN_INSERTITEM" & @LF & "--> hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @LF & _
                            "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @LF & _
                            "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @LF & _
                            "-->Mask:" & @TAB & DllStructGetData($tInfo, "Mask") & @LF & _
                            "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
                            "-->Text:" & @TAB & DllStructGetData($tBuffer, "Text") & @LF & _
                            "-->TextMax:" & @TAB & DllStructGetData($tInfo, "TextMax") & @LF & _
                            "-->Indent:" & @TAB & DllStructGetData($tInfo, "Indent") & @LF & _
                            "-->Image:" & @TAB & DllStructGetData($tInfo, "Image") & @LF & _
                            "-->SelectedImage:" & @TAB & DllStructGetData($tInfo, "SelectedImage") & @LF & _
                            "-->OverlayImage:" & @TAB & DllStructGetData($tInfo, "OverlayImage") & @LF & _
                            "-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _GetComboBoxEx($ilParam)
    Local $tInfo = DllStructCreate($tagNMCOMBOBOXEX, $ilParam)
    Local $aItem = _GUICtrlComboBoxEx_GetItem ($hCombo, DllStructGetData($tInfo, "Item"))
    Return @LF & "--> hWndFrom:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @LF & _
            "-->IDFrom:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @LF & _
            "-->Code:" & @TAB & DllStructGetData($tInfo, "Code") & @LF & _
            "-->Mask:" & @TAB & DllStructGetData($tInfo, "Mask") & @LF & _
            "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
            "-->Text:" & @TAB & $aItem[0] & @LF & _
            "-->TextMax:" & @TAB & $aItem[1] & @LF & _
            "-->Indent:" & @TAB & $aItem[2] & @LF & _
            "-->Image:" & @TAB & $aItem[3] & @LF & _
            "-->SelectedImage:" & @TAB & $aItem[4] & @LF & _
            "-->OverlayImage:" & @TAB & $aItem[5] & @LF & _
            "-->Param:" & @TAB & $aItem[5]
EndFunc   ;==>_GetComboBoxEx

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint
Edited by Bot
Link to comment
Share on other sites

Looks like something is wrong with the comboEx. According to msdn the notification should be sent when a user changes the selected text and there is nothing I can see to suggest that the style of the combo will affect that. You don't get $CBEN_BEGINEDIT either.

Here is one way though not the best.

#include <GuiComboBoxEx.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

Opt('MustDeclareVars', 1)

$Debug_CB = False ; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work

Global $hCombo, $newval = False, $lbl1

_Main()

Func _Main()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("ComboBoxEx Create", 400, 300)
    $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "This is a test|Line 2", 2, 2, 394, 268, $CBS_DROPDOWNLIST)
    $lbl1 = GUICtrlCreateLabel("Selected = 0", 40, 40, 100, 22)
    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    _GUICtrlComboBoxEx_AddString($hCombo, "Some More Text")
    _GUICtrlComboBoxEx_InsertString($hCombo, "Inserted Text", 1)

    ; Loop until user exits
    Do
    If $newval Then
    GUICtrlSetData($lbl1, "selected = " & _GUICtrlComboBoxEx_GetCurSel($hCombo))
    $newval = False
    EndIf

    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom

    Case $hCombo
    Switch $iCode
    Case -807
    $newval = True
    ; return is ignored

    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Looks like something is wrong with the comboEx. According to msdn the notification should be sent when a user changes the selected text and there is nothing I can see to suggest that the style of the combo will affect that. You don't get $CBEN_BEGINEDIT either.

Here is one way though not the best.

Thanks for the answer but the event in your code is triggered every time the user move mouse over items or click on the combo, which generates lots of notification and it is inconvenient some way. Are there any workaround so that I can catch the event when the user has finally selected an item of the combo box?

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