Search code examples
c++wpfwinapiinteroppinvoke

Inconsistent window styles behavior when trying to disable window resizing in win 32


I have the following styles applied to my window and I can resize which is expected (WS_CAPTION, WS_VISIBLE, WS_CLIPSIBLINGS, WS_CLIPCHILDREN, WS_SYSMENU, WS_THICKFRAME, WS_OVERLAPPED, WS_MAXIMIZEBOX, WS_MINIMIZEBOX). My aim is to remove WS_SYSMENU and disable resizing.

So I then remove WS_THICKFRAME and window resizing is disabled as expected. I then have to also remove WS_SYSMENU as well but window resizing comes back.

My final set of styles are (WS_CAPTION, WS_VISIBLE, WS_CLIPSIBLINGS, WS_CLIPCHILDREN, WS_OVERLAPPED, WS_MAXIMIZEBOX, WS_MINIMIZEBOX).

Anyone know why this is happening please?


Solution

  • Works just fine for me on a normal win32 window:

    SetWindowLong(hWnd, GWL_STYLE, WS_CAPTION|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_OVERLAPPED|WS_MAXIMIZEBOX|WS_MINIMIZEBOX);
    SetWindowPos(hWnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_FRAMECHANGED);
    

    The final styles are 0x16C30000 and 0x00000100.

    Adding WS_POPUP often helps when you want to remove the sizing border.

    WS_MAXIMIZEBOX and WS_MINIMIZEBOX will not be visible in the caption without WS_SYSMENU. You can disable the close button by disabling SC_CLOSE in the system menu if that is what you are after...