鼠标停留、移出窗口事件
没事看到这两个事件,原来还要wm_mousemove事件的#include <Winapi.au3>
Global Const $WM_MOUSEMOVE = 0x0200 ;鼠标移动
Global Const $WM_MOUSEHOVER = 0x02A1 ;鼠标停留
Global Const $WM_MOUSELEAVE = 0x02A3 ;鼠标离开
Global Const $TME_HOVER = 0x00000001
Global Const $TME_LEAVE = 0x00000002
$Form1 = GUICreate("测试", 261, 254, 192, 124)
GUISetState()
GUIRegisterMsg($WM_MOUSEMOVE, "WM_MOUSEMOVE")
GUIRegisterMsg($WM_MOUSEHOVER, "WM_MOUSEHOVER")
GUIRegisterMsg($WM_MOUSELEAVE, "WM_MOUSELEAVE")
While GUIGetMsg() <> -3
WEnd
Func WM_MOUSEMOVE($hWnd, $Msg, $wParam, $lParam)
$tagTRACKMOUSEEVENT = DllStructCreate("DWORD cbSize;DWORD dwFlags;HWNDhwndTrack;DWORD dwHoverTime")
DllStructSetData($tagTRACKMOUSEEVENT, "cbSize", DllStructGetSize($tagTRACKMOUSEEVENT)) ;结构体缓冲区大小
DllStructSetData($tagTRACKMOUSEEVENT, "dwFlags", BitOR($TME_HOVER,$TME_LEAVE)) ;注册WM_MOUSEHOVER和$WM_MOUSELEAVE消息
DllStructSetData($tagTRACKMOUSEEVENT, "hwndTrack", $hWnd) ;当前窗口句柄
DllStructSetData($tagTRACKMOUSEEVENT, "dwHoverTime", 300) ;触发的时间300ms
$TRACKMOUSEEVENT = DllStructGetPtr($tagTRACKMOUSEEVENT)
DllCall("user32.dll", "bool", "TrackMouseEvent","ptr",$TRACKMOUSEEVENT)
EndFunc ;==>WM_MOUSEMOVE
Func WM_MOUSEHOVER($hWnd, $Msg, $wParam, $lParam)
$X = _WinAPI_LoWord($lParam)
$Y = _WinAPI_HiWord($lParam)
TrayTip("鼠标在窗口坐标", "X:" & $X & " Y:" & $Y, 1, 1)
EndFunc ;==>WM_MOUSEHOVER
Func WM_MOUSELEAVE($hWnd, $Msg, $wParam, $lParam)
TrayTip("提示","鼠标移出窗口了!",1,1)
EndFunc
本帖最后由 xx44t10 于 2012-1-6 19:13 编辑
谢谢你的代码.学习先 你这个不能对无边框窗体 使用它啊 回复 2# xx44t10
无边框窗体当然也可以。#include <Winapi.au3>
Global Const $WM_MOUSEMOVE = 0x0200 ;鼠标移动
Global Const $WM_MOUSEHOVER = 0x02A1 ;鼠标停留
Global Const $WM_MOUSELEAVE = 0x02A3 ;鼠标离开
Global Const $TME_HOVER = 0x00000001
Global Const $TME_LEAVE = 0x00000002
Global Const $WS_SYSMENU = 0x00080000
Global Const $WS_POPUP = 0x80000000
;$Form1 = GUICreate("测试", 261, 254, 192, 124)
$Form1 = GUICreate('无边框', 261, 254, 192, 124, BitOR($WS_SYSMENU, $WS_POPUP))
GUISetState()
GUIRegisterMsg($WM_MOUSEMOVE, "WM_MOUSEMOVE")
GUIRegisterMsg($WM_MOUSEHOVER, "WM_MOUSEHOVER")
GUIRegisterMsg($WM_MOUSELEAVE, "WM_MOUSELEAVE")
While GUIGetMsg() <> -3
WEnd
Func WM_MOUSEMOVE($hWnd, $Msg, $wParam, $lParam)
$tagTRACKMOUSEEVENT = DllStructCreate("DWORD cbSize;DWORD dwFlags;HWNDhwndTrack;DWORD dwHoverTime")
DllStructSetData($tagTRACKMOUSEEVENT, "cbSize", DllStructGetSize($tagTRACKMOUSEEVENT)) ;结构体缓冲区大小
DllStructSetData($tagTRACKMOUSEEVENT, "dwFlags", BitOR($TME_HOVER,$TME_LEAVE)) ;注册WM_MOUSEHOVER和$WM_MOUSELEAVE消息
DllStructSetData($tagTRACKMOUSEEVENT, "hwndTrack", $hWnd) ;当前窗口句柄
DllStructSetData($tagTRACKMOUSEEVENT, "dwHoverTime", 300) ;触发的时间300ms
$TRACKMOUSEEVENT = DllStructGetPtr($tagTRACKMOUSEEVENT)
DllCall("user32.dll", "bool", "TrackMouseEvent","ptr",$TRACKMOUSEEVENT)
EndFunc ;==>WM_MOUSEMOVE
Func WM_MOUSEHOVER($hWnd, $Msg, $wParam, $lParam)
$X = _WinAPI_LoWord($lParam)
$Y = _WinAPI_HiWord($lParam)
TrayTip("鼠标在窗口坐标", "X:" & $X & " Y:" & $Y, 1, 1)
EndFunc ;==>WM_MOUSEHOVER
Func WM_MOUSELEAVE($hWnd, $Msg, $wParam, $lParam)
TrayTip("提示","鼠标移出窗口了!",1,1)
EndFunc 为了获取高两字节和低两字节就include一个大文件,体积可能会不必要地增大吧,直接 BitAnd 做一下位运算好了。 回复 3# xiehuahere
谢谢.原来我没把Global Const $WS_SYSMENU = 0x00080000
Global Const $WS_POPUP = 0x80000000它们全局定义 所以出错了 哎呀,是咱的风哥呀.支持支持啊! 谢谢楼主分享 支持,支持。 很实用的一个小东西,学习了! 这个挺好的 好东西呀,支持。 這個用於判斷還不錯啊
將之套用在判斷鼠標不再窗口中
就將ToolTip取消掉,'ˋ只是尚未能完美...XD
页:
[1]