static BOOL IsFullScreenActive()
{
/*
这个函数获取屏幕4角的窗口的进程句柄,判断与激活句柄是否相等的方式来判断是否全屏程序。
特别的,对 IE 之类的多标签多进程程序,子窗口的进程会和主窗口不同。需要获取窗口的主窗口来对比才可以
*/
struct IsNotSameProcessID
{
IsNotSameProcessID( DWORD id ) : processID(id){}
bool operator()( int x, int y )
{
POINT pt={x,y};
HWND xwnd=WindowFromPoint(pt);
HWND desktop=GetDesktopWindow();
HWND parent=0;
for(;;){ // 查找窗口的主窗口
parent=GetParent( xwnd );
if( parent==desktop || parent==0 )
break;
xwnd=parent;
}
DWORD pid=0;
GetWindowThreadProcessId( xwnd, &pid );
return ( pid!=processID );
}
DWORD processID;
};
HWND wnd=::GetForegroundWindow();
DWORD processID;
GetWindowThreadProcessId( wnd, &processID );
/// 获取屏幕大小
int iCx=GetSystemMetrics(SM_CXSCREEN);
int iCy=GetSystemMetrics(SM_CYSCREEN);
IsNotSameProcessID checker( processID );
if( checker(0,0) )
return FALSE;
if( checker(iCx-1,0) )
return FALSE;
if( checker(0,iCy-1) )
return FALSE;
if( checker(iCx-1,iCy-1) )
return FALSE;
return TRUE;
}
}