本帖最后由 298311657 于 2015-11-20 20:15 编辑
使用_WinAPI_SetWindowLong子类化控件,然后为控件添加WM_MOUSEHOVER或WM_MOUSELEAVE,正常情况下消息并不会响应,可以使用_WinAPI_TrackMouseEvent处理一下。
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <WinAPISys.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 442, 192, 124)
$Label1 = GUICtrlCreateLabel("如何设置鼠标触摸标签时字体的颜色【带手型效果】", 120, 96, 280, 17, BitOR($SS_NOTIFY, $SS_LEFT))
$wStaticProcNew = DllCallbackRegister("_MyStaticProc", "int", "hwnd;uint;uint;dword")
$wStaticProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), $GWL_WNDPROC, DllCallbackGetPtr($wStaticProcNew))
$Label2 = GUICtrlCreateLabel("标签2", 120, 150, 280, 17)
$wStaticProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), $GWL_WNDPROC, DllCallbackGetPtr($wStaticProcNew))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _MyStaticProc($hWnd, $uiMsg, $wParam, $lParam)
Switch $uiMsg
Case $WM_LBUTTONDOWN;左键点击
MsgBox(0,"", "点击的控件id:" & _WinAPI_GetDlgCtrlID($hWnd))
Case $WM_MOUSEHOVER;鼠标悬停
GUICtrlSetColor(_WinAPI_GetDlgCtrlID($hWnd), 0xFF0000)
Case $WM_MOUSELEAVE;鼠标离开
GUICtrlSetColor(_WinAPI_GetDlgCtrlID($hWnd), 0x000000)
Case $WM_MOUSEMOVE;鼠标移动
_WinAPI_TrackMouseEvent($hWnd, BitOR($TME_HOVER, $TME_LEAVE)) ;//MOUSELEAVE|MOUSEHOVER消息由此函数触发
Case $WM_SETCURSOR;设置光标
GUICtrlSetCursor(_WinAPI_GetDlgCtrlID($hWnd), 0)
EndSwitch
Return _WinAPI_CallWindowProc($wStaticProcOld, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc
|