在windows下判断当前系统是否处于全屏独占的模式下,通过这个能够获知用户是否在玩游戏,看电影等等。
以下采用的办法是通过判断屏幕的四角是否属于同一个窗口句柄。
//检查当前是否有程序处于全屏独占模式
bool IsFullScreen()
{
//声明4个句柄,用于获取屏幕角落的的四个点
HWND pWnd1 = NULL;
HWND pWnd2 = NULL;
HWND pWnd3 = NULL;
HWND pWnd4 = NULL;
//获取当前屏幕分辨率 Width
int iCx=GetSystemMetrics(SM_CXSCREEN);
//获取当前屏幕分辨率 Height
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;
}
bool IsFullScreen()
{
//声明4个句柄,用于获取屏幕角落的的四个点
HWND pWnd1 = NULL;
HWND pWnd2 = NULL;
HWND pWnd3 = NULL;
HWND pWnd4 = NULL;
//获取当前屏幕分辨率 Width
int iCx=GetSystemMetrics(SM_CXSCREEN);
//获取当前屏幕分辨率 Height
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;
}
另外MSDN给出了一个官方的解决办法,暂时还没有测试。
shellapi.h
ABN_FULLSCREENAPP Notification
Notifies an appbar when a full-screen application is opening or closing. This notification is sent in the form of an application-defined message that is set by the
ABM_NEW
message.
Syntax
ABN_FULLSCREENAPP fOpen = (BOOL) lParam;
Parameters
- fOpen
- A flag specifying whether a full-screen application is opening or closing. This parameter is TRUE if the application is opening or FALSE if it is closing.
Return Value
No return value.
Remarks
When a full-screen application is opening, an appbar must drop to the bottom of the z-order. When it is closing, the appbar should restore its z-order position.
Notification Requirements
Minimum DLL Version None Custom Implementation No Header shellapi.h Minimum operating systems Windows NT 3.51, Windows 95
本文转自阿汐 51CTO博客,原文链接:http://blog.51cto.com/axiii/152102,如需转载请自行联系原作者