求合并_GUICtrlComboBox_Create与_GUICtrlComboBoxEx_Create的WM_NOTIFY消息
本帖最后由 kk_lee69 于 2020-6-6 16:58 编辑目前的范例中 _GUICtrlComboBoxEx_Create 的 WM_NOTIFY 几乎都是只有在下拉选择的时候 可以有消息产生 但是_GUICtrlComboBox_Create 在下拉选择的时候 几乎都不会有消息产生…… 似乎到这边 鱼与熊掌无法兼得
_GUICtrlComboBox_Create 的範例
#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("创建 ComboBox 控件", 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) ; 低位字
$iCode = BitShift($iwParam, 16) ; 高位字
Switch $hWndFrom
Case $hCombo
Switch $iCode
Case $CBN_CLOSEUP ; 发送组合框的列表框已关闭消息
_DebugPrint("关闭列表框" & @LF & "--> 控件句柄:" & @TAB & $hWndFrom & @LF & _
"--> 控件 ID:" & @TAB & $iIDFrom & @LF & _
"--> 操作代码:" & @TAB & $iCode)
; 没有返回值
Case $CBN_DBLCLK ; 发送用户双击组合框的列表框的字符串消息
_DebugPrint("$CBN_DBLCLK" & @LF & "--> 控件句柄:" & @TAB & $hWndFrom & @LF & _
"--> 控件 ID:" & @TAB & $iIDFrom & @LF & _
"--> 操作代码:" & @TAB & $iCode)
; 没有返回值
Case $CBN_DROPDOWN ; 发送组合框的列表框为可见状态的消息
_DebugPrint("$CBN_DROPDOWN" & @LF & "--> 控件句柄:" & @TAB & $hWndFrom & @LF & _
"--> 控件 ID:" & @TAB & $iIDFrom & @LF & _
"--> 操作代码:" & @TAB & $iCode)
; 没有返回值
Case $CBN_EDITCHANGE ; 发送用户在组合框的编辑控件部分修该文本的消息
_DebugPrint("$CBN_EDITCHANGE" & @LF & "--> 控件句柄:" & @TAB & $hWndFrom & @LF & _
"--> 控件 ID:" & @TAB & $iIDFrom & @LF & _
"--> 操作代码:" & @TAB & $iCode)
; 没有返回值
Case $CBN_EDITUPDATE ; 发送组合框的编辑控件显示已修改文字的消息
_DebugPrint("$CBN_EDITUPDATE" & @LF & "--> 控件句柄:" & @TAB & $hWndFrom & @LF & _
"--> 控件 ID:" & @TAB & $iIDFrom & @LF & _
"--> 操作代码:" & @TAB & $iCode)
; 没有返回值
Case $CBN_ERRSPACE ; 发送组合框无法分配足够的内存满足一个特定请求的消息
_DebugPrint("$CBN_ERRSPACE" & @LF & "--> 控件句柄:" & @TAB & $hWndFrom & @LF & _
"--> 控件 ID:" & @TAB & $iIDFrom & @LF & _
"--> 操作代码:" & @TAB & $iCode)
; 没有返回值
Case $CBN_KILLFOCUS ; 发送组合框失去键盘焦点消息
_DebugPrint("$CBN_KILLFOCUS" & @LF & "--> 控件句柄:" & @TAB & $hWndFrom & @LF & _
"--> 控件 ID:" & @TAB & $iIDFrom & @LF & _
"--> 操作代码:" & @TAB & $iCode)
; 没有返回值
Case $CBN_SELCHANGE ; 发送用户修改组合框的列表框的当前选择消息
_DebugPrint("$CBN_SELCHANGE" & @LF & "--> 控件句柄:" & @TAB & $hWndFrom & @LF & _
"--> 控件 ID:" & @TAB & $iIDFrom & @LF & _
"--> 操作代码:" & @TAB & $iCode)
; 没有返回值
Case $CBN_SELENDCANCEL ; 发送用户选择一个项目, 然后选择另一个控件或关闭对话框消息
_DebugPrint("$CBN_SELENDCANCEL" & @LF & "--> 控件句柄:" & @TAB & $hWndFrom & @LF & _
"--> 控件 ID:" & @TAB & $iIDFrom & @LF & _
"--> 操作代码:" & @TAB & $iCode)
; 没有返回值
Case $CBN_SELENDOK ; 发送用户选择一个列表项, 或者选择一个项目, 然后关闭列表消息
_DebugPrint("$CBN_SELENDOK" & @LF & "--> 控件句柄:" & @TAB & $hWndFrom & @LF & _
"--> 控件 ID:" & @TAB & $iIDFrom & @LF & _
"--> 操作代码:" & @TAB & $iCode)
; 没有返回值
Case $CBN_SETFOCUS ; 发送组合框接收键盘焦点消息
_DebugPrint("$CBN_SETFOCUS" & @LF & "--> 控件句柄:" & @TAB & $hWndFrom & @LF & _
"--> 控件 ID:" & @TAB & $iIDFrom & @LF & _
"--> 操作代码:" & @TAB & $iCode)
; 没有返回值
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Func _DebugPrint($s_text, $line = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @LF & _
"+======================================================" & @LF & _
"--> 行(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
"+======================================================" & @LF)
EndFunc ;==>_DebugPrint
_GUICtrlComboBoxEx_Create 的範例
#include <GuiComboBoxEx.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
$Debug_CB = False ; 检查传递到 ComboBox / ComboBoxEx 函数的控件类名, 设置为 True, 并使用一个句柄到另一个控件, 查看它的工作
Global $hCombo
_Main()
Func _Main()
Local $hGUI
; 创建 GUI
$hGUI = GUICreate("ComboBoxEx 函数演示", 400, 300)
$hCombo = _GUICtrlComboBoxEx_Create($hGUI, "这是测试|数据行 2", 2, 2, 394, 268)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_GUICtrlComboBoxEx_AddString($hCombo, "再加一点文字")
_GUICtrlComboBoxEx_InsertString($hCombo, "插入的文本", 1)
; 循环到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo
$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 ; 发送用户激活下拉列表或编辑框点击消息.
_DebugPrint("$CBEN_BEGINEDIT" & @LF & "--> 控件句柄:" & @TAB & $hWndFrom & @LF & _
"--> 控件 ID:" & @TAB & $iIDFrom & @LF & _
"--> 操作代码:" & @TAB & $iCode)
Return 0
Case $CBEN_DELETEITEM
_DebugPrint("$CBEN_DELETEITEM" & _GetComboBoxEx($ilParam))
Return 0
Case $CBEN_DRAGBEGINA, $CBEN_DRAGBEGINW
$tInfo = DllStructCreate($tagNMCBEDRAGBEGIN, $ilParam)
If DllStructGetData($tInfo, "ItemID") Then _DebugPrint("$CBEN_DRAGBEGIN" & _GetComboBoxEx($ilParam))
_DebugPrint("$CBEN_DRAGBEGIN" & @LF & "--> 控件句柄:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @LF & _
"--> 控件 ID:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @LF & _
"--> 操作代码:" & @TAB & DllStructGetData($tInfo, "Code") & @LF & _
"--> 项目 ID:" & @TAB & DllStructGetData($tInfo, "ItemID") & @LF & _
"--> 项目文本:" & @TAB & DllStructGetData($tInfo, "Text"))
; 忽略返回值
Case $CBEN_ENDEDITA, $CBEN_ENDEDITW ; 发送用户结束编辑框操作或下拉列表选定项目消息
$tInfo = DllStructCreate($tagNMCBEENDEDIT, $ilParam)
_DebugPrint("$CBEN_ENDEDIT" & @LF & "--> 控件句柄:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @LF & _
"--> 控件 ID:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @LF & _
"--> 操作代码:" & @TAB & DllStructGetData($tInfo, "Code") & @LF & _
"--> 变动:" & @TAB & DllStructGetData($tInfo, "fChanged") & @LF & _
"--> 新选择:" & @TAB & DllStructGetData($tInfo, "NewSelection") & @LF & _
"--> 项目文本:" & @TAB & DllStructGetData($tInfo, "Text") & @LF & _
"-->Why:" & @TAB & DllStructGetData($tInfo, "Why"))
Return False ; 接受通知,并允许该控件显示所选项目
;~ Return True否则,与上面相反
Case $CBEN_GETDISPINFOA, $CBEN_GETDISPINFOW ; 发送显示回调项目检索信息
_DebugPrint("$CBEN_GETDISPINFO" & _GetComboBoxEx($ilParam))
Return 0
Case $CBEN_INSERTITEM
$tInfo = DllStructCreate($tagNMCOMBOBOXEX, $ilParam)
Local $tBuffer = DllStructCreate("wchar Text[" & DllStructGetData($tInfo, "TextMax") & "]", DllStructGetData($tInfo, "Text"))
_DebugPrint("$CBEN_INSERTITEM" & @LF & "--> 控件句柄:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @LF & _
"--> 控件 ID:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @LF & _
"--> 操作代码:" & @TAB & DllStructGetData($tInfo, "Code") & @LF & _
"--> 掩码:" & @TAB & DllStructGetData($tInfo, "Mask") & @LF & _
"--> 项目:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
"--> 项目文本:" & @TAB & DllStructGetData($tBuffer, "Text") & @LF & _
"--> 最大文本:" & @TAB & DllStructGetData($tInfo, "TextMax") & @LF & _
"--> 缩 进:" & @TAB & DllStructGetData($tInfo, "Indent") & @LF & _
"--> 图像:" & @TAB & DllStructGetData($tInfo, "Image") & @LF & _
"--> 选中时图像:" & @TAB & DllStructGetData($tInfo, "SelectedImage") & @LF & _
"--> 覆盖时图像:" & @TAB & DllStructGetData($tInfo, "OverlayImage") & @LF & _
"--> 参数:" & @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 & "--> 控件句柄:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @LF & _
"--> 控件 ID:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @LF & _
"--> 操作代码:" & @TAB & DllStructGetData($tInfo, "Code") & @LF & _
"--> 掩码:" & @TAB & DllStructGetData($tInfo, "Mask") & @LF & _
"--> 项目:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
"--> 项目文本:" & @TAB & $aItem & @LF & _
"--> 最大文本:" & @TAB & $aItem & @LF & _
"--> 缩 进:" & @TAB & $aItem & @LF & _
"--> 图像:" & @TAB & $aItem & @LF & _
"--> 选中时图像:" & @TAB & $aItem & @LF & _
"--> 覆盖时图像:" & @TAB & $aItem & @LF & _
"--> 参数:" & @TAB & $aItem
EndFunc ;==>_GetComboBoxEx
Func _DebugPrint($s_text, $line = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @LF & _
"+======================================================" & @LF & _
"--> 行(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
"+======================================================" & @LF)
EndFunc ;==>_DebugPrint
但是根据这两个 函数的范例中 都有一句
【$Debug_CB= False ; 检查传递到ComboBox / ComboBoxEx 函数的控件类名, 设置为 True, 并使用一个句柄到另一个控件, 查看它的工作】
因此我觉得这两个函数产生的 WM_NOTIFY理论上应该 可以同时产生 CBEN 与 CBN 的消息才对……….. 有人可以使用_GUICtrlComboBox_Create的范例帮我把 _GUICtrlComboBoxEx_Create的WM_NOTIFY 也合并进去吗??
本帖最后由 afan 于 2020-9-20 14:47 编辑
chzj589 发表于 2020-8-23 21:24
用以下代码试试
不要搞得那么复杂,精简代码是解决问题的第一步
功能达到了再去优化,关键还是设计思路
列表临时出现一个下拉控件并处理交互,可以很简单
#include <GUIListView.au3>
Global $hListView1, $aItem, $iCombo
Global $sDefCombo1 = '11|22', $sDefCombo2 = 'abc|ZZZ'
_GUICreate()
While GUIGetMsg() <> -3
WEnd
Func _GUICreate()
Local $hGUI = GUICreate('')
Dim $iCombo = GUICtrlCreateCombo('', -100, -100)
Local $ListView1 = GUICtrlCreateListView('编号|可双击下拉1 |xxx|可双击下拉2 |fff', 2, 30, 396, 250)
Dim $hListView1 = GUICtrlGetHandle(-1)
GUICtrlSetFont(-1, 11, 400, 0, '微软雅黑')
_GUICtrlListView_SetExtendedListViewStyle($ListView1, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
For $ii = 1 To 8
GUICtrlCreateListViewItem(StringFormat('%s|aaa-%s|BBB_%s|333.%s|ddd~%s', $ii, $ii, $ii, $ii, $ii), $ListView1)
Next
GUISetState()
GUIRegisterMsg(0x004E, '_WM_NOTIFY') ;$WM_NOTIFY = 0x004E
EndFunc ;==>_GUICreate
Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, 'hWndFrom'))
Local $iCode = DllStructGetData($tNMHDR, 'Code')
Switch $hWndFrom
Case $hListView1
Switch $iCode
Case -2 ;$NM_CLICK = -2
If IsArray($aItem) Then
_GUICtrlListView_SetItemText($hListView1, $aItem, GUICtrlRead($iCombo), $aItem)
GUICtrlSetPos($iCombo, -1000, -100)
Dim $aItem = 0
EndIf
Case -3 ;$NM_DBLCLK = -3
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $iIndex = DllStructGetData($tInfo, 'Index')
Local $iSub = DllStructGetData($tInfo, 'SubItem')
Dim $aItem = 0
If Not StringRegExp($iSub, "^(1|3)$") Then Return 'GUI_RUNDEFMSG'
Local $aRect = _GUICtrlListView_GetSubItemRect($hListView1, $iIndex, $iSub)
Dim $aItem = [$iIndex, $iSub]
Local $sDef = $sDefCombo1
If $iSub = 3 Then $sDef = $sDefCombo2
Local $sData = _GUICtrlListView_GetItemText($hListView1, $iIndex, $iSub)
GUICtrlSetPos($iCombo, $aRect + 4, $aRect + 32, $aRect - $aRect)
GUICtrlSetData($iCombo, '|' & $sData & '|' & $sDef, $sData)
GUICtrlSetState($iCombo, 256)
EndSwitch
EndSwitch
Return 'GUI_RUNDEFMSG'
EndFunc ;==>_WM_NOTIFY
又被吃代码了,还好自己复制测试发现了问题。 没明白你的意思呢!两个例子,一个是用的WM_COMMAND 另一个是WM_NOTIFY 要怎么合并? 水木子 发表于 2020-6-6 17:05
没明白你的意思呢!两个例子,一个是用的WM_COMMAND 另一个是WM_NOTIFY 要怎么合并?
哈哈哈~~~~~~~~~ 我現在才發現ㄟ@@原來如此.......................誤會了@@
不過話說回來..........._GUICtrlComboBox_Create就一定不會發送 Case $CBEN_ENDEDITA, $CBEN_ENDEDITW這個消息嗎 kk_lee69 发表于 2020-6-6 18:18
哈哈哈~~~~~~~~~ 我現在才發現ㄟ@@原來如此.......................誤會了@@
不過話說回來......... ...
不是很明白你的用意,你是想要注册Combo控件选项发生改变或输入文本的消息吗?
#include <GUIComboBox.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
$hGui = GUICreate('ComboBox Auto Complete', 400, 300)
$edit = GUICtrlCreateEdit('', 5, 5, 390, 260, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL))
$hCombo = GUICtrlCreateCombo('', 5, 275, 390, 290)
GUICtrlSetData(-1, '项目-1|项目-2|项目-3', '项目-1')
GUISetState()
Do
Until GUIGetMsg() = -3
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
Local $iCode
$iCode = BitShift($iwParam, 16) ; Hi Word
ConsoleWrite($iCode & @CRLF)
Switch $iCode
Case $CBN_SELCHANGE; 组合框的列表框中的当前选项改变时发送
GUICtrlSetData($edit, GUICtrlRead($hCombo) & @CRLF, 1)
Case 5
GUICtrlSetData($edit, GUICtrlRead($hCombo) & @CRLF, 1)
EndSwitch
EndFunc ;==>WM_COMMAND 水木子 发表于 2020-6-6 18:28
不是很明白你的用意,你是想要注册Combo控件选项发生改变或输入文本的消息吗?
我的意思是
目前如果我使用 _GUICtrlComboBox_Create創建 就會
但是我捕捉到 我停留在 G 的事件
如 下面的圖
可以用 _GUICtrlComboBox_Create 做到嗎??
直接用_GUICtrlComboBoxEx_Create afan 发表于 2020-6-7 14:04
直接用_GUICtrlComboBoxEx_Create
OK 我懂了...............了解我怎麼沒想到呢 哈哈 afan 发表于 2020-6-7 14:04
直接用_GUICtrlComboBoxEx_Create
對了 可以在詢問一下嗎??
_GUICtrlComboBoxEx_GetEditText
如果消息發送到具有 $CBS_DROPDOWN 或 $CBS_DROPDOWNLIST 樣式的下拉式列示方塊, 該函數將失敗.
我需要讀取 _GUICtrlComboBoxEx_GetEditText 這個方塊 使用者 輸入的資料又需要 有下拉樣式
我如何可以讀取到ComboBox 的內容呢??
afan 发表于 2020-6-7 14:04
直接用_GUICtrlComboBoxEx_Create
跟 這個類似
https://www.autoitx.com/forum.php?mod=viewthread&tid=7969&highlight=ComboBoxEx
我需要讀取的是 使用者輸入的內容不一定是從下拉 項目選擇的內容 kk_lee69 发表于 2020-6-7 18:07
跟 這個類似
https://www.autoitx.com/forum.php?mod=viewthread&tid=7969&highlight=ComboBoxEx
不懂你的意思,最好有简单可测试代码。
本帖最后由 kk_lee69 于 2020-6-7 20:06 编辑
afan 发表于 2020-6-7 18:27
不懂你的意思,最好有简单可测试代码。
#include <GuiComboBoxEx.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
$Debug_CB = False ; 检查传递到 ComboBox / ComboBoxEx 函数的控件类名, 设置为 True, 并使用一个句柄到另一个控件, 查看它的工作
Global $hCombo
Local $hGUI
; 创建 GUI
$hGUI = GUICreate("ComboBoxEx 函数演示", 400, 300)
$hCombo = _GUICtrlComboBoxEx_Create($hGUI, "这是测试|资料行 2", 2, 2, 394, 268) ;样式不能变
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_GUICtrlComboBoxEx_AddString($hCombo, "再加一点文字")
_GUICtrlComboBoxEx_InsertString($hCombo, "插入的文本", 1)
$BUTTON = GuiCtrlCreateButton('读取COMBO数据', 10, 158, 150, 30); 清除纪录按钮
GUISetState()
While 1
Switch guigetmsg()
Case $GUI_EVENT_CLOSE
Exit
Case $BUTTON
MsgBox(0,"",_GUICtrlComboBoxEx_GetEditText($hCombo))
EndSwitch
Sleep(10)
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo
$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 ; 发送用户激活下拉列表或编辑框点击消息.
_DebugPrint("$CBEN_BEGINEDIT" & @LF & "--> 控件句柄:" & @TAB & $hWndFrom & @LF & _
"--> 控件 ID:" & @TAB & $iIDFrom & @LF & _
"--> 操作代码:" & @TAB & $iCode)
Return 0
Case $CBEN_DELETEITEM
_DebugPrint("$CBEN_DELETEITEM" & _GetComboBoxEx($ilParam))
Return 0
Case $CBEN_DRAGBEGINA, $CBEN_DRAGBEGINW
$tInfo = DllStructCreate($tagNMCBEDRAGBEGIN, $ilParam)
If DllStructGetData($tInfo, "ItemID") Then _DebugPrint("$CBEN_DRAGBEGIN" & _GetComboBoxEx($ilParam))
_DebugPrint("$CBEN_DRAGBEGIN" & @LF & "--> 控件句柄:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @LF & _
"--> 控件 ID:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @LF & _
"--> 操作代码:" & @TAB & DllStructGetData($tInfo, "Code") & @LF & _
"--> 项目 ID:" & @TAB & DllStructGetData($tInfo, "ItemID") & @LF & _
"--> 专案文本:" & @TAB & DllStructGetData($tInfo, "Text"))
; 忽略返回值
Case $CBEN_ENDEDITA, $CBEN_ENDEDITW ; 发送使用者结束编辑框操作或下拉列表选定项目消息
$tInfo = DllStructCreate($tagNMCBEENDEDIT, $ilParam)
_DebugPrint("$CBEN_ENDEDIT" & @LF & "--> 控件句柄:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @LF & _
"--> 控件 ID:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @LF & _
"--> 操作代码:" & @TAB & DllStructGetData($tInfo, "Code") & @LF & _
"--> 变动:" & @TAB & DllStructGetData($tInfo, "fChanged") & @LF & _
"--> 新选择:" & @TAB & DllStructGetData($tInfo, "NewSelection") & @LF & _
"--> 专案文本:" & @TAB & DllStructGetData($tInfo, "Text") & @LF & _
"-->Why:" & @TAB & DllStructGetData($tInfo, "Why"))
Return False ; 接受通知,并允许该控件显示所选项目
;~ Return True否则,与上面相反
Case $CBEN_GETDISPINFOA, $CBEN_GETDISPINFOW ; 发送显示回调项目检索信息
_DebugPrint("$CBEN_GETDISPINFO" & _GetComboBoxEx($ilParam))
Return 0
Case $CBEN_INSERTITEM
$tInfo = DllStructCreate($tagNMCOMBOBOXEX, $ilParam)
Local $tBuffer = DllStructCreate("wchar Text[" & DllStructGetData($tInfo, "TextMax") & "]", DllStructGetData($tInfo, "Text"))
_DebugPrint("$CBEN_INSERTITEM" & @LF & "--> 控件句柄:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @LF & _
"--> 控件 ID:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @LF & _
"--> 操作代码:" & @TAB & DllStructGetData($tInfo, "Code") & @LF & _
"--> 屏蔽:" & @TAB & DllStructGetData($tInfo, "Mask") & @LF & _
"--> 项目:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
"--> 专案文本:" & @TAB & DllStructGetData($tBuffer, "Text") & @LF & _
"--> 最大文本:" & @TAB & DllStructGetData($tInfo, "TextMax") & @LF & _
"--> 缩 进:" & @TAB & DllStructGetData($tInfo, "Indent") & @LF & _
"--> 图像:" & @TAB & DllStructGetData($tInfo, "Image") & @LF & _
"--> 选中时图像:" & @TAB & DllStructGetData($tInfo, "SelectedImage") & @LF & _
"--> 覆盖时图像:" & @TAB & DllStructGetData($tInfo, "OverlayImage") & @LF & _
"--> 参数:" & @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 & "--> 控件句柄:" & @TAB & DllStructGetData($tInfo, "hWndFrom") & @LF & _
"--> 控件 ID:" & @TAB & DllStructGetData($tInfo, "IDFrom") & @LF & _
"--> 操作代码:" & @TAB & DllStructGetData($tInfo, "Code") & @LF & _
"--> 屏蔽:" & @TAB & DllStructGetData($tInfo, "Mask") & @LF & _
"--> 项目:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
"--> 专案文本:" & @TAB & $aItem & @LF & _
"--> 最大文本:" & @TAB & $aItem & @LF & _
"--> 缩 进:" & @TAB & $aItem & @LF & _
"--> 图像:" & @TAB & $aItem & @LF & _
"--> 选中时图像:" & @TAB & $aItem & @LF & _
"--> 覆盖时图像:" & @TAB & $aItem & @LF & _
"--> 参数:" & @TAB & $aItem
EndFunc ;==>_GetComboBoxEx
Func _DebugPrint($s_text, $line = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @LF & _
"+======================================================" & @LF & _
"--> 行(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
"+======================================================" & @LF)
EndFunc ;
本帖最后由 afan 于 2020-6-7 20:46 编辑
kk_lee69 发表于 2020-6-7 20:03
_GUICtrlComboBox*_GetEditText 的确是一系列白痴函数,简单写了个 _GUICtrlComboBox_GetEditTextEx,替换它
顺便告诉你什么叫“简单的可测试代码”
#include <GuiComboBoxEx.au3>
Local $hGUI = GUICreate('ComboBoxEx GetEditText', 400, 300)
Global $hCombo = _GUICtrlComboBoxEx_Create($hGUI, '这是测试|资料行 2', 2, 2, 394, 268) ;样式不能变
Local $BUTTON = GUICtrlCreateButton('读取COMBO数据', 10, 158, 150, 30)
GUISetState()
While 1
Switch GUIGetMsg()
Case -3
Exit
Case $BUTTON
MsgBox(0, '', _GUICtrlComboBox_GetEditTextEx($hCombo))
EndSwitch
WEnd
Func _GUICtrlComboBox_GetEditTextEx($hWnd) ; _GUICtrlComboBoxEx_GetEditText 修改版
Local $hCBEdit = _GUICtrlComboBoxEx_GetEditControl($hWnd)
Return ControlGetText('', '', $hCBEdit)
EndFunc ;==>_GUICtrlComboBox_GetEditTextEx afan 发表于 2020-6-7 20:30
_GUICtrlComboBox*_GetEditText 的确是一系列白痴函数,简单写了个 _GUICtrlComboBox_GetEditTextEx,替 ...
果然高手一出手就解決了我的問題 感謝!! 本帖最后由 chzj589 于 2020-8-23 21:27 编辑
kk_lee69 发表于 2020-6-8 00:41
果然高手一出手就解決了我的問題 感謝!!
用以下代码试试
#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GUIListView.au3>
#include <GuiImageList.au3>
#include <GuiEdit.au3>
#include <GuiComboBoxEx.au3>
Global $sText, $sText1, $hCombo, $hComboa
Local $hGUI = GUICreate('ComboBoxEx GetEditText', 400, 420)
Global $hCombo = _GUICtrlComboBoxEx_Create($hGUI, '这是测试|资料行 2', 2, 2, 154, 268) ;样式不能变
Local $sRead1 = "張三|李四|王五|陳六"
Local $hComboa = _GUICtrlComboBox_Create($hGUI, $sRead1, 160, 2, 154, 296)
;Local $ListView1 = GUICtrlCreateListView('序号|此列下拉框 |XXXX |下拉框 | BBBB', 2, 30, 396, 248, $LVS_REPORT, $WS_EX_CLIENTEDGE)
;Dim $hListView1 = GUICtrlGetHandle(-1)
;_GUICtrlListView_SetExtendedListViewStyle($ListView1, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
;GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
Local $ListView1 = GUICtrlCreateListView('', 2, 30, 396, 250, $LVS_REPORT, $WS_EX_CLIENTEDGE);序号|此列下拉框|XXXX|下拉框|BBBB
Dim $hListView1 = GUICtrlGetHandle(-1)
GUICtrlSetFont(-1, 11, 400, 0, "微软雅黑")
GUICtrlSetBkColor($ListView1, 0xC0E0FF)
_GUICtrlListView_SetBkColor($ListView1, 14675183)
_GUICtrlListView_AddColumn($hListView1, "编号", 60, 2);设置列属性
_GUICtrlListView_AddColumn($hListView1, "此列下拉框", 80, 2)
_GUICtrlListView_AddColumn($hListView1, "XXXX", 80, 2)
_GUICtrlListView_AddColumn($hListView1, "此列下拉框", 90, 2)
_GUICtrlListView_AddColumn($hListView1, "BBBB", 90, 2)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
$iStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_CLIENTEDGE, $LVS_EX_INFOTIP, $LVS_EX_SUBITEMIMAGES)
GUICtrlSetBkColor($ListView1, 0xC0E0FF)
_GUICtrlListView_SetBkColor($hListView1, 14675183)
; 添加项目
For $ii = 1 To 8
GUICtrlCreateListViewItem($ii & '|aaa|bbb|CCCC|DDDD', $ListView1)
Next
$Edit = GUICtrlCreateEdit("", 2, 290, 396, 70, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL));, $BS_BITMAP, $WS_EX_DLGMODALFRAME);, $WS_VSCROLL)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
GUICtrlSetColor(-1, 0xFF000F7F)
Local $BUTTON = GUICtrlCreateButton('读取COMBO数据', 10, 390, 150, 25)
$GInputuk7 = GUICtrlCreateLabel("", 360, 390, 30, 25);, $SS_CENTER + $SS_CENTERIMAGE + $WS_BORDER, $WS_EX_DLGMODALFRAME)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
Switch GUIGetMsg()
Case -3
Exit
Case $BUTTON
_GUICtrlComboBoxEx_GetItemText($hCombo, _GUICtrlComboBoxEx_GetCurSel($hCombo), $sText)
_GUICtrlComboBoxEx_GetItemText($hComboa, _GUICtrlComboBoxEx_GetCurSel($hComboa), $sText1)
MsgBox(0, '', $sText & @CRLF & $sText1)
;_GUICtrlComboBox_Destroy($hComboa)
;_GUICtrlComboBox_Destroy($hCombo)
EndSwitch
WEnd
Func _GUICtrlComboBox_GetEditTextEx($hWnd) ; _GUICtrlComboBoxEx_GetEditText 修改版
Local $hCBEdit = _GUICtrlComboBoxEx_GetEditControl($hCombo)
Return ControlGetText('', '', $hCBEdit)
EndFunc ;==>_GUICtrlComboBox_GetEditTextEx
Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $zhucaidan
;Local $hWndListView1 = $hListView1
;If Not IsHWnd($hListView1) Then $hWndListView1 = GUICtrlGetHandle($hListView1)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hListView1
Switch $iCode
#cs
Case $NM_DBLCLK ; 按兩下 Case $NM_CLICK ; 滑鼠左鍵按一下
Local $index = _GUICtrlListView_GetSelectedIndices($hListView1)
GUICtrlSetData($GInputuk7, $index)
;GUISetState(@SW_HIDE, $hEditForm)
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$iIndex = DllStructGetData($tInfo, "Index")
$iSub = DllStructGetData($tInfo, "SubItem")
$x = DllStructGetData($tInfo, "X")
Local $SubItem = DllStructGetData($tInfo, 'SubItem')
Global $aHit = _GUICtrlListView_SubItemHitTest($hListView1)
Global $aHit = _GUICtrlListView_SubItemHitTest($hListView1)
;$SubItem = $iSub
Local $ax = 1
Local $ay = 1
Local $aRect = _GUICtrlListView_GetSubItemRect($hListView1, $iIndex, $iSub)
;MsgBox($MB_SYSTEMMODAL, "消息", StringFormat("子項矩形 : [%d, %d, %d, %d]", $aRect, $aRect, $aRect, $aRect))
Local $iEdit_X = $aRect ;+ 4
Local $iEdit_Y = $aRect ;- 25;+ 3
Local $iEdit_Width = _GUICtrlListView_GetColumnWidth($hListView1, $iSub) + 3
Local $iEdit_Height = $aRect - $aRect + 3
Local $sItem = _GUICtrlListView_GetItemText($ListView1, $iIndex, $iSub);取listview$iIndex行 $iSub列的文本
Local $sRead = "男|女"
If $SubItem = 1 Then
;_GUICtrlComboBox_Destroy($hCombo)
$hCombo = _GUICtrlComboBox_Create($hListView1, $sRead, $iEdit_X, $iEdit_Y, $iEdit_Width, $iEdit_Height);, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
ElseIf $SubItem = 3 Then
;_GUICtrlComboBox_Destroy($hComboa)
;Local $sRead = "張三|李四|王五|陳六"
Local $sComboTxt = ""
$sFilePath1 = @ScriptDir & "\config.ini";读取
Local $aArray = IniReadSection($sFilePath1, "1")
; 检查是否发生错误.
If Not @error Then
; 枚举显示数组中关键字及其各自的值.
For $i = 1 To $aArray
$totalini = $aArray[$i]
If Not StringInStr($sComboTxt, $totalini) Then $sComboTxt &= $totalini & "|"
Next
EndIf
$hComboa = _GUICtrlComboBox_Create($hListView1, $sComboTxt, $iEdit_X, $iEdit_Y, $iEdit_Width, $iEdit_Height);, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
ElseIf ($iIndex <> -1) And ($iSub >= 2) And ($x > 16) Then;點擊的x>16才回應原地編輯
$hEdit = GUICtrlCreateInput($sItem, $iEdit_X, $iEdit_Y, $iEdit_Width, $iEdit_Height, BitOR($WS_CHILD, $WS_VISIBLE, $ES_LEFT))
Else
;MsgBox(0, "提示", "按一下了空白處", 1)
EndIf
$index = _GUICtrlListView_GetSelectedIndices($hListView1)
GUICtrlSetData($GInputuk7, $index)
GUICtrlSetColor($GInputuk7, 0x990000)
#ce
Case $NM_CLICK ; 滑鼠左鍵按一下
Local $index = _GUICtrlListView_GetSelectedIndices($hListView1)
GUICtrlSetData($GInputuk7, $index)
EndSwitch
EndSwitch
#forceref $hWnd, $iMsg, $iwParam
Local $MyGuiFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$MyGuiFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $iIDFrom
Case $ListView1
Switch $iCode
Case $NM_CUSTOMDRAW
Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam)
Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW
Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
Switch $iSubItem
Case 2
If $iSubItem = 2 Then ;設置首列, 即專案
$iColor = RGB2BGR(0x990000)
DllStructSetData($tCustDraw, "clrText", $iColor)
EndIf
Case 3
If $iSubItem = 3 Then ;設置首列, 即專案
$iColor = RGB2BGR(0x009900)
DllStructSetData($tCustDraw, "clrText", $iColor)
EndIf
Case 4
If $iSubItem = 4 Then ;設置首列, 即專案
$iColor = RGB2BGR(0xFF0000)
DllStructSetData($tCustDraw, "clrText", $iColor)
EndIf
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_NOTIFY
Func RGB2BGR($iColor)
Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc ;==>RGB2BGR
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iIDFrom, $iCode, $sText
$hWndFrom = $ilParam
$iIDFrom = BitAND($iwParam, 0xFFFF) ; 低位字
$iCode = BitShift($iwParam, 16) ; 高位字
Local $aHit = _GUICtrlListView_SubItemHitTest($hListView1)
Switch $hWndFrom
Case $hCombo
Switch $iCode
Case $CBN_SELENDCANCEL ;发送用户选择一个项目, 然后选择另一个控件或关闭对话框消息
$sItemText1 = _GUICtrlEdit_GetText($hCombo)
GUICtrlSetData($Edit, $sItemText1 & @CRLF)
_GUICtrlComboBoxEx_GetItemText($hCombo, _GUICtrlComboBoxEx_GetCurSel($hCombo), $sText)
_GUICtrlListView_SetItemText($hListView1, $aHit, $sItemText1, 1)
Case $CBN_SELENDOK
$iCurSel = _GUICtrlComboBox_GetCurSel($hCombo)
_GUICtrlComboBox_GetLBText($hCombo, $iCurSel, $sText)
;MsgBox(0, "", $iCurSel)
GUICtrlSetData($Edit, $sText & @CRLF)
$idda = GUICtrlRead($GInputuk7)
_GUICtrlComboBoxEx_GetItemText($hCombo, _GUICtrlComboBoxEx_GetCurSel($hCombo), $sText)
_GUICtrlListView_SetItemText($hListView1, $idda, $sText, 1)
;GUICtrlSetFont($ListView1, 12, 400, 0, "微軟雅黑")
GUICtrlSetBkColor($ListView1, 0xC0E0FF)
_GUICtrlListView_SetBkColor($ListView1, 14675183)
;_GUICtrlComboBox_Destroy($hCombo)
EndSwitch
Case $hComboa
Switch $iCode
Case $CBN_SELENDCANCEL ;发送用户选择一个项目, 然后选择另一个控件或关闭对话框消息
$sItemText1 = _GUICtrlEdit_GetText($hComboa)
GUICtrlSetData($Edit, $sItemText1 & @CRLF)
_GUICtrlComboBoxEx_GetItemText($hComboa, _GUICtrlComboBoxEx_GetCurSel($hComboa), $sText)
_GUICtrlListView_SetItemText($hListView1, $aHit, $sItemText1, 3)
;MsgBox(0, '', $sText)
;_GUICtrlComboBox_Destroy($hComboa)
Case $CBN_SELENDOK
$iCurSel = _GUICtrlComboBox_GetCurSel($hComboa)
_GUICtrlComboBox_GetLBText($hComboa, $iCurSel, $sText)
;MsgBox(0, "", $iCurSel)
GUICtrlSetData($Edit, $sText & @CRLF)
$idda = GUICtrlRead($GInputuk7)
_GUICtrlComboBoxEx_GetItemText($hComboa, _GUICtrlComboBoxEx_GetCurSel($hComboa), $sText)
_GUICtrlListView_SetItemText($hListView1, $idda, $sText, 3)
;GUICtrlSetFont($ListView1, 12, 400, 0, "微軟雅黑")
GUICtrlSetBkColor($ListView1, 0xC0E0FF)
_GUICtrlListView_SetBkColor($ListView1, 14675183)
;MsgBox(0, '', _GUICtrlComboBox_GetEditTextExa($hComboa))
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
chzj589 发表于 2020-8-23 21:24
用以下代码试试
把_GUICtrlComboBox_Create放在列表里,WM_COMMAND就失效了。
你看看有什么办法。
页:
[1]
2