Change Win32 Window Style

Viewed 26218

Is there a win32 function to change the style of a window after it has been created? I would like to change the style flags that are specified in CreateWindowEx. Specifically, I would like to convert a standard window to a window with no border and no resize.

5 Answers

I think SetWindowLongPtr should do that. Note that you need to call SetWindowPos afterwards if you changed the border style, as pointed out in the remarks.

Some styles only take effect during window creation and so can not be set by this call. MSDN normally calls out styles that CAN be set afterwards.

HWND windowHandle = FindWindow(NULL, L"Various tests");
    SetWindowLongPtr(windowHandle, GWL_STYLE, WS_SYSMENU); //3d argument=style
    SetWindowPos(windowHandle, HWND_TOPMOST, 100, 100, Width, Height, SWP_SHOWWINDOW);

did it for me :D

SetWindowLong(hWnd, GWL_STYLE, newStyle); ShowWindow(hWnd, SW_SHOW);

Related