15,979
社区成员
发帖
与我相关
我的任务
分享
// 如果在半透明窗口上 要弹出另一个窗口,那么这个弹出窗口必须在初始化中置顶
// 即 SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
// 如果这个弹出窗口,不能置顶, 如 AfxMessageBox(),
// 请加上 鼠标穿透属性 WS_EX_TRANSPARENT 。
// 如果要子类化:
//WNDPROC g_OldProc;
//LRESULT CALLBACK NewProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
//{
// return CallWindowProc(g_OldProc, hwnd, message, wParam, lParam);
//}
#define WS_EX_LAYERED 0x00080000
void CzzzzDlg::CreateHalfTransWindow()
{
LPCTSTR m_lpszClassName=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,0,// IDC_ARROW
(HBRUSH)::GetStockObject(BLACK_BRUSH),NULL);
CRect rc;
GetWindowRect(rc);
int x_coord=rc.Width(); //::GetSystemMetrics(SM_CXSCREEN);//幕宽
int y_coord=rc.Height();//::GetSystemMetrics(SM_CYSCREEN);//幕高
// mouse penetrate : WS_EX_TRANSPARENT
m_hwndF=::CreateWindowEx(WS_EX_TOPMOST | WS_EX_LAYERED ,m_lpszClassName,"",
WS_VISIBLE | WS_POPUP ,
rc.left,rc.top,x_coord,y_coord,0,0,NULL,NULL);
// 如果要子类化
// g_OldProc = (WNDPROC)SetWindowLong(m_hwndF, GWL_WNDPROC, (LONG)NewProc);
//
HINSTANCE hInstTmp = LoadLibrary("User32.DLL");
if(hInstTmp)
{
typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
MYFUNC fun = NULL;
// get "SetLayeredWindowAttributes"函数
fun=(MYFUNC)GetProcAddress(hInstTmp, "SetLayeredWindowAttributes");
#define LWA_ALPHA 0x00000002
if(fun) fun(m_hwndF,RGB(0,0,0),30,LWA_ALPHA);//透明度1-30,透明方式2
FreeLibrary(hInstTmp);
}
}
调用
void CzzzzDlg::OnButton3()
{
CreateHalfTransWindow();
CAboutDlg dlgAbout;
dlgAbout.DoModal();
//
DestroyHalfTransWindow();
}
void CzzzzDlg::DestroyHalfTransWindow()
{
if(m_hwndF)
{
::DestroyWindow(m_hwndF);
m_hwndF=0;
}
}
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
//
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
#define WS_EX_LAYERED 0x00080000
void CCheckCursorDlg::cursorHide()
{
LPCTSTR m_lpszClassName=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,::LoadCursorA(NULL,MAKEINTRESOURCE(IDC_CROSS)),
(HBRUSH)::GetStockObject(BLACK_BRUSH),NULL);
CRect rc;
GetWindowRect(rc);
int x_coord=rc.Width();//::GetSystemMetrics(SM_CXSCREEN);//获取屏幕的宽度
int y_coord=rc.Height();//::GetSystemMetrics(SM_CYSCREEN);//获取屏幕的高度
// HWND desk=::GetDesktopWindow();
// mouse penetrate : |WS_EX_TRANSPARENT
m_hwndF=::CreateWindowEx(WS_EX_TOPMOST|WS_EX_LAYERED,m_lpszClassName,"",
WS_VISIBLE | WS_POPUP,
rc.left,rc.top,x_coord,y_coord,0,0,NULL,NULL);
g_OldProc = (WNDPROC)SetWindowLong(m_hwndF, GWL_WNDPROC, (LONG)NewProc);
//
HINSTANCE hInstTmp = LoadLibrary("User32.DLL");
if(hInstTmp)
{
typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
MYFUNC fun = NULL;
//取得SetLayeredWindowAttributes函数指针
fun=(MYFUNC)GetProcAddress(hInstTmp, "SetLayeredWindowAttributes");
#define LWA_ALPHA 0x00000002
if(fun)
fun(m_hwndF,RGB(0,0,0),30,LWA_ALPHA); //透明度1-30,透明方式2
FreeLibrary(hInstTmp);
}
::SendMessage(m_hwndF,WM_CREATE,0,0);// create a button
SetTimer(2,10000,0);
}