Implement the additional code described in the answer here - how-do-i-implement-dragging-a-window-using-its-client-area. If your button takes the entire client area of the parent window then you need to drag the window by using its border. So test for both HTCLIENT and HTBORDER.
Create small win32 window which is both draggable and clickable
Shabari Pragash
126
Reputation points
Created a small window
HWND hWnd = CreateWindowW(szWindowClass, NULL, WS_POPUP | WS_BORDER,
1200, 800, 60, 60,
nullptr, nullptr, hInstance, nullptr);
Dragging window is working when the following code is added in window procedure,
case WM_NCHITTEST:
return HTCAPTION;
break;
But unfortunately dragging stopped working after i added a button in the window. I need to capture click event so added a button. Click event is working, i.e., i get the message box when i click.
case WM_COMMAND:
{
MessageBoxW(NULL, L"WM_COMMAND", L"msgbox", MB_OK);
}
break;
case WM_CREATE:
{
hButton = CreateWindow(L"BUTTON", NULL,
WS_CHILD | WS_VISIBLE, 0, 0, 60, 60, hWnd, 0, NULL, NULL);
}
break;
I like to have both dragging and clicking to work.