#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消息[已解決]
;[url]https://msdn.microsoft.com/en-us/library/windows/desktop/bb775784(v=vs.85).aspx[/url]
Case $NM_SETFOCUS;CBEM_SETCOMBOFOCUS
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Combo3 - $NM_SETFOCUS' & @CRLF)
;疑問:為什麼ComboBoxEx不接收$NM_SETFOCUS消息[已解決]
;[url]https://msdn.microsoft.com/en-us/library/windows/desktop/bb775785(v=vs.85).aspx[/url]
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的 [url]https://msdn.microsoft.com/en-us/library/windows/desktop/bb775760(v=vs.85).aspx[/url]
;參見MSDN的 [url]https://msdn.microsoft.com/en-us/library/windows/desktop/bb775750(v=vs.85).aspx[/url]
;問題: 為什麼$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
;###########################################