Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted

1 solution

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

So you get all Mouse Messages while the capture is set

For example:
C++
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
}


Or see here[^].
 
Share this answer
 
v2
Comments
the vacuum 20-Mar-14 5:00am    
I tried that, but the mouse click event in toolbar is not forwarding to my view class..
C3D1 20-Mar-14 5:30am    
Maybe you could inherit the toolbar to have your own customizable toolbar and then in your custom toolbar you could send these messages directly to your view class

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900