本帖最后由 lixiaolong 于 2012-3-10 21:18 编辑
#include <GuiComboBoxEx.au3>
#include <GuiImageList.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
Global $hGUI, $hImage, $hCombo, $msg, $iMemo
Global $Color[3] = ['0xFF0000', '0x00FF00', '0x0000FF']
_Main()
Func _Main()
; 创建界面
$hGUI = GUICreate("ComboBoxEx Image List", 400, 300)
$hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 394, -1, $CBS_DROPDOWNLIST, $CBES_EX_NOSIZELIMIT)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
$hImage = _GUIImageList_Create(24, 24, 5, 3)
For $i = 0 To UBound($Color) - 1
_GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, $Color[$i], 24, 24))
Next
; 设置图像列表
_GUICtrlComboBoxEx_SetImageList($hCombo, $hImage)
For $x = 0 To UBound($Color) - 1
_GUICtrlComboBoxEx_AddString($hCombo, $Color[$x], $x, $x)
Next
_GUICtrlComboBoxEx_SetCurSel($hCombo, 0)
While 1
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
EndSwitch
WEnd
EndFunc ;==>_Main
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iCode, $Count, $sText
$hWndFrom = $ilParam
$iCode = BitShift($iwParam, 16)
Switch $hWndFrom
Case $hCombo
Switch $iCode
Case $CBN_SELCHANGE ; Sent when the user changes the current selection in the list box of a combo box
$Count = _GUICtrlComboBoxEx_GetCurSel($hCombo)
;~ $sText = _GUICtrlComboBoxEx_GetItem($hCombo, $Count); $sText[0]
_GUICtrlComboBoxEx_GetItemText ($hCombo, $Count, $sText)
MsgBox(0, 0, $sText)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
|