删除外部窗口的完全边框

时间:2017-02-17 22:58:13

标签: c# winapi

我试图使用winapi完全删除外部窗口的所有边框。

现在我使用此代码获得了以下结果:

enter image description here

    public static int GWL_STYLE = -16;
    public static int WS_BORDER = 0x00800000; //window with border
    public static int WS_DLGFRAME = 0x00400000; //window with double border but no title
    public static int WS_CAPTION = WS_BORDER | WS_DLGFRAME; //window with a title bar
    private const int WS_SYSMENU = 0x00080000;      //window with no borders etc.
    private const int WS_MAXIMIZEBOX = 0x00010000;
    private const int WS_MINIMIZEBOX = 0x00020000;  //window with minimizebox

      public static void HideWindowBorders(IntPtr hWnd)
    {
        int style = GetWindowLong(hWnd, GWL_STYLE); //gets current style
        SetWindowLong(hWnd, GWL_STYLE, (style & ~WS_CAPTION)); //removes caption from current style
    }

这将删除标题和最小/最大/关闭按钮(奇怪的是仅在调整窗口大小后)。但是,这不会删除允许调整窗口大小的细边框。

如何删除边框?

2 个答案:

答案 0 :(得分:0)

我认为您可能正在寻找的是WS_POPUP而不是~WS_CAPTION。

也许尝试添加这种风格:

public const uint WS_POPUP = 0x80000000;

然后像这样选择窗口:

SetWindowLong(hWnd, GWL_STYLE, WS_POPUP);

为了进一步解释,WS_POPUP基本上删除了任何大小调整/调整大小,最小/最大化,只留下一个简单的窗口。

答案 1 :(得分:0)

        public const uint WS_SIZEBOX = 0x00040000;

    public static void HideWindowBorders(IntPtr hWnd)
    {
        int style = GetWindowLong(hWnd, GWL_STYLE); //gets current style
        SetWindowLong(hWnd, GWL_STYLE, (uint)(style & ~(WS_CAPTION | WS_SIZEBOX))); //removes caption and the sizebox from current style
    }