MFC General: How to change frame and caption window styles at run-time?
Q: How to change frame and caption window styles at run-time?
I want to remove at run-time the window caption (title bar). I called GetWindowLong to get the old style, removed the WS_CAPTION flag, then called SetWindowLong to set the new style. But this seems to have no effect. What must be done?
A: After 'SetWindowLong()' to set the new style you must call 'SetWindowPos()' with 'SWP_DRAWFRAME' or 'SWP_FRAMECHANGED' flag set.
When using MFC, an easier way to modify window styles is to call 'CWnd::ModifyStyle()' or 'CWnd::ModifyStyleEx()' respectively.
Unfortunately, the first time programmers use these functions, most of them ignore the last parameter ('nFlags'). The solution is to pass 'SWP_DRAWFRAME' or 'SWP_FRAMECHANGED'.
If 'nFlags' is not zero, 'CWnd::ModifyStyle()'/'CWnd::ModifyStyleEx()' combine it with 'SWP_NOZORDER', 'SWP_NOMOVE', 'SWP_NOSIZE', and 'SWP_NOACTIVATE' flags, then call 'SetWindowPos()'.
The example below, shows/hides the control-menu box from title bar (adds/removes 'WS_SYSMENU' style).
Bookmarks