devxlogo

How To Capture a Mouse Without SetCapture

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;};

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist