question

ShabariPragash-5690 avatar image
0 Votes"
ShabariPragash-5690 asked JunjieZhu-MSFT commented

Create small win32 window which is both draggable and clickable

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.

windows-api
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, @ShabariPragash-5690
I used the code in the link shared by RLWA32 and successfully implemented the function you want, it has been a few days, have you solved this problem?

0 Votes 0 ·

1 Answer

RLWA32-6355 avatar image
1 Vote"
RLWA32-6355 answered RLWA32-6355 edited

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.