Jump to content

_GUICtrlComboBoxEx_Create() and WM_NOTIFY


Yashied
 Share

Recommended Posts

When I create Combo by using _GUICtrlComboBoxEx_Create() I can control it through WM_NOTIFY message. But if I add icons, messages are not received. Has anyone encountered this problem?

Thanks.

#Include <GUIComboBoxEx.au3>
#Include <GUIImageList.au3>
#Include <WindowsConstants.au3>

GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')

Global $Index = -1

$hForm = GUICreate('MyGUI', 400, 300)
$hCombo = _GUICtrlComboBoxEx_Create($hForm, '', 2, 2, 394, 268, $CBS_DROPDOWNLIST)
$Label = GUICtrlCreateLabel('', 4, 280, 40, 16)
GUISetState()

;$hImage = _GUIImageList_Create(16, 16, 5, 1)
;_GUIImageList_AddIcon($hImage, @SystemDir & '\shell32.dll', 4)
;_GUICtrlComboBoxEx_SetImageList($hCombo, $hImage)
;$Index = 0

_GUICtrlComboBoxEx_AddString($hCombo, 'String1', $Index, $Index)
_GUICtrlComboBoxEx_AddString($hCombo, 'String2', $Index, $Index)
_GUICtrlComboBoxEx_AddString($hCombo, 'String3', $Index, $Index)
_GUICtrlComboBoxEx_SetCurSel($hCombo, 0)

Do
Until GUIGetMsg() = -3

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    Local $tNMCOMBOBOXEX = DllStructCreate($tagNMCOMBOBOXEX, $lParam)
    Local $hWndFrom = DllStructGetData($tNMCOMBOBOXEX, 'hWndFrom')
    Local $Code = DllStructGetData($tNMCOMBOBOXEX, 'Code')

    Switch $hWndFrom
        Case $hCombo
            Switch $Code
                Case $CBEN_GETDISPINFOA, $CBEN_GETDISPINFOW
                    GUICtrlSetData($Label, DllStructGetData($tNMCOMBOBOXEX, 'Item'))
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_NOTIFY
Link to comment
Share on other sites

Hi Yashied.

Does this code help?

#include <GuiComboBoxEx.au3>
#include <GuiImageList.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)


_Main()

Func _Main()
    Global $msg, $hGUI, $hImage, $combobox, $button, $sText
    
    ; Create GUI
    $hGUI = GUICreate("ComboBoxEx Get Text with Icon", 400, 300)
    $combobox = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 394, 100)
    GUISetState()

    $button = GUICtrlCreateButton("Get text", 50, 150, 100, 20)
    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    For $x = 0 To 20
        _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", $x)
    Next
    _GUICtrlComboBoxEx_SetImageList($combobox, $hImage)
    _GUICtrlComboBoxEx_InitStorage($combobox, 150, 300)
    _GUICtrlComboBoxEx_BeginUpdate($combobox)

    For $x = 0 To 20
        _GUICtrlComboBoxEx_AddString($combobox, StringFormat("%03d : Random string", Random(1, 200, 1)), $x, $x)
    Next

    _GUICtrlComboBoxEx_EndUpdate($combobox)
    GuiRegisterMsg($WM_COMMAND,"MY_WM_COMMAND")
Global $fComboFocused = False
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $button
                _GUICtrlComboBoxEx_GetItemText($combobox, _GUICtrlComboBoxEx_GetCurSel($combobox), $sText)
                MsgBox(4160, "Information", "Edit Text: " & $sText)
        EndSwitch
    WEnd
EndFunc   ;==>_Main

 Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = _HiWord($wParam)
    Local $nID = _LoWord($wParam)
 ; Local $hCtrl = $lParam

    Switch $lParam
    Case $combobox
            Switch $nNotifyCode
            Case $CBN_SETFOCUS
                ConsoleWrite("Focus"&@crlf)
        Case $CBN_KILLFOCUS
            ConsoleWrite("Kill Focus"&@crlf)
        Case $CBN_SELCHANGE
            ConsoleWrite("Selection Changed"&@crlf) 
        Case $CBN_DROPDOWN
            ConsoleWrite("Drop Down"&@crlf)
                
        EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>MY_WM_COMMAND

Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc ;==>_LoWord
Link to comment
Share on other sites

Okay, how about this?

#include <GuiComboBoxEx.au3>
#include <GuiImageList.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)


_Main()

Func _Main()
    Global $msg, $hGUI, $hImage, $combobox, $button, $sText
    
    ; Create GUI
    $hGUI = GUICreate("ComboBoxEx Get Text with Icon", 400, 300)
    $combobox = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 394, 100)
    GUISetState()

    $button = GUICtrlCreateButton("Get text", 50, 150, 100, 20)
    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    For $x = 0 To 20
        _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", $x)
    Next
    _GUICtrlComboBoxEx_SetImageList($combobox, $hImage)
    _GUICtrlComboBoxEx_InitStorage($combobox, 150, 300)
    _GUICtrlComboBoxEx_BeginUpdate($combobox)

    For $x = 0 To 20
        _GUICtrlComboBoxEx_AddString($combobox, StringFormat("%03d : Random string", Random(1, 200, 1)), $x, $x)
    Next

    _GUICtrlComboBoxEx_EndUpdate($combobox)
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
 ;   GuiRegisterMsg($WM_COMMAND,"MY_WM_COMMAND")
Global $fComboFocused = False
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $button
                _GUICtrlComboBoxEx_GetItemText($combobox, _GUICtrlComboBoxEx_GetCurSel($combobox), $sText)
                MsgBox(4160, "Information", "Edit Text: " & $sText)
        EndSwitch
    WEnd
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  $combobox
            Switch $iCode
                Case $CBEN_BEGINEDIT ; Sent when the user activates the drop-down list or clicks in the control's edit box.
                    ConsoleWrite("Beginedita"&@CRLF)
                    Return 0
                Case $CBEN_DRAGBEGINA, $CBEN_DRAGBEGINW
                        ConsoleWrite("Drag Begins"&@CRLF)
                    ; 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.
                   ConsoleWrite("Endedita"&@CRLF)
                    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
                    
                    ConsoleWrite("CBEN_GETDISPINFOA"&@CRLF)
                    Return 0
                Case $CBEN_INSERTITEM
                    ConsoleWrite("CBEN_INSERTITEM"&@CRLF)
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Link to comment
Share on other sites

When I create Combo by using _GUICtrlComboBoxEx_Create() I can control it through WM_NOTIFY message. But if I add icons, messages are not received. Has anyone encountered this problem?

In order to receive CBEN_GETDISPINFO the text of the combobox item must be set to LPSTR_TEXTCALLBACK which is an integer equal -1 (s. http://msdn.microsoft.com/en-us/library/bb775746%28v=VS.85%29.aspx ). Not sure if ComboboxEx UDF supports it. There's a similar problem in ToolTip UDF however (s. #1513) and here's a workaround. Edited by doudou

UDFS & Apps:

Spoiler

DDEML.au3 - DDE Client + Server
Localization.au3 - localize your scripts
TLI.au3 - type information on COM objects (TLBINF emulation)
TLBAutoEnum.au3 - auto-import of COM constants (enums)
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector - OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Link to comment
Share on other sites

Hi!

WM_NOTIFY works somehow stange...

I'm trying to tell WM_NOTIFY to respond when an item in the ComboBox control is clicked...

Has there an other event to be triggered? The events in your sample scripts seem not to work.

No luck so far...

Any ideas?

Greets,

-supersonic.

Link to comment
Share on other sites

I'm trying to tell WM_NOTIFY to respond when an item in the ComboBox control is clicked...

Has there an other event to be triggered?

There is no such event. Comboboxes send messages when an item is selected or the box itself is clicked.

The events in your sample scripts seem not to work.

Would you explain, whom do you mean by "you"? And what scripts? Strange way asking for help...

UDFS & Apps:

Spoiler

DDEML.au3 - DDE Client + Server
Localization.au3 - localize your scripts
TLI.au3 - type information on COM objects (TLBINF emulation)
TLBAutoEnum.au3 - auto-import of COM constants (enums)
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector - OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Link to comment
Share on other sites

Going through the includes...these are your options

Global Const $CBN_CLOSEUP = 8
Global Const $CBN_DBLCLK = 2
Global Const $CBN_DROPDOWN = 7
Global Const $CBN_EDITCHANGE = 5
Global Const $CBN_EDITUPDATE = 6
Global Const $CBN_ERRSPACE = (-1)
Global Const $CBN_KILLFOCUS = 4
Global Const $CBN_SELCHANGE = 1
Global Const $CBN_SELENDCANCEL = 10
Global Const $CBN_SELENDOK = 9
Global Const $CBN_SETFOCUS = 3

Global Const $CBEN_FIRST = (-800)
Global Const $CBEN_LAST = (-830)
Global Const $CBEN_BEGINEDIT = ($CBEN_FIRST - 4)
Global Const $CBEN_DELETEITEM = ($CBEN_FIRST - 2)
Global Const $CBEN_DRAGBEGINA = ($CBEN_FIRST - 8)
Global Const $CBEN_DRAGBEGINW = ($CBEN_FIRST - 9)
Global Const $CBEN_ENDEDITA = ($CBEN_FIRST - 5)
Global Const $CBEN_ENDEDITW = ($CBEN_FIRST - 6)
Global Const $CBEN_GETDISPINFO = ($CBEN_FIRST - 0)
Global Const $CBEN_GETDISPINFOA = ($CBEN_FIRST - 0)
Global Const $CBEN_GETDISPINFOW = ($CBEN_FIRST - 7)
Global Const $CBEN_INSERTITEM = ($CBEN_FIRST - 1)
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...