How to check if an other program is running in fullscreen mode, eg. a media player(如何检查其他程序是否以全屏模式运行,例如.媒体播放器)
问题描述
如何检查其他应用程序是否以全屏模式运行&c ++ MFC中最顶层?如果媒体播放器或其他播放器正在运行,我只想禁用所有自动对话框(警告).(就像 Avast 中的静音/游戏模式.)我怎么能这样做?
How can I check if an other app is running in full screen mode & topmost in c++ MFC? I just want to disable all of my auto dialogs (warnings) if media player or other players are running. (Like silent/gamer mode in Avast.) How could I do that?
谢谢.
推荐答案
使用 EnumWindows、GetWindowInfo 和 GetWindowRect 的组合可以解决问题.
using a combination of EnumWindows, GetWindowInfo and GetWindowRect does the trick.
bool IsTopMost( HWND hwnd )
{
WINDOWINFO info;
GetWindowInfo( hwnd, &info );
return ( info.dwExStyle & WS_EX_TOPMOST ) ? true : false;
}
bool IsFullScreenSize( HWND hwnd, const int cx, const int cy )
{
RECT r;
::GetWindowRect( hwnd, &r );
return r.right - r.left == cx && r.bottom - r.top == cy;
}
bool IsFullscreenAndMaximized( HWND hwnd )
{
if( IsTopMost( hwnd ) )
{
const int cx = GetSystemMetrics( SM_CXSCREEN );
const int cy = GetSystemMetrics( SM_CYSCREEN );
if( IsFullScreenSize( hwnd, cx, cy ) )
return true;
}
return false;
}
BOOL CALLBACK CheckMaximized( HWND hwnd, LPARAM lParam )
{
if( IsFullscreenAndMaximized( hwnd ) )
{
* (bool*) lParam = true;
return FALSE; //there can be only one so quit here
}
return TRUE;
}
bool bThereIsAFullscreenWin = false;
EnumWindows( (WNDENUMPROC) CheckMaximized, (LPARAM) &bThereIsAFullscreenWin );
edit2:使用经过测试的代码进行了更新,在 Windows 7 上的 MediaPlayer 中运行良好.我尝试使用 GetForeGroundWindow 而不是 EnumWindows,但随后 IsFullScreenSize() 检查仅根据鼠标所在的媒体播放器区域起作用.
edit2: updated with tested code, which works fine here for MediaPlayer on Windows 7. I tried with GetForeGroundWindow instead of the EnumWindows, but then the IsFullScreenSize() check only works depending on which area of media player the mouse is in exactly.
请注意,下面评论中提到的多显示器设置问题仍然存在.
Note that the problem with multimonitor setups mentioned in the comment below is still here.
这篇关于如何检查其他程序是否以全屏模式运行,例如.媒体播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何检查其他程序是否以全屏模式运行,例如.媒体播放器


基础教程推荐
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01