回复 2# haijie1223
发哥帮我完善一下哇 怎么获取焦点呢?
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiComboBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Global Const $TME_CANCEL = 0x80000000
Global Const $TME_HOVER = 0x00000001
Global Const $TME_LEAVE = 0x00000002
Global Const $TME_NONCLIENT = 0x00000010
Global Const $TME_QUERY = 0x40000000
Global $idComboBox1, $idComboBox2, $wProcOld, $wProcNew
Example()
Func Example()
Local $hGUI = GUICreate("ComboBox", 300, 200)
$idComboBox1 = GUICtrlCreateCombo("test1", 10, 10, 185, 20, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $CBS_DROPDOWNLIST))
$wProcNew = DllCallbackRegister("_MyProc", "int", "hwnd;uint;uint;dword")
$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
$idComboBox2 = GUICtrlCreateCombo("中文1", 10, 50, 185, 20, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $CBS_DROPDOWNLIST))
$wProcNew = DllCallbackRegister("_MyProc", "int", "hwnd;uint;uint;dword")
$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
Local $idClose = GUICtrlCreateButton("关闭", 210, 170, 85, 25)
GUISetState(@SW_SHOW, $hGUI)
GUICtrlSetData($idComboBox1, "test2|test3|test4", "test4")
GUICtrlSetData($idComboBox2, "中文2|中文3|中文4", "中文4")
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $idClose
ExitLoop
EndSwitch
WEnd
GUIDelete($hGUI)
EndFunc ;==>Example
Func _MyProc($hWnd, $uiMsg, $wParam, $lParam)
Local $iCtrl = _WinAPI_GetDlgCtrlID($hWnd)
Switch $uiMsg
Case $WM_LBUTTONDOWN;左键按下
Case $WM_LBUTTONUP;左键弹起
Case $WM_MOUSEHOVER;鼠标悬停
Switch $iCtrl
Case $idComboBox1
MsgBox(0, "", "1", 1)
EndSwitch
Case $WM_MOUSELEAVE;鼠标离开
Switch $iCtrl
Case $idComboBox1
EndSwitch
Case $WM_MOUSEMOVE;鼠标移动
__TrackMouseEvent($hWnd, BitOR($TME_HOVER, $TME_LEAVE), 5) ;//MOUSELEAVE|MOUSEHOVER消息由此函数触发
Case $WM_SETCURSOR;设置光标
GUICtrlSetCursor($iCtrl, 0)
EndSwitch
Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc ;==>_MyProc
Func __TrackMouseEvent($hWnd, $iFlags, $iTime = -1)
Local $tTME = DllStructCreate('dword;dword;hwnd;dword')
DllStructSetData($tTME, 1, DllStructGetSize($tTME))
DllStructSetData($tTME, 2, $iFlags)
DllStructSetData($tTME, 3, $hWnd)
DllStructSetData($tTME, 4, $iTime)
Local $aRet = DllCall('user32.dll', 'bool', 'TrackMouseEvent', 'struct*', $tTME)
If @error Then Return SetError(@error, @extended, 0)
; If Not $aRet[0] Then Return SetError(1000, 0, 0)
Return $aRet[0]
EndFunc ;==>__TrackMouseEvent
|