简体   繁体   English

删除窗口边框?

[英]Removing window border?

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 ? 如何使用SetWindowLongGetWindowLong删除边框(所有非客户区域)?

In C/C++ 在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). WS_CAPTION定义为(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。

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

The following Delphi codes does it: 以下Delphi代码执行此操作:

  SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) and not WS_BORDER and not WS_SIZEBOX and not WS_DLGFRAME );
  SetWindowPos(Handle, HWND_TOP, Left, Top, Width, Height, SWP_FRAMECHANGED);

Of course, these API calls look the same in all languages. 当然,这些API调用在所有语言中看起来都是一样的。

This line of code below removes the border of any given window, and remains only its client: 下面这行代码删除了任何给定窗口的边框,并且只保留其客户端:

SetWindowLong(hWnd /*The handle of the window to remove its borders*/, GWL_STYLE, WS_POPUP);

You can use WS_POPUPWINDOW instead in the third parameter of SetWindowLong function. 您可以在SetWindowLong函数的第三个参数中使用WS_POPUPWINDOW It also removes the borders of the given window and works too, but the difference is that it also draws outlined black rectangle all over the remaining client of the window. 它还删除了给定窗口的边框并且也可以工作,但区别在于它还在窗口的其余客户端上绘制了轮廓黑色矩形。 The thickness of that outlined rectangle is 1 pixel. 轮廓矩形的厚度为1像素。 WS_POPUP doesn't draw that rectangle, actually it doesn't draw anything, just only remove window's borders. WS_POPUP不绘制该矩形,实际上它不绘制任何东西,只是删除窗口的边框。

If you are about to return back the borders of the window, before you use that line of code I posted above, call first that line of code below: 如果您要返回窗口的边框,在使用我上面发布的代码行之前,请先调用以下代码行:

GetWindowLong(hWnd /*The handle of the window that you want to remove its borders and later return them back to it*/, GWL_STYLE);

but of course that this function retuns the styles of the window, so create new variable that will keep these styles, ie set this variable to the return value of that function. 但是当然这个函数会返回窗口的样式,所以创建将保留这些样式的新变量,即将此变量设置为该函数的返回值。

Then you use SetWindowLong as I showen above to remove its borders, and when you want later to restore its borders back, just recall again SetWindowLong , the first two parameters are same (hWnd and GWL_STYLE), but the third parameter is the styles of the window that returned from GetWindowLong . 然后你使用上面显示的SetWindowLong来删除它的边框,当你想稍后恢复它的边框时,只需再次调用SetWindowLong ,前两个参数是相同的(hWnd和GWL_STYLE),但第三个参数是从GetWindowLong返回的窗口。 If you don't want to call GetWindowLong , but still return the borders of the window, then you can use SetWindowLong with the same first two parameters, and in the third parameter, you can use one of the following: WS_OVERLAPPED or/and WS_OVERLAPPEDWINDOW or/and WS_SIZEFRAME . 如果您不想调用GetWindowLong ,但仍然返回窗口的边框,那么您可以使用具有相同前两个参数的SetWindowLong ,并且在第三个参数中,您可以使用以下之一: WS_OVERLAPPED或/和WS_OVERLAPPEDWINDOW或/和WS_SIZEFRAME

NOTE: If you try my answer, but it doesn't work for you, this can be, because that the both functions SetWindowLong and GetWindowLong have been superseded and doesn't work for you, and that because they are compatible with only 32-bit version of Windows. 注:如果试试我的答案,但它不为你工作,这样就可以了,因为两者的功能SetWindowLongGetWindowLong已经被取代和不为你工作,这是因为他们32兼容Windows的版本。 Probably you are using 64-bit version of Windows, then use SetWindowLongPtr and GetWindowLongPtr instead, which are compatible with both 32-bit and 64-bit versions of Windows. 也许你正在使用Windows的64位版本,然后使用SetWindowLongPtrGetWindowLongPtr相反,它与Windows的3264位版本兼容。 MSDN informs that about these functions in the Note section. MSDN在Note部分中告知了这些函数。 Just search for them in that site. 只需在该网站中搜索它们即可。 Here are the links to them: 以下是他们的链接:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms633591(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/windows/desktop/ms633584(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/windows/desktop/ms633591(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/windows/desktop/ ms633584(v = vs.85)的.aspx

Hope that all this answers your question. 希望这一切都能回答你的问题。

This removes the title bar, and the vertical scroll bars... 这将删除标题栏和垂直滚动条...

int main()
{
    HWND hwnd = GetConsoleWindow();
    // remove title bar
    LONG lStyle = GetWindowLong(hwnd, GWL_STYLE);
    lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU);
    SetWindowLong(hwnd, GWL_STYLE, lStyle);
    //remove vertical scrollbar
    ShowScrollBar(hwnd, SB_VERT, FALSE);

    cout << "Hello World! \n";
    system("pause");

    return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM