Windows下经常会遇到这样一个问题,检测是否有应用程序处于全屏状态,如果有,则需要做一些特别动作。
笔者尝试过不同的方法,
方法一,检测四个角点的hWnd,看他们是否是同一个window,通常对于播放器这种应用程序处于全屏时,会带有一个进度控制条,导致了四个角点属于两个不同的window。
方法二,注册Desktop Toolbars,当有全屏幕程序打开或者关闭的时候都会有ABN_FULLSCREENAPP消息通知,在收到后作处理即可。
下面分别列举这两种方法:
方法一:
bool IsFullScreen() { HWND pWnd1 = NULL; HWND pWnd2 = NULL; HWND pWnd3 = NULL; HWND pWnd4 = NULL; int iCx=GetSystemMetrics(SM_CXSCREEN); int iCy=GetSystemMetrics(SM_CYSCREEN); POINT pt1; pt1.x = 1; pt1.y = 1; POINT pt2; pt2.x = 1; pt2.y = iCy-1; POINT pt3; pt3.x = iCx-1; pt3.y = 1; POINT pt4; pt4.x = iCx-1; pt4.y = iCy-1; pWnd1 = WindowFromPoint(pt1); pWnd2 = WindowFromPoint(pt2); pWnd3 = WindowFromPoint(pt3); pWnd4 = WindowFromPoint(pt4); if (pWnd1 == pWnd2 && pWnd2 == pWnd3 && pWnd3 == pWnd4) { return true; } return false; }
事实上,除了IE的full screen,上述方法都没有试成功过。
方法二:
//以dialog为例 xdlg.h class cxdlg { // ... APPBARDATA m_abd; // ... }; xdlg.cpp
#define UM_APPBARID WM_USER+1 BEGIN_MESSAGE_MAP(cxdlg, CDialogEx) // ... ON_WM_POWERBROADCAST() // ... END_MESSAGE_MAP() BOOL cxdlg::OnInitDialog() { // ... memset(&m_abd, 0, sizeof(APPBARDATA)); m_abd.cbSize = sizeof(APPBARDATA); m_abd.hWnd = this->m_hWnd; m_abd.uCallbackMessage = UM_APPBARID; ::SHAppBarMessage(ABM_NEW, &m_abd); // ... }LRESULT cxdlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { // TODO: Add your specialized code here and/or call the base class if (UM_APPBARID == message) { TRACE(TEXT("==><== Get UM_APPBARID ... /n")); switch((UINT)wParam) { case ABN_FULLSCREENAPP: { if (TRUE == (BOOL)lParam) { TRACE(TEXT("GetFullScreen On/n")); } else { TRACE(TEXT("GetFullScreen Off/n")); } } break; default: break; } }
return CDialogEx::WindowProc(message, wParam, lParam); }