如何实现鼠标悬停ComboBox控件上就可以用滑轮翻动[已解决]
本帖最后由 heroxianf 于 2017-5-29 09:18 编辑之前不加禁止编辑的样式点进去就可以滑轮上下翻动,现在使用下拉控件禁止编辑后想实现鼠标悬停上就可以滑动翻菜单,请大家指点一下。
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiComboBox.au3>
Example()
Func Example()
Local $hGUI = GUICreate("ComboBox", 300, 200)
Local $idComboBox1 = GUICtrlCreateCombo("test1", 10, 10, 185, 20, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $CBS_DROPDOWNLIST))
Local $idComboBox2 = GUICtrlCreateCombo("中文1", 10, 50, 185, 20, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $CBS_DROPDOWNLIST))
Local $idClose = GUICtrlCreateButton("关闭", 210, 170, 85, 25)
GUICtrlSetData($idComboBox1, "test2|test3|test4", "test4")
GUICtrlSetData($idComboBox2, "中文2|中文3|中文4", "中文4")
GUISetState(@SW_SHOW, $hGUI)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $idClose
ExitLoop
Case $idComboBox1
Case $idComboBox2
EndSwitch
WEnd
GUIDelete($hGUI)
EndFunc ;==>Example
和鼠标悬停不悬停没关系,只要获取了焦点就可以。 回复 2# haijie1223
发哥 哪个函数呢?{:face (396):} 回复 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 Then Return SetError(1000, 0, 0)
Return $aRet
EndFunc ;==>__TrackMouseEvent
While 1
$Info = GUIGetCursorInfo($hGUI)
If $Info = $idComboBox1 Or $Info = $idComboBox2 Then
GUICtrlSetState($Info, $GUI_FOCUS)
EndIf
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $idClose
ExitLoop
Case $idComboBox1
Case $idComboBox2
EndSwitch
WEnd 基础已经完成,谢谢大家了。
#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
GUICtrlSetState($idComboBox1, $GUI_FOCUS)
Case $idComboBox2
GUICtrlSetState($idComboBox2, $GUI_FOCUS)
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 Then Return SetError(1000, 0, 0)
Return $aRet
EndFunc ;==>__TrackMouseEvent
页:
[1]