找回密码
 加入
搜索
查看: 9360|回复: 12

[原创] 鼠标停留、移出窗口事件

 火.. [复制链接]
发表于 2012-1-6 17:06:45 | 显示全部楼层 |阅读模式
没事看到这两个事件,原来还要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;HWND  hwndTrack;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

评分

参与人数 3金钱 +72 贡献 +11 收起 理由
lixiaolong + 30 + 5
tryhi + 30 + 5
xiehuahere + 12 + 1 学习。楼主总是有好东西!

查看全部评分

发表于 2012-1-6 17:27:05 | 显示全部楼层
本帖最后由 xx44t10 于 2012-1-6 19:13 编辑

谢谢你的代码.学习先 你这个不能对无边框窗体 使用它啊
发表于 2012-1-9 23:36:09 | 显示全部楼层
回复 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;HWND  hwndTrack;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
发表于 2012-1-9 23:41:45 | 显示全部楼层
为了获取高两字节和低两字节就include一个大文件,体积可能会不必要地增大吧,直接 BitAnd 做一下位运算好了。
发表于 2012-1-11 21:42:56 | 显示全部楼层
回复 3# xiehuahere


  谢谢.原来我没把
Global Const $WS_SYSMENU = 0x00080000

Global Const $WS_POPUP = 0x80000000
它们全局定义 所以出错了
发表于 2012-2-20 15:05:04 | 显示全部楼层
哎呀,是咱的风哥呀.支持支持啊!
发表于 2012-2-21 21:27:29 | 显示全部楼层
谢谢楼主分享
发表于 2015-1-20 16:27:41 | 显示全部楼层
支持,支持。
发表于 2017-3-23 19:23:23 | 显示全部楼层
很实用的一个小东西,学习了!
发表于 2017-4-18 11:53:20 | 显示全部楼层
这个挺好的
发表于 2017-8-9 10:56:29 | 显示全部楼层
好东西呀,支持。
发表于 2019-5-25 18:50:43 | 显示全部楼层
這個用於判斷還不錯啊
將之套用在判斷鼠標不再窗口中
就將ToolTip取消掉,'ˋ只是尚未能完美...XD
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-4 01:38 , Processed in 0.089950 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表