得到屏幕大小,把窗口设置为全屛
int m_xScreen = GetSystemMetrics(SM_CXSCREEN);
int m_yScreen = GetSystemMetrics(SM_CYSCREEN);
SetWindowLong(GetSafeHwnd(),GWL_EXSTYLE,WS_EX_TOOLWINDOW);SetLayeredWindow(m_hWnd,80);SetWindowPos(&CWnd::wndTopMost,0,0,m_xScreen,m_yScreen,SWP_SHOWWINDOW);SetForegroundWindow();
实现透明函数
void SetLayeredWindow(HWND m_hWnd,int nRate)
{HINSTANCE hInst;if ((hInst = LoadLibrary(_T("USER32.dll"))) != NULL)
{
SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);typedef BOOL (WINAPI* lpfnSetTransparent)(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);if (hInst){lpfnSetTransparent pFnSetTransparent = NULL;pFnSetTransparent= (lpfnSetTransparent)GetProcAddress(hInst, "SetLayeredWindowAttributes");if (pFnSetTransparent)pFnSetTransparent(m_hWnd, 0, (255 * nRate) / 100, LWA_ALPHA);}
}
}