如何检查其他程序是否以全屏模式运行

如何检查其他程序是否以全屏模式运行

本文介绍了如何检查其他程序是否以全屏模式运行,例如.媒体播放器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查其他应用程序是否以全屏模式运行&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.

这篇关于如何检查其他程序是否以全屏模式运行,例如.媒体播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 13:27