Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Instead of manually tracking the mouse or swapping the buttons, there is an easier way - in response to <code>WM_NCRBUTTONDOWN</code>, simply put the window into a move mode natively by sending it a special <code>WM_SYSCOMMAND</code> message, then it will handle all the hard work of dragging for you, eg:</p> <pre><code>const WPARAM MOUSE_MOVE = SC_MOVE + 2; case WM_NCRBUTTONDOWN: { POINT pt; GetCursorPos(&amp;pt); SendMessage(Handle, WM_NCRBUTTONUP, 0, MAKELPARAM(pt.x, pt.y)); SendMessage(Handle, WM_SYSCOMMAND, MOUSE_MOVE, MAKELPARAM(pt.x, pt.y)); break; } </code></pre> <p>See <a href="http://support.microsoft.com/kb/114593/" rel="nofollow">Q114593</a> for more details.</p> <p><strong>Update:</strong> I wasn't able to get <code>WM_SYSCOMMAND</code> to work with right-clicking (it works great when left-clicking on child controls, though). I think the OS is doing some internally processing that simply makes it impossible to work correctly. So I went with the approach of intercepting mouse movements to move the window manually, making it operate correctly with fast mouse movements without the use of a timer by using <code>SetCapture()</code> instead:</p> <pre><code>bool RightButton_CanMove = false; bool RightButton_WindowMoved = false; POINTS LastPoint; void __fastcall TForm1::WndProc(TMessage &amp;Message) { switch( Message.Msg ) { case WM_NCRBUTTONDOWN: LastPoint = MAKEPOINTS(Message.LParam); RightButton_CanMove = true; RightButton_WindowMoved = false; SetCapture(Handle); Message.Result = 0; return; case WM_MOUSEMOVE: if( (Message.WParam &amp; MK_RBUTTON) &amp;&amp; (RightButton_CanMove) ) { POINT CurPoint; GetCursorPos(&amp;CurPoint); SetWindowPos(Handle, NULL, Left + (CurPoint.x - LastPoint.x), Top + (CurPoint.y - LastPoint.y), 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); LastPoint.x = CurPoint.x; LastPoint.y = CurPoint.y; RightButton_WindowMoved = true; } break; case WM_RBUTTONUP: if( RightButton_CanMove ) { RightButton_CanMove = false; ReleaseCapture(); if( RightButton_WindowMoved ) { RightButton_WindowMoved = false; Message.Result = 0; return; } } break; } TForm::WndProc(Message); } </code></pre> <p>The code differentiates between right-click and right-move operations. If the user right-clicks the mouse without moving it, the default popup menu is allowed to appear normally. If the user holds down the right mouse button down and moves the window around, the default popup is not displayed when the user releases the right button.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload