我有一个相当标准的C++程序,我在其中创建了一个全屏窗口(有两个子窗口(。在装有 Windows 10 的开发计算机上,此窗口会填满整个屏幕并覆盖任务栏。
在Windows 7上,它不覆盖任务栏。经过一些实验,似乎如果我关闭 Aero,程序将覆盖任务栏!
我还创建了一个快速的 C#/WPF 应用程序,无论 Aero 的状态如何,此应用程序都能够覆盖任务栏。
我是否缺少窗口消息或窗口的创建选项?
这是定位和创建窗口的代码
// Get a handle to the primary monitor, which by definition has its top
// left corner at (0, 0).
const POINT ptZero = { 0, 0 };
HMONITOR hmon = MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY);
MONITORINFO mi = { sizeof(mi) };
GetMonitorInfo(hmon, &mi);
// Fill the entire screen
layout->left = mi.rcMonitor.left;
layout->right = mi.rcMonitor.right;
layout->top = mi.rcMonitor.top;
layout->bottom = mi.rcMonitor.bottom;
// Create a full screen window
m_hwnd = CreateWindowEx(
WS_EX_TOPMOST,
className,
windowName,
WS_POPUP | WS_VISIBLE,
layout.left,
layout.top,
layout.right - layout.left,
layout.bottom - layout.top,
NULL,
NULL,
GetModuleHandle(NULL),
this); // LPARAM is used in WM_CREATE to associate the class instance with the Window
下面是处理窗口消息的代码
switch (uMsg)
{
case WM_PAINT:
OnPaint(hwnd); // Draws a black background
return DefWindowProc(hwnd, uMsg, wParam, lParam);
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
更新:经过一些谷歌搜索,我发现这个问题也可能与DPI有关:http://forums.pcsx2.net/Thread-Fullscreen-Windows-7-Taskbar-does-not-auto-hide-w-aerohttps://productforums.google.com/forum/#!topic/chrome/5dMYLChXeWk
目前有效和无效的内容:
Areo + DPI @ 150%:任务栏未覆盖没有 Areo + DPI @ !150%:覆盖任务栏Areo + DPI @ 100%:覆盖任务栏无区域 + DPI @ 100%:覆盖任务栏
这让我很困惑...
在我发现DPI可以发挥作用后,我偶然发现了解决方案。我们需要告诉Windows我们的应用程序是DPI感知的。如果我们不这样做,Windows 将尝试重新缩放应用程序的 UI 元素。我仍然不知道为什么这只在启用 Aero 时会导致问题,但这个解决方法可以解决它:
将一个名为"manifest.xml"(名称无关紧要(的文件添加到项目中,其中包含以下内容:
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
然后在属性页中更改所有配置的以下选项
- 链接器>清单文件
- 生成清单:是
- 清单工具 ->输入和输出
- 其他清单文件:清单.xml
- 嵌入清单:是