Reputation: 309
I'm designing a custom window border, and i put a bitmap on the top as a drag bar. This works, however when i try to drag the window, it places itself in two different areas and flickers between the two. Here's a video:
http://dl.dropbox.com/u/85700751/capture-1.avi
When the window is flashing, i'm trying to drag it (it doesn't show my cursor for some reason). Here's my dragging code:
case WM_LBUTTONDOWN: {
int posX = LOWORD(lParam);
int posY = HIWORD(lParam);
if((isDragging==false)&&(posX>4)&&(posX<470)&&(posY>4)&&(posY<24))
{
isDragging = true;
ClipCursor(rect);
oldCursorX = posX;
oldCursorY = posY;
}
}
break;
case WM_LBUTTONUP: {
isDragging = false;
ClipCursor(NULL);
}
break;
case WM_MOUSEMOVE: {
if(isDragging) {
SetWindowPos(hWnd, NULL, LOWORD(lParam)-oldCursorX, HIWORD(lParam)-oldCursorY, 500, 500, NULL);
}
}
break;
Upvotes: 3
Views: 1487
Reputation: 2313
It's generally easiest to simply resond to WM_NCHITTEST. For that message, the LPARAM will have the mouse hit X and Y coordinates (same as WM_LBUTTONDOWN). If they're within your draggable area just return HTCAPTION. The system will then automatically handle all the drag logic for you.
Upvotes: 5
Reputation: 3281
The cursor coordinates passed to WM_MOUSEMOVE are relative to the window position. But you keep changing the window position with every WM_MOUSEMOVE recieved.
Convert the coordinates to Screen coordinates using ::ClientToScreen().
Upvotes: 0