admin 管理员组

文章数量: 1184232

鼠标在得到左键双击事件时,同时也得到了左键down的消息。在只想处理双击事件而不处理按下事件,有下面的方法。


思路:

在收到单击事件后,不处理单击事件,而是settimer,将单击事件对应的操作放到timer中,如果再收到双击事件,则killtimer,使得单击事件不再执行。


相关参考代码:

void CDlgVideo::OnLButtonDown(UINT nFlags, CPoint point)
{
CDialog::OnLButtonDown(nFlags, point);


KillTimer(TIMER_ID_LBUTTONDOWN);
SetTimer(TIMER_ID_LBUTTONDOWN, GetDoubleClickTime()+1, NULL);

TRACE("[CDlgVideo::OnLButtonDown] %d\n", GetTickCount());


/*
On simple click, kill the previous timer,
if any, and start a new timer with SetTimer. The timeout interval is
the value returned by GetDoubleClickTime plus several microseconds.
Then, in the handler for timer call KillTimer and execute your actions
designed for simple clicks. In the handler for double clicks, call
KillTimer and execute your actions designed for double clicks.
*/

}

//////////

void CDlgVideo::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == TIMER_ID_LBUTTONDOWN)
{
TRACE("[CDlgVideo::OnTimer] %d\n", GetTickCount());
KillTimer(TIMER_ID_LBUTTONDOWN);
CPoint point;
GetCursorPos(&point);
ScreenToClient(&point);


if (m_hAVCPlayer != NULL && avcpIsFullScreen(m_hAVCPlayer))
{


}
else
{
if (AfxGetMainWnd() != NULL)
{
//TRACE("[CDlgVideo::OnLButtonDown] point x %d, y %d\n", point.x, point.y);
ClientToScreen(&point);
AfxGetMainWnd()->ScreenToClient(&point);
::SendMessage(AfxGetMainWnd()->GetSafeHwnd(), WM_LBUTTONDOWN, /*nFlags*/MK_LBUTTON, MAKELPARAM(point.x, point.y));
}
}
}


CDialog::OnTimer(nIDEvent);
}



void CDlgVideo::OnLButtonDblClk(UINT nFlags, CPoint point)
{

KillTimer(TIMER_ID_LBUTTONDOWN);


if (PtInRect(m_rectStaticPlayer, point))
{
if (m_hAVCPlayer != NULL)
{
int nPlayState = avcpGetPlayState(m_hAVCPlayer);
if (nPlayState == 1 || nPlayState == 3)
{
if (avcpIsFullScreen(m_hAVCPlayer))
{
avcpSetFullScreen(m_hAVCPlayer, false);
}
else
{
avcpSetFullScreen(m_hAVCPlayer, true);
}
}
}
}


CDialog::OnLButtonDblClk(nFlags, point);
}


////

如果左键按下可能对应完成拖动的操作,则有以下参考代码

void CDlgVideo::OnMouseMove(UINT nFlags, CPoint point)
{
if (KillTimer(TIMER_ID_LBUTTONDOWN))
{
// left button is down, now move, so do drag move
SetTimer(TIMER_ID_LBUTTONDOWN, 1, NULL);
}



CDialog::OnMouseMove(nFlags, point);
}




本文标签: 配置问题 解决 里轻松搞