MFC 将子窗口设置成透明的主窗口也跟着透明了? 50
在线求大神帮我解决这个问题,我在字节新创建的类中设置了半透明属性,然后想将该对话框黏贴在主对话框上面,但是反而主对话框变成透明的,我设置了的对话框却不是透明的,搞不懂为什...
在线求大神帮我解决这个问题,我在字节新创建的类中设置了半透明属性,然后想将该对话框黏贴在主对话框上面,但是反而主对话框变成透明的,我设置了的对话框却不是透明的,搞不懂为什么。。求大神帮忙
以下是设置对话框透明的代码
BOOL CMyTestW::OnInitDialog()
{
CDialog::OnInitDialog();
COLORREF color=RGB(0, 0, 0);
HWND hwnd = AfxGetApp()->GetMainWnd()->GetSafeHwnd(); //主窗口的句柄
SetTransparentWnd(hwnd,color,200,LWA_ALPHA);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void CMyTestW::SetTransparentWnd(HWND hWnd, COLORREF clr , BYTE byAlpha, DWORD dwFlags)
{
typedef BOOL (FAR PASCAL *Fun)(HWND,COLORREF,BYTE,DWORD);
Fun SetTransparentFun;
HMODULE hModule=LoadLibrary(_T("User32.DLL"));
if(hModule)
{
SetTransparentFun=(Fun)GetProcAddress(hModule,"SetLayeredWindowAttributes");
if(SetTransparentFun&&hWnd)
{
SetWindowLong(hWnd,GWL_EXSTYLE,GetWindowLong(hWnd,GWL_EXSTYLE)|0x80000L);
SetTransparentFun(hWnd,clr,byAlpha,dwFlags);
}
FreeLibrary(hModule);
}
}
以下是将该透明对话框贴到主框架上的代码
mmychildlg 是透明窗口的类指针
pStatic->SetBitmap(hBmp1);
pStatic->ShowWindow(SW_SHOWNA);
CRect rcClient;
GetClientRect(&rcClient);
m_rcmychildlg = CRect(rcClient.left+172+20,
rcClient.top + 31,
rcClient.right - 152,
rcClient.bottom - 152);
m_mychildlg = new CMyTestW();
m_mychildlg->Create(CMyTestW::IDD, this);
m_mychildlg->SetWindowPos(NULL,
m_rcmychildlg.left,
m_rcmychildlg.top,
m_rcmychildlg.Width(),
m_rcmychildlg.Height(),
SWP_SHOWWINDOW); 展开
以下是设置对话框透明的代码
BOOL CMyTestW::OnInitDialog()
{
CDialog::OnInitDialog();
COLORREF color=RGB(0, 0, 0);
HWND hwnd = AfxGetApp()->GetMainWnd()->GetSafeHwnd(); //主窗口的句柄
SetTransparentWnd(hwnd,color,200,LWA_ALPHA);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void CMyTestW::SetTransparentWnd(HWND hWnd, COLORREF clr , BYTE byAlpha, DWORD dwFlags)
{
typedef BOOL (FAR PASCAL *Fun)(HWND,COLORREF,BYTE,DWORD);
Fun SetTransparentFun;
HMODULE hModule=LoadLibrary(_T("User32.DLL"));
if(hModule)
{
SetTransparentFun=(Fun)GetProcAddress(hModule,"SetLayeredWindowAttributes");
if(SetTransparentFun&&hWnd)
{
SetWindowLong(hWnd,GWL_EXSTYLE,GetWindowLong(hWnd,GWL_EXSTYLE)|0x80000L);
SetTransparentFun(hWnd,clr,byAlpha,dwFlags);
}
FreeLibrary(hModule);
}
}
以下是将该透明对话框贴到主框架上的代码
mmychildlg 是透明窗口的类指针
pStatic->SetBitmap(hBmp1);
pStatic->ShowWindow(SW_SHOWNA);
CRect rcClient;
GetClientRect(&rcClient);
m_rcmychildlg = CRect(rcClient.left+172+20,
rcClient.top + 31,
rcClient.right - 152,
rcClient.bottom - 152);
m_mychildlg = new CMyTestW();
m_mychildlg->Create(CMyTestW::IDD, this);
m_mychildlg->SetWindowPos(NULL,
m_rcmychildlg.left,
m_rcmychildlg.top,
m_rcmychildlg.Width(),
m_rcmychildlg.Height(),
SWP_SHOWWINDOW); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询