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 hInstif ((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 = NULLpFnSetTransparent= (lpfnSetTransparent)GetProcAddress(hInst, "SetLayeredWindowAttributes")if (pFnSetTransparent)pFnSetTransparent(m_hWnd, 0, (255 * nRate) / 100, LWA_ALPHA)}
}
}
在其父窗口中响应OnCtlColor然后添加如下代码
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor)
if (nCtlColor==CTLCOLOR_STATIC)
{
pDC->SetTextColor(RGB(255,0,0))//字体颜色
pDC->SetBkMode(TRANSPARENT)// 背景透明
}
return hbr
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)