Removing window border?

前端 未结 4 928
孤街浪徒
孤街浪徒 2020-11-29 19:32

I have a window with a solid border around it. How can I remove the border (all of the non-client area) by using SetWindowLong and GetWindowLong

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 20:14

    In C/C++

    LONG lStyle = GetWindowLong(hwnd, GWL_STYLE);
    lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU);
    SetWindowLong(hwnd, GWL_STYLE, lStyle);
    

    WS_CAPTION is defined as (WS_BORDER | WS_DLGFRAME). You can get away with removing just these two styles, since the minimize maximize and sytem menu will disappear when the caption disappears, but it's best to remove them as well.

    It's also best to remove the extended border styles.

    LONG lExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
    lExStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
    SetWindowLong(hwnd, GWL_EXSTYLE, lExStyle);
    

    And finally, to get your window to redraw with the changed styles, you can use SetWindowPos.

    SetWindowPos(hwnd, NULL, 0,0,0,0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
    

提交回复
热议问题