windows 使用 WinAPI 进行全屏管理

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3549148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:05:34  来源:igfitidea点击:

Fullscreen management with WinAPI

windowswinapifullscreen

提问by Xavier V.

How to well use the WinAPI to manage the fullscreen mode on windows's window ?

如何很好地使用 WinAPI 来管理 windows 窗口的全屏模式?

Here is my problem :

这是我的问题:

I have an application which has to be fullscreen. I use ChangeDisplaySettings() function (winuser.h) with the CDS_FULLSCREEN value to put my window to fullscreen mode when receiving a WM_ACTIVATEwith (wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE):

我有一个必须是全屏的应用程序。我使用 ChangeDisplaySettings() 函数 (winuser.h) 和 CDS_FULLSCREEN 值在收到WM_ACTIVATEwith时将我的窗口置于全屏模式(wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE)

DEVMODE dmScreenSettings;
memset (&dmScreenSettings, 0, sizeof (dmScreenSettings));
dmScreenSettings.dmSize = sizeof (dmScreenSettings);   
dmScreenSettings.dmPelsWidth = 1280;
dmScreenSettings.dmPelsHeight = 720;    
dmScreenSettings.dmBitsPerPel = 32;      
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);

I use the same function with the CDS_RESET value to put it back in "normal" mode when receiving a WM_ACTIVATEwith (wParam == WA_INACTIVE):

我使用与 CDS_RESET 值相同的函数在收到WM_ACTIVATEwith时将其恢复为“正常”模式(wParam == WA_INACTIVE)

ChangeDisplaySettings(&dmScreenSettings, CDS_RESET);

When I first launch my application, it is in fullscreen. I use ALT+TAB to switch to another application on my computer. My application minimized itself. It works well. Then, I switch back to my application, and it comes up in fullscreen mode. Again, it works well. But if I want to switch back to another application one more time, my application statys in fullscreen mode, hiding all others applications on my computer.

当我第一次启动我的应用程序时,它是全屏的。我使用 ALT+TAB 切换到我计算机上的另一个应用程序。我的应用程序将自身最小化。它运作良好。然后,我切换回我的应用程序,它以全屏模式出现。再次,它运作良好。但是如果我想再次切换回另一个应用程序,我的应用程序将处于全屏模式,隐藏我计算机上的所有其他应用程序。

NB : My window is created using CreateWindowEx() function with the following parameters :

注意:我的窗口是使用 CreateWindowEx() 函数创建的,参数如下:

DWORD dwExStyle = WS_EX_TOPMOST;
DWORD dwStyle = WS_VISIBLE | WS_POPUP;

1) Is there another way than using ChangeDisplaySettings() to change the fullscreen mode ?

1) 除了使用 ChangeDisplaySettings() 更改全屏模式之外,还有其他方法吗?

2) Am I using it the good values ?

2)我使用它的好价值吗?

3) Is there anything to do that I forgot ?

3) 有什么事情我忘记了吗?

Thanks in advance for all your answers. Best regards,

预先感谢您的所有回答。此致,

回答by JustBoo

These guys seemto cover all the options.

这些家伙似乎涵盖了所有选项。

Win32: full-screen and hiding taskbar

Win32:全屏和隐藏任务栏



New Edit:Based on a new comment, try this.

新编辑:根据新评论,试试这个。

Trap the WM_ACTIVATEevent in you app for that window. In that event call the GetWindowPlacement Functionand hopefully you'll be on your way. Note the link to "SetWindowPlacement" at the bottom.

在您的应用程序中为该窗口捕获WM_ACTIVATE事件。在这种情况下,调用GetWindowPlacement 函数,希望您能顺利完成。请注意底部的“SetWindowPlacement”链接。

回答by Adrian McCarthy

Try it without WS_EX_TOPMOST.

没有WS_EX_TOPMOST.

Whenever you're activated, you'll become the foreground window automatically.

每当您被激活时,您将自动成为前台窗口。

回答by Chris Becke

  • If you are a Kiosk application, then the screen is already configured to the ideal / correct resolution.

  • If you are not a Kiosk application, then you have no business f*****g with the users resolution. Instead: GetSystemMetrics to get the size of the default display, and create your borderless window exactly that large. The taskbar will automatically hide and your app will be "full screen".

  • 如果您是 Kiosk 应用程序,则屏幕已配置为理想/正确的分辨率。

  • 如果您不是 Kiosk 应用程序,那么您与用户分辨率无关。取而代之的是:GetSystemMetrics 获取默认显示的大小,并创建完全一样大的无边框窗口。任务栏将自动隐藏,您的应用程序将“全屏”显示。

Especially now that LCD panels are popular, the display resolution must match the panel resolution in order for sub pixel anti aliasing to work - ala ClearType. It is your applications responsibility to draw correctly at the display resolution, not the other way around.

尤其是现在 LCD 面板很流行,显示分辨率必须与面板分辨率匹配才能使亚像素抗锯齿工作 - ala ClearType。您的应用程序有责任以显示分辨率正确绘制,而不是相反。