如何找到鼠标按住? [英] How do I find Mouse press and hold?

查看:107
本文介绍了如何找到鼠标按住?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的MFC doc-view应用程序中连续执行一个函数(用于操作),同时使用鼠标左键按住我的一个工具栏按钮(缩放按钮)。

如何跟踪按住鼠标左键?这是什么标准方法?



我试图实现如果使用一个标记设置在鼠标左键(OnLButtonDown)并清除

左键向上鼠标(OnLButtonUp)并在工具栏按钮处理程序(OnZoomIn)函数中检查其状态,但是while循环没有终止鼠标按钮。

我的代码如下



BOOL blMouseLButtonStatus;

int nZoom;



void OnLButtonDown(UINT nFlags,CPoint (); b $ b $
OnLButtonUp(UINT nFlags,CPoint point);

{

blMouseLButtonStatus = false;

}

void OnZoomIn( )

{

while(blMouseLButtonStatus)

{

nZoom + = 1;

}

}



有一种方法可以在鼠标按键事件中终止执行上面的OnZoomIn()函数吗?

我认为必须使用线程来处理,我是对的吗?

I need to continuously execute a function (for operation) in my MFC doc-view application while press and hold one of my toolbar button (zoom button) using left mouse button.
How can I track press and hold of a mouse left button? is any standard method for that?

I tried to implement if using a flag which set on left mouse down (OnLButtonDown)and clear on
left mouse up (OnLButtonUp) and checking it's status inside a while loop in toolbar button handler (OnZoomIn) function, but the while loop not terminating mouse button up.
My code is as follows

BOOL blMouseLButtonStatus;
int nZoom;

void OnLButtonDown(UINT nFlags, CPoint point);
{
blMouseLButtonStatus = true;

}
void OnLButtonUp(UINT nFlags, CPoint point);
{
blMouseLButtonStatus = false;
}
void OnZoomIn()
{
while(blMouseLButtonStatus )
{
nZoom += 1;
}
}

Have a method to terminate execution of above OnZoomIn() function on mouse button up event?
I think have to incorporate threading for even handling, am I right?

推荐答案

在OnLButtonDown中调用:: SetCapture()并在OnLButtonUp中调用: :ReleaseCapture()。



所以你在设置捕获时获得所有鼠标消息



例如:

in OnLButtonDown you call ::SetCapture()and in OnLButtonUp you call ::ReleaseCapture().

So you get all Mouse Messages while the capture is set

For example:
MyClass::OnLButtonDown(UINT nFlags,CPoint point)
{
    ::SetCapture(this->m_hWnd);
}

MyClass::OnLButtonUp(UINT nFlags,CPoint point )
{
    ::ReleaseCapture();
}

MyClass::OnMouseMove(UINT nFlags, CPoint point)
{
    // Your code here
}





或者看here [ ^ ]。


这篇关于如何找到鼠标按住?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆