如何判断在激活一个窗口后鼠标是否在该窗口上活动【已解决】
本帖最后由 872777825 于 2013-12-12 13:46 编辑如上图首次运行只出现窗口1
当鼠标移动到窗口1的 BUT...1的时候弹出并激活窗口2
那么现在的问题是 如果判断如果鼠标不在窗口1上 或
不在窗口2上 2秒钟后自动关闭窗口2
窗口1 保留显示
麻烦长辈们指点下 百度了下鼠标停留是mousehover事件,但是这个事件必须配合TrackMouseEvent使用,结果发现论坛已经有人写好了 那就太方便了
http://www.autoitx.com/forum.php?mod=viewthread&tid=29731
判断坐标X Y 是否在按钮坐标范围之类,再执行下面的操作。
如果不需要判断停留 应该一个MOUSEMOVE事件就够用了。 回复 2# zch11230
非常感谢 先看看 如果知道窗口句柄 比较简单
_WinApi_WindowFromPoint
获取当前鼠标下的窗口句柄 回复 4# Ycxw2008
看错问题了
再补充吧:
#include <WinAPIEx.au3>
#include <APIConstants.au3>
Global $bTrack
Global $m_hWnd = GUICreate('',200,200,400,400,$WS_VISIBLE+$WS_POPUP)
GUISetState()
GUIRegisterMsg($WM_MOUSEMOVE, "OnMouseMove")
GUIRegisterMsg($WM_MOUSELEAVE, "OnMouseLeave")
While GUIGetMsg() <> -3
Sleep(10)
WEnd
Func OnMouseMove($hWnd, $Msg, $wParam, $lParam)
If Not $bTrack Then
$bTrack = True
_WinAPI_TrackMouseEvent($hWnd, $TME_LEAVE)
EndIf
Return 0
EndFunc ;==>OnMouseMove
Func OnMouseLeave($hWnd, $Msg, $wParam, $lParam)
$bTrack = False
For $I = 5 To 1 Step -1
ToolTip($I & "秒后关闭窗口",400,400)
Sleep(1000)
Next
GUIDelete($hWnd)
Return 0
EndFunc ;==>OnMouseLeave
回复 5# Ycxw2008
Ycxw2008 非常感谢结合修改了下问题基本上解决了 谢谢 回复 6# 872777825
不知道修改的啥?
现在主流的DirectUI 也是这样的操作的
贴段代码给你吧,有兴趣自己研究研究
出自Duilib case WM_MOUSELEAVE:
{
if( m_hwndTooltip != NULL ) ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, FALSE, (LPARAM) &m_ToolTip);
if( m_bMouseTracking ) ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, (LPARAM) -1);
m_bMouseTracking = false;
}
break;
case WM_MOUSEMOVE:
{
// Start tracking this entire window again...
if( !m_bMouseTracking ) {
TRACKMOUSEEVENT tme = { 0 };
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.dwFlags = TME_HOVER | TME_LEAVE;
tme.hwndTrack = m_hWndPaint;
tme.dwHoverTime = m_hwndTooltip == NULL ? 400UL : (DWORD) ::SendMessage(m_hwndTooltip, TTM_GETDELAYTIME, TTDT_INITIAL, 0L);
_TrackMouseEvent(&tme);
m_bMouseTracking = true;
}
// Generate the appropriate mouse messages
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
m_ptLastMousePos = pt;
CControlUI* pNewHover = FindControl(pt);
if( pNewHover != NULL && pNewHover->GetManager() != this ) break;
TEventUI event = { 0 };
event.ptMouse = pt;
event.dwTimestamp = ::GetTickCount();
if( pNewHover != m_pEventHover && m_pEventHover != NULL ) {
event.Type = UIEVENT_MOUSELEAVE;
event.pSender = m_pEventHover;
m_pEventHover->Event(event);
m_pEventHover = NULL;
if( m_hwndTooltip != NULL ) ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, FALSE, (LPARAM) &m_ToolTip);
}
if( pNewHover != m_pEventHover && pNewHover != NULL ) {
event.Type = UIEVENT_MOUSEENTER;
event.pSender = pNewHover;
pNewHover->Event(event);
m_pEventHover = pNewHover;
}
if( m_pEventClick != NULL ) {
event.Type = UIEVENT_MOUSEMOVE;
event.pSender = m_pEventClick;
m_pEventClick->Event(event);
}
else if( pNewHover != NULL ) {
event.Type = UIEVENT_MOUSEMOVE;
event.pSender = pNewHover;
pNewHover->Event(event);
}
}
break;
页:
[1]