创建一个组合对话框控件
#Include <GuiComboBox.au3>
_GUICtrlComboBox_Create($hWnd, $sText, $iX, $iY[, $iWidth = 100[, $iHeight = 120[, $iStyle = 0x00200042[, $iExStyle = 0x00000000]]]])
$hWnd | 父窗或属主窗体句柄 |
$sText | 被添加的项目字符串,多项目由 "|" 分隔 |
$iX | 控件水平位置 |
$iY | 控件垂直位置 |
$iWidth | [可选参数] 控件宽度 |
$iHeight | [可选参数] 控件高度 |
$iStyle | [可选参数] 控件样式: $CBS_AUTOHSCROLL - 当用户在编辑框行尾输入字符时, 文本自动向左滚动. $CBS_DISABLENOSCROLL - 显示禁用的垂直滚动条. $CBS_DROPDOWN - 类似 $CBS_SIMPLE, 只有当用户选择编辑框边上的下拉按钮时才显示列表框. $CBS_DROPDOWNLIST - 类似 $CBS_DROPDOWN, 编辑框使用与编辑框等宽的蓝色静态条显示当前选择项文本, 常规时蓝色静态条与选中项文本等宽. 点击编辑框内除下拉箭头外任意地方均可打开列表框,且禁用编辑框修改输入 (译注:依据示例脚本运行结果翻译) $CBS_LOWERCASE - 所有文本转换为小写 $CBS_NOINTEGRALHEIGHT - 组合控件的大小由应用程序创建时指定. $CBS_OEMCONVERT - 转换编辑控件的输入文字 Windows 字符集为 OEM 字符集,然后再返回到 Windows 字符集. $CBS_OWNERDRAWFIXED - 指定列表框的所属者负责刷新内容,列表框中项目高度相同. $CBS_OWNERDRAWVARIABLE - 指定列表框的所属者负责刷新内容,列表框中项目高度可变. $CBS_SIMPLE - 总是显示列表框 $CBS_SORT - 自动排序列表框的字符串 $CBS_UPPERCASE - 所有文本转换为大写 [可选参数] 默认 : $CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL 强制 : $WS_CHILD, $WS_TABSTOP, $WS_VISIBLE |
$iExStyle | [可选参数] 控件扩展样式,对应于标准$WS_EX_ 常量. |
成功: | 返回 ComboBox 组合控件句柄. |
失败: | 返回 0 |
#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
$Debug_CB = False ;检查传递给 ComboBox/ComboBoxEx 函数的类名, 设置为True并输出到一个控件的句柄,用于检查它是否工作
Global $hCombo
_Main()
Func _Main()
Local $hGUI
; 创建 GUI
$hGUI = GUICreate("(UDF) ComboBox Create", 400, 296)
$hCombo = _GUICtrlComboBox_Create($hGUI, "", 2, 2, 396, 296)
GUISetState()
; 添加文件
_GUICtrlComboBox_BeginUpdate($hCombo)
_GUICtrlComboBox_AddDir($hCombo, "", $DDL_DRIVES, False)
_GUICtrlComboBox_EndUpdate($hCombo)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
; 循环直到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iIDFrom, $iCode
$hWndFrom = $ilParam
$iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
$iCode = BitShift($iwParam, 16) ; Hi Word
Switch $hWndFrom
Case $hCombo
Switch $iCode
Case $CBN_CLOSEUP ; Sent when the list box of a combo box has been closed
_DebugPrint("$CBN_CLOSEUP" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
Case $CBN_DBLCLK ; Sent when the user double-clicks a string in the list box of a combo box
_DebugPrint("$CBN_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
Case $CBN_DROPDOWN ; Sent when the list box of a combo box is about to be made visible
_DebugPrint("$CBN_DROPDOWN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
Case $CBN_EDITCHANGE ; Sent after the user has taken an action that may have altered the text in the edit control portion of a combo box
_DebugPrint("$CBN_EDITCHANGE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
Case $CBN_EDITUPDATE ; Sent when the edit control portion of a combo box is about to display altered text
_DebugPrint("$CBN_EDITUPDATE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
Case $CBN_ERRSPACE ; Sent when a combo box cannot allocate enough memory to meet a specific request
_DebugPrint("$CBN_ERRSPACE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
Case $CBN_KILLFOCUS ; Sent when a combo box loses the keyboard focus
_DebugPrint("$CBN_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
Case $CBN_SELCHANGE ; Sent when the user changes the current selection in the list box of a combo box
_DebugPrint("$CBN_SELCHANGE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
Case $CBN_SELENDCANCEL ; Sent when the user selects an item, but then selects another control or closes the dialog box
_DebugPrint("$CBN_SELENDCANCEL" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
Case $CBN_SELENDOK ; Sent when the user selects a list item, or selects an item and then closes the list
_DebugPrint("$CBN_SELENDOK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
Case $CBN_SETFOCUS ; Sent when a combo box receives the keyboard focus
_DebugPrint("$CBN_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
"-->IDFrom:" & @TAB & $iIDFrom & @LF & _
"-->Code:" & @TAB & $iCode)
; 没有返回值
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Func _DebugPrint($s_text, $line = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @LF & _
"+======================================================" & @LF & _
"-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
"+======================================================" & @LF)
EndFunc ;==>_DebugPrint