question

ShabariPragash-5690 avatar image
0 Votes"
ShabariPragash-5690 asked RLWA32-6355 commented

Create small win32 window which is draggable

I want to create a small win32 window which is draggable.

I tried to create a small window by using the following code where i have specified the width and height of window to be 60, 60 resp. But the created window looks like it is 120 width and 60 height i.e., it has slightly larger width. I think it has added empty title bar/caption bar and hence width became larger. I have attached the image of window for your reference. This window is draggable.

    HWND hWnd = CreateWindowW(szWindowClass, NULL, WS_VISIBLE | WS_BORDER,
        1200, 800, 60, 60,
        nullptr, nullptr, hInstance, nullptr);


198550-screenshot-287.png


Then i changed the window style to WS_POPUP, which created window with width and height as 60 and 60 resp. But this window is not draggable. It's position is fixed. I have attached the image of window for your reference.

    HWND hWnd = CreateWindowW(szWindowClass, NULL, WS_POPUP | WS_BORDER,
        1200, 800, 60, 60,
        nullptr, nullptr, hInstance, nullptr);

198526-screenshot-289.png


Kindly let me know what i need to change so that i can create small draggable window.



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.

Any update for this?

0 Votes 0 ·

1 Answer

RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered RLWA32-6355 edited

Window procedure to drag a window without a caption (title bar) created with WS_POPUP | WS_BORDER. Hold down the left mouse button anywhere in the window and drag it.

 LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
  switch (msg)
  {
  case WM_NCHITTEST:
  return HTCAPTION;
  break;
  case WM_DESTROY:
  PostQuitMessage(0);
  break;
    
  default:
  return DefWindowProcW(hwnd, msg, wParam, lParam);
  }
    
  return 0;
 }
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.