ClientToScreen() is causing mysterious problems, and I cannot figure out why
case WM_LBUTTONDOWN:
initPos.x = LOWORD(lParam);
initPos.y = HIWORD(lParam);
break;
case WM_MOUSEMOVE:
{
POINT realPos;
RECT clientRect;
int rSect = 0;
GetClientRect(hWnd, &clientRect);
realPos.x = (int)(short) LOWORD(lParam);
realPos.y = (int)(short) HIWORD(lParam);
ClientToScreen(hWnd, reinterpret_cast<POINT*>(&clientRect.left));
ClientToScreen(hWnd, reinterpret_cast<POINT*>(&clientRect.right));
if(wParam == MK_LBUTTON)
{
if(!rSect)
{
MoveWindow(hWnd, clientRect.left + (realPos.x -
initPos.x), clientRect.top + (realPos.y - initPos.y),
width, height, TRUE);
}
}
break;
}
This is a basic snippet of my program that allows my custom window to be
dragged around the screen. It works perfect, and I am content with it.
But when I innocently tried to convert realPos and initPos coordinates to
screen positions, the window started glitching out every time I dragged
it, source code here:
case WM_LBUTTONDOWN:
initPos.x = LOWORD(lParam);
initPos.y = HIWORD(lParam);
break;
case WM_MOUSEMOVE:
{
POINT realPos;
RECT clientRect;
int rSect = 0;
GetClientRect(hWnd, &clientRect);
realPos.x = (int)(short) LOWORD(lParam);
realPos.y = (int)(short) HIWORD(lParam);
ClientToScreen(hWnd, reinterpret_cast<POINT*>(&clientRect.left));
ClientToScreen(hWnd, reinterpret_cast<POINT*>(&clientRect.right));
ClientToScreen(hWnd, &realPos);
ClientToScreen(hWnd, &initPos);
if(wParam == MK_LBUTTON)
{
if(!rSect)
{
MoveWindow(hWnd, clientRect.left + (realPos.x -
initPos.x), clientRect.top + (realPos.y - initPos.y),
width, height, TRUE);
}
}
break;
}
The initPos and realPos should be relative to eachother, as long as they
are both relative to the same grid, whether it be a client area or the
screen in general. Can anybody tell me why this, then, isn't working? I
feel like I'm missing something blatantly obvious...
No comments:
Post a Comment