Home
Tutorials
Code Snippets
Code Samples
Downloads
Links

The Blog
Our Projects
About
Contact

::Add RageStorm to Favorites!::

The Blog | Our Projects | Guest Book | About | Contact

 
Code Snippet - Window Draggable by Client Area
Author:Arkon
Category:Win32API
File Size:~ 1.05 KB
Uploaded at:10-Sep-06 08:44:19 pm
Description:
  This tiny snippet will make your window draggable by its client area, just like the dragging by caption.
  
// In your window procedure:
//Define
static POINT relPos;

// And paste the following code:
case WM_LBUTTONDOWN:
GetCursorPos(&relPos); // Get screen mouse pos!
ScreenToClient(hWnd, &relPos);
SetCapture(hWnd);
return 0;
case WM_LBUTTONUP:
ReleaseCapture();
return 0;
case WM_MOUSEMOVE:
if (wParam & MK_LBUTTON) {
RECT rect;
GetWindowRect(hWnd, &rect); // Screen relative.
POINT p;
// I call this function instead of using lParam,
// because, sometimes you might be out of the window area.
GetCursorPos(&p);
ScreenToClient(hWnd, &p);
// This is the trick :)
// Notice we use the relPos so the window position is always(!)
// relative to the initial point we started the dragging.
// What acutally moves the window is that we take into calculation
// the current position of the mouse inside the client area.
MoveWindow(hWnd,
   rect.left - relPos.x + p.x,
   rect.top - relPos.y + p.y,
   rect.right - rect.left,
   rect.bottom - rect.top,
   true);
}
return 0;
User Contributed Comments(1)
 [1] arkon | 2007-03-23 10:45:46

actually there is another easier way to do the same thing with much less effort, check out the WM_NCHITTEST message...you should return HTCAPTION...
NOTE:
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
notice. Use the comment system decently.

Post your comment:
Name:
email:
Comment:
::Top 5 Tutorials::
Embedded Python[117053]
2D Rotated Rectangles Collision Detection[88982]
Keyboard Hook[77320]
UDP[65824]
HTTP Proxy[41213]

::Top 5 Samples::
2D ColDet Rotated Rectangles[11561]
PS2 Mouse Driver[6958]
Wave Format Player[5792]
Reading FAT12[5620]
CodeGuru[5359]


All rights reserved to RageStorm © 2009