Creating window frame without maximize button and without resizing options?

做~自己de王妃 提交于 2019-12-04 18:17:49

Creating a window as below will give you a non-sizeable window with a title bar, a minimize button and an exit button.

dwStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX;
hWnd = CreateWindow(szAppName, szTitle, dwStyle,
    CW_USEDEFAULT, 0,  CW_USEDEFAULT, 0,
    NULL, NULL, hInstance, NULL);

See http://msdn.microsoft.com/en-us/library/windows/desktop/ms632679%28v=vs.85%29.aspx

and http://msdn.microsoft.com/en-us/library/windows/desktop/ms632600%28v=vs.85%29.aspx

I suppose you are creating the window using CreateWindowEx. Then, if you omit both WS_MAXIMIZEBOX and WS_MINIMIZEBOX flags (the dwStyle parameter), the window will have only the close button (no minimize/maximize) buttons. If you ommit just WS_MAXIMIZEBOX, Windows draw the maximize box disabled to keep the graphics layout consistent for all windows. There is no way to change this behavior, and it can change in different versions of Windows (Win3.1, for instance, didn't draw the maximize button at all when the flags were set as mentioned.)

Resizable border is disabled by setting other frame than WS_THICKFRAME (ie. WS_BORDER or WS_EX_DLGMODALFRAME in the dwExStyle parameter).

You can also control the user sizing/moving of your window by intercepting messages WM_WINDOWPOSCHANGING, WM_WINDOWPOSCHANGED, WM_ENTERSIZEMOVE, WM_EXITSIZEMOVE, WM_SIZING and WM_MOVING.

In theory, you can also completly change the appearance of the non-client area of the window, but it's hardly worth the effort, and it's questionable whether it's a good idea to fight with the default graphic layout of the operating system when all the developers and user are used to it and content with it. (In other words: if you don't want your window to be maximized, just omit the WS_MAXIMIZEBOX flag and leave it on the operating system how to realize this particular decision.)

I'm pretty sure it is documented on MSDN that the window style you want to OMIT is WS_THICKFRAME, since the Window Styles page says that a thick frame is a sizing frame.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!