問(wèn)題描述
我正在制作一個(gè)在 Windows 上帶有無(wú)邊框窗口的應(yīng)用程序.但是,由于窗口是無(wú)邊框的,所以我沒(méi)有陰影、捕捉、最小化動(dòng)畫(huà)或抖動(dòng).我環(huán)顧四周,沒(méi)有找到解釋如何實(shí)現(xiàn)這一點(diǎn)的網(wǎng)站.但是,我知道這是可能的,因?yàn)?Office 2013、Visual Studio 2012 和 Steam 都具有這些功能并且是無(wú)邊界的.我專(zhuān)門(mén)使用 QT 和 C++,但如果您已經(jīng)為另一個(gè)窗口庫(kù)解決了這個(gè)問(wèn)題,我也想聽(tīng)聽(tīng)您的解決方案.任何一個(gè).我所說(shuō)的 areo 陰影并不是指兩側(cè)的陰影,我指的是所有活動(dòng)的本機(jī) areo windows 應(yīng)用程序的所有側(cè)面的發(fā)光陰影.
在使用 Spy++ 檢查 Steam 的窗口(它的窗口樣式,它如何回復(fù)窗口消息)并嘗試匹配它所做的一切之后,結(jié)合來(lái)自這個(gè) ,F(xiàn)11切換無(wú)邊框/窗口模式,F(xiàn)12切換無(wú)邊框陰影開(kāi)啟并關(guān)閉.
I am making a application with a borderless window on Windows. However, since the window is borderless, I have no areo shadow, snap, minimization animation, or shake. I have looked around and found no site that explains how to implement this. However, I know it is possible because Office 2013, Visual Studio 2012, and Steam all have these features and are borderless. I am specifically using QT and C++ but if you have solved this for another windowing library I would like to hear your solutions as well. either. And by areo shadow I don't mean drop shadow on two sides, I mean the glowing shadow on all sides of all active native areo windows applications.
After using Spy++ to inspect Steam's window (its window styles, how it replies to window messages) and trying to match everything it does, combined with the DWMAPI calls from this C# borderless window behavior, I believe I figured it out.
To hide the window's border, handle the WM_NCCALCSIZE
message in your WindowProc:
case WM_NCCALCSIZE: {
if (window->is_borderless) {
return 0;
} else {
return DefWindowProc(hwnd, msg, wparam, lparam);
}
}
To enable the shadow, all you need to do is:
MARGINS borderless = {1,1,1,1};
DwmExtendFrameIntoClientArea(hwnd, &borderless);
To turn it back off, restore the default margins MARGINS windowed = {0,0,0,0};
.
Perhaps throw in a SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_ASYNCWINDOWPOS | SWP_NOSIZE | SWP_NOMOVE );
also, to make sure the frame gets redrawn.
However, this does not seem to work with all window styles, apparently your window style must not contain a titlebar. Title bars work fine, and adding one seems to enable the minimize animation.
The simplest window style I got the shadow to work with was WS_POPUP | WS_THICKFRAME
, to also get aero snap, maximizing, minimizing, and the smooth minimize animation I used WS_POPUP | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION
.
Changing DWMWA_NCRENDERING_POLICY
or DWMWA_ALLOW_NCPAINT
via DwmSetWindowAttribute
does not appear to be required, the default settings seem to work.
One word of caution: DwmExtendFrameIntoClientArea
does exactly what the name suggests, so if you are drawing an image with an alpha channel directly into your client area (say with opengl, direct3d/2d), a small frame will be visible through it:
So you might have to put a non transparent widget, brush or something behind the transparent element.
If all goes well, it should then look like this:
Here is a small example project, F11 toggles borderless/windowed mode, F12 toggles the borderless shadow on and off.
這篇關(guān)于使用 Areo Snap、陰影、最小化動(dòng)畫(huà)和抖動(dòng)的無(wú)邊框窗口的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!