Basically, you store the Style and ExStyle of the window via GetWindowsLong(hWnd, GWL_STYLE) and GetWindowsLong(hWnd, GWL_EXSTYLE). You use that to revert to bordered window. To go borderless, you remove remove a few styles and then set GWL_(EX)STLYE to the stored style long, without the border style flags.
Example:
const LONG BORDER_STYLE = (WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
const LONG BORDER_EXSTYLE = (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
LONG g_defaultStyle;
LONG g_defaultExStyle;
HWND g_hWnd; // guessing you already have the hWnd, so I won't set it in the example
void RefreshWindow() {
// could alternatively set the position here instead of just update the frame
// since setting the position will also update the frame
SetWindowPos(g_hWnd, NULL, 0, 0, 0, 0, ONLY_FRAME_CHANGED);
}
void StoreStyles() {
g_defaultStyle = GetWindowLong(g_hWnd, GWL_STYLE);
g_defaultExStyle = GetWindowLong(g_hWnd, GWL_EXSTYLE);
}
void DecorateWindow() {
SetWindowLong(g_hWnd, GWL_STYLE, g_defaultStyle & ~BORDER_STYLE);
SetWindowLong(g_hWnd, GWL_EXSTYLE, g_defaultExStyle & ~BORDER_EXSTYLE);
RefreshWindow(); // necessary for the change to actually happen
}
void UndecorateWindow() {
SetWindowLong(g_hWnd, GWL_STYLE, g_defaultStyle);
SetWindowLong(g_hWnd, GWL_EXSTYLE, g_defaultExStyle);
RefreshWindow(); // necessary for the change to actually happen
}