请教ComboBoxEx接收$CBEN_ENDEDITW消息的问题
本帖最后由 athland5013 于 2015-2-6 19:52 编辑#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiComboBoxEx.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 500, 300)
$Label1 = GUICtrlCreateLabel("GUICtrlCreateCombo生成", 60, 66, 200, 17)
$Combo1 = GUICtrlCreateCombo("Combo1", 250, 64, 177, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$Label2 = GUICtrlCreateLabel("_GUICtrlComboBox_Create生成", 60, 111, 200, 17)
$Combo2 = _GUICtrlComboBox_Create($Form1, "Combo2", 250, 109, 177, 25)
_SendMessage($Combo2, $CB_SETCURSEL, 0)
$Label3 = GUICtrlCreateLabel("_GUICtrlComboBoxEx_Create生成", 60, 162, 200, 17)
$Combo3 = _GUICtrlComboBoxEx_Create($Form1, "Combo3|a|b|c", 250, 160, 177)
_SendMessage($Combo3, $CB_SETCURSEL, 0)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
;###########################################
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 $iIDFrom
Case $Combo1
Switch $iCode
Case $CBN_KILLFOCUS
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_KILLFOCUS' & @CRLF)
Case $CBN_SETFOCUS
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_SETFOCUS' & @CRLF)
Case $CBN_EDITCHANGE
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_EDITCHANGE' & @CRLF)
Case $CBN_SELCHANGE
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_SELCHANGE' & @CRLF)
Case $CBN_SELENDCANCEL
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_SELENDCANCEL' & @CRLF)
Case $CBN_EDITUPDATE
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_EDITUPDATE' & @CRLF)
Case $CBN_DROPDOWN
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_DROPDOWN' & @CRLF)
Case $CBN_CLOSEUP
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_CLOSEUP' & @CRLF)
Case $CBN_SELENDOK
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $CBN_SELENDOK' & @CRLF)
Case Else
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo1 - $iCode = ' & $iCode & @CRLF)
EndSwitch
ConsoleWrite('===========================================================================' & @CRLF)
EndSwitch
Switch $hWndFrom
Case $Combo2
Switch $iCode
Case $CBN_KILLFOCUS
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_KILLFOCUS' & @CRLF)
Case $CBN_SETFOCUS
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_SETFOCUS' & @CRLF)
Case $CBN_EDITCHANGE
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_EDITCHANGE' & @CRLF)
Case $CBN_SELCHANGE
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_SELCHANGE' & @CRLF)
Case $CBN_SELENDCANCEL
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_SELENDCANCEL' & @CRLF)
Case $CBN_EDITUPDATE
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_EDITUPDATE' & @CRLF)
Case $CBN_DROPDOWN
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_DROPDOWN' & @CRLF)
Case $CBN_CLOSEUP
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_CLOSEUP' & @CRLF)
Case $CBN_SELENDOK
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $CBN_SELENDOK' & @CRLF)
Case Else
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo2 - $iCode = ' & $iCode & @CRLF)
EndSwitch
ConsoleWrite('===========================================================================' & @CRLF)
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
;###########################################
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $tNMHDR, $hWndFrom, $iIDFrom, $iCode
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hFrom = DllStructGetData($tNMHDR, "hWndFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hFrom
Case $Combo3
Switch $iCode
Case $NM_KILLFOCUS;CBEM_KILLCOMBOFOCUS
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo3 - $NM_KILLFOCUS' & @CRLF)
;疑问:为什么ComboBoxEx不接收$NM_KILLFOCUS消息[已解决]
;https://msdn.microsoft.com/en-us/library/windows/desktop/bb775784(v=vs.85).aspx
Case $NM_SETFOCUS;CBEM_SETCOMBOFOCUS
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo3 - $NM_SETFOCUS' & @CRLF)
;疑问:为什么ComboBoxEx不接收$NM_SETFOCUS消息[已解决]
;https://msdn.microsoft.com/en-us/library/windows/desktop/bb775785(v=vs.85).aspx
Case $NM_SETCURSOR
Case $CBEN_GETDISPINFOW
Case $CBEN_BEGINEDIT
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo3 - $CBEN_BEGINEDIT' & @CRLF)
Case $CBEN_ENDEDITW
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo3 - $CBEN_ENDEDITW' & @CRLF)
Local $tNMCBEENDEDIT = DllStructCreate($tagNMCBEENDEDIT, $ilParam)
Local $fChanged = DllStructGetData($tNMCBEENDEDIT, "fChanged")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $fChanged = ' & $fChanged & @CRLF)
Local $NewSelection = DllStructGetData($tNMCBEENDEDIT, "NewSelection")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $NewSelection = ' & $NewSelection & @CRLF)
Local $szText = DllStructGetData($tNMCBEENDEDIT, "szText")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $szText = ' & $szText & @CRLF)
Local $Why = DllStructGetData($tNMCBEENDEDIT, "Why")
Switch $Why
Case 4
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Why = CBENF_DROPDOWN' & @CRLF) ;(用户激活下拉列表)
Case 1
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Why = CBENF_KILLFOCUS' & @CRLF) ;(编辑框失去键盘焦点)
;***********************************************************
Case 2
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Why = CBENF_ESCAPE' & @CRLF) ;(用户按了ESC)
Case 3
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Why = CBENF_RETURN' & @CRLF) ;(用户完成编辑操作按回车)
Case Else
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo3 - $CBEN_ENDEDITW - $Why = ' & $iCode & @CRLF)
;参见帮助的 $tagNMCBEENDEDIT
;参见MSDN的 https://msdn.microsoft.com/en-us/library/windows/desktop/bb775760(v=vs.85).aspx
;参见MSDN的 https://msdn.microsoft.com/en-us/library/windows/desktop/bb775750(v=vs.85).aspx
;问题: 为什么$CBEN_ENDEDITW消息只响应了(CBENF_DROPDOWN)和(CBENF_KILLFOCUS)
; msdn上定义的(CBENF_ESCAPE)和(CBENF_RETURN)没有响应?
; ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
; 这些(CBENF_DROPDOWN,CBENF_KILLFOCUS,CBENF_ESCAPE,CBENF_RETURN)的具体值是多少呢?貌似AU3里面没有定义,网上也找不到
; (找不到也许是我能力不足问题)(以上$Why的1,2,3,4值是我蒙的)
; =====================================================
; 之所以(CBENF_ESCAPE)和(CBENF_RETURN)没有响应是AU3的问题吗,用其他语言写有响应吗?请大神试一下!
; 假设其他语言也无效这个是ComboBoxEx本身的问题,我们有没有方法让控件响应CBENF_RETURN和CBENF_ESCAPE呢?
; =====================================================
; 题外话
; 如果说WM_NOTIFY是比WM_COMMAND相对更高级的消息,ComboBoxEx是比ComboBox相对更高级的控件
; 为什么ComboBoxEx只发送这么少量的通知,不像ComboBox那样拥有相对全面的通知,微软是怎么想的?(如下)
; (CBN_CLOSEUP,CBN_DBLCLK,CBN_DROPDOWN,CBN_EDITCHANGE,CBN_EDITUPDATE,CBN_ERRSPACE)
; (CBN_KILLFOCUS,CBN_SELCHANGE,CBN_SELENDCANCEL,CBN_SELENDOK,CBN_SETFOCUS)
;***********************************************************
EndSwitch
ConsoleWrite('===========================================================================' & @CRLF)
Case Else
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo3 - $iCode = ' & $iCode & @CRLF)
;ComboBoxEx你就不能发送多点通知么,我,我~~
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
;###########################################
请各位兄弟测试一下代码,按下回车键ComboBoxEx有没有响应,我测试的是win732/64,AU3版本3.3.12.0,按下回车没响应,谢谢 不用测,不对 本帖最后由 athland5013 于 2015-2-6 01:09 编辑
为什么呢!!!!请仔细看看绿色注息部分 原来你是每日签到贴的楼主。你才发了149贴,有很多还是签到。。。。。 我也是win7 32,回车也没响应 学习了,感谢分享!! 建一个虚拟按钮,再建一个快键方式,来响应回车试试看
$idButton1 = GUICtrlCreateDummy()
Dim $AccelKeys = [['{Enter}', $idButton1]]
GUISetAccelerators($AccelKeys, $Form1) ;设置快捷方式. ComboBox不响应回车的
页:
[1]