Reputation: 11
I am writing an APP (c++, win32 ) where I want to create the main window as a) a standard one, or b) without a title bar but resizable/movable and I want to switch between the two styles at run time.
I am using the following code to create the window :
bool bare = false ;
DWORD style_bare = WS_POPUP | WS_SIZEBOX | WS_THICKFRAME ;
DWORD style_std = WS_OVERLAPPEDWINDOW ;
DWORD win_style = bare ? style_bare : style_std ;
DWORD win_exstyle = WS_EX_ACCEPTFILES | WS_EX_CLIENTEDGE | WS_EX_APPWINDOW;
...
HWND main = CreateWindowEx( win_exstyle , className , applName , win_style, x, y, cx, cy, NULL, NULL, hInstance, NULL);
and later, in the MainWndProc(), to change the style
bare = ! bare ;
if ( bare )
SetWindowLongPtr( hwnd , GWL_STYLE, style_bare ) ;
else
SetWindowLongPtr( hwnd , GWL_STYLE, style_std ) ;
InvalidateRect( hwnd, NULL , TRUE ) ;
and while in 'bare' mode I handle the WM_NCHITEST message which makes the bare window movable, as follows:
if ( bare && WM_NCHITTEST == message )
{
LRESULT rc = DefWindowProc( hwnd, message, wParam, lParam ) ;
if ( HTCLIENT == rc ) return HTCAPTION ;
return rc ;
}
The code works fine when I create the window in either mode, but when I switch mode the window is drawn as expected, but is not "selectable"... When I click on it, it moves behind all windows that might be there, and when I close all windows to find my APP and click on it, icons from the desktop are selected.
What I am missing ...
Upvotes: 0
Views: 842
Reputation: 7170
Don't forget to call SetWindowPos
when using SetWindowLongPtr
to change the window frame. Your SetWindowLongPtr
sets a value of window frame at the specified offset in the extra window memory. And the information of frame changing is cached. SetWindowPos
will make it effective.
bare = !bare;
if (bare)
SetWindowLongPtr(hwnd, GWL_STYLE, style_bare);
else
SetWindowLongPtr(hwnd, GWL_STYLE, style_std);
SetWindowPos(hwnd,0,0,0,0,0, SWP_FRAMECHANGED| SWP_NOMOVE| SWP_NOOWNERZORDER| SWP_NOSIZE| SWP_NOZORDER| SWP_SHOWWINDOW);
InvalidateRect(hWnd, NULL, TRUE);
Upvotes: 1