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

问题描述

限时删除!!

如何检查其他应用程式是否以全萤幕模式运行?最顶层在c ++ MFC?
如果媒体播放器或其他播放器正在运行,我只想禁用所有自动对话框(警告)。 (如Avast中的沉默/玩家模式)
我该怎么办?



谢谢。

 使用EnumWindows,GetWindowInfo和GetWindowRect的组合, bool IsTopMost(HWND hwnd)
{
WINDOWINFO info;
GetWindowInfo(hwnd,& info);
return(info.dwExStyle& WS_EX_TOPMOST)?真假;
}

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; //可以只有一个这样退出
}
return TRUE;
}

bool bThereIsAFullscreenWin = false;
EnumWindows((WNDENUMPROC)CheckMaximized,(LPARAM)& bThereIsAFullscreenWin);

edit2:用测试代码更新,在Windows 7上MediaPlayer的工作正常。我试过GetForeGroundWindow而不是EnumWindows,但是IsFullScreenSize()检查只根据鼠标在媒体播放器的哪个区域工作。



请注意,multimonitor设置的问题在下面的评论仍然在这里。


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?

Thank you.

解决方案

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: 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.

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

1403页,肝出来的..

09-06 18:06