How To Capture a Mouse Without SetCapture

 typedef BOOL ( CALLBACK *REPEATUNTILRELEASECALLBACK )( POINTptScreen, LPARAM lParam );BOOL RepeatUntilRelease( HWND hWnd, REPEATUNTILRELEASECALLBACKfctRepeatUntilRelease, 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;};

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: