Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Intermediate
Aug 19, 2002

How To Capture a Mouse Without SetCapture

 
typedef BOOL ( CALLBACK *REPEATUNTILRELEASECALLBACK )( POINT
ptScreen, LPARAM lParam );

BOOL RepeatUntilRelease( HWND hWnd, REPEATUNTILRELEASECALLBACK
fctRepeatUntilRelease, LPARAM lParam, RECT* prtClipping, UINT vk )
{
	MSG message; ZeroMemory( &message, sizeof(message) );
	if ( IsWindow( hWnd ) )
	{
		while ( IsWindow( hWnd ) )
		{

			POINT ptMessagePosition = _
{ LOWORD( GetMessagePos()),
HIWORD(GetMessagePos() )};
			if ( PeekMessage( &message, _
NULL, WM_MOUSEFIRST, WM_MOUSELAST,
PM_REMOVE) || PeekMessage(&message, NULL, WM_KEYFIRST, _
WM_KEYLAST,
PM_REMOVE) )
			{
				TranslateMessage( &message );
				DispatchMessage(&message);

				// check for button _
cancellation (any button down will cancel)
				if ( message.message == _
WM_LBUTTONUP || message.message ==
WM_RBUTTONUP || message.message == _
WM_LBUTTONDOWN || message.message ==
WM_RBUTTONDOWN )
					return TRUE;
				// check for keyboard _
cancellation
				if ( ( message.message ==_
 WM_KEYDOWN ) || ( message.message ==
WM_SYSKEYDOWN ) )
					return FALSE;
			}

			if ( !( GetAsyncKeyState( vk ) < 0 ) )
				return TRUE;

			if ( ( GetAsyncKeyState_
( VK_RBUTTON ) < 0 ) ||
GetAsyncKeyState( VK_ESCAPE ) < 0 ) )
				return FALSE;

			if ( ( prtClipping == NULL ) || _
( PtInRect( prtClipping,
ptMessagePosition ) ) )
				if ( (*fctRepeatUntilRelease)( ptMessagePosition, lParam ) )
					break;

			MSG msg;
			while ( PeekMessage( &msg, NULL, NULL, NULL, PM_REMOVE ) )
			{
				TranslateMessage( &msg );
				DispatchMessage( &msg );
			};

			Sleep( 2 );

		}
	}
	return TRUE;
};

Mike Filimon
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date