|
-
March 3rd, 2019, 11:39 PM
#1
Cursor and Window position problem
I'm trying to create 2 windows and magnet them so they stay close to each other by 10px: the main window and bottom window. The bottom window act as a resizer for main window when user drag it.
Everything is fine with one problem: when main window is moved, the cursor points are not correct anymore. I posted below the pseudo code and a screenshot to show the effect problem.
Code:
hwndMain = CreateWindow(L"classMain", L"main", WS_POPUP, 50, 0, 800, 600, NULL, NULL, instanceMain, NULL);
hwndResizer = CreateWindowEx(WS_EX_LAYERED, TEXT("classResizer"), L"", WS_POPUP, 400, 610, 55, 35, hwndMain, NULL, instanceMain, NULL);
resizer proc
Code:
case WM_LBUTTONUP: {
ReleaseCapture();
} break;
case WM_LBUTTONDOWN: {
SetCapture(hwndBottomResizer);
} break;
case WM_MOUSEMOVE: {
if (wParam & MK_LBUTTON) {
RECT bottomResizerRect, mainWindowRect;
POINT posBottomResizer;
GetWindowRect(hwndBottomResizer, &bottomResizerRect);
GetWindowRect(hwndMain, &mainWindowRect);
posBottomResizer.x = GET_X_LPARAM(lParam); //(int)(short)LOWORD(lParam);
posBottomResizer.y = GET_Y_LPARAM(lParam); //(int)(short)HIWORD(lParam);
ClientToScreen(hwndBottomResizer, &posBottomResizer);
HDWP move = BeginDeferWindowPos(2);
DeferWindowPos(move, hwndMain, 0, mainWindowRect.left, mainWindowRect.top, mainWindowRect.right - mainWindowRect.left, posBottomResizer.y, 0);
DeferWindowPos(move, hwndBottomResizer, 0, bottomResizerRect.left, posBottomResizer.y + 10, bottomResizerRect.right - bottomResizerRect.left, 35, 0);
EndDeferWindowPos(move);
}
} break;
main proc
Code:
case WM_NCHITTEST: {
moveWindows = DefWindowProc(hwnd, message, wParam, lParam);
RECT rc, brc;
GetWindowRect(hwnd, &rc);
GetWindowRect(hwndBottomResizer, &brc);
POINT pt;
pt.x = GET_X_LPARAM(lParam);
pt.y = GET_Y_LPARAM(lParam);
ScreenToClient(hwnd, &pt);
HDWP move = BeginDeferWindowPos(1);
//DeferWindowPos(move, hwndMain, 0, mainWindowRect.left, mainWindowRect.top, mainWindowRect.right - mainWindowRect.left, posBottomResizer.y, 0);
DeferWindowPos(move, hwndBottomResizer, 0, brc.left, rc.bottom + 10, brc.right - brc.left, 35, 0);
EndDeferWindowPos(move);
if (moveWindows == HTCLIENT) {
return HTCAPTION;
}
else {
return moveWindows;
}
} break;
See below gif for effect problem.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|