这是我遇到的问题。我派生了CPaneDialog类
class cdroView : public CPaneDialog
{
DeclARE_DYNAMIC(cdroView)
public:
cdroView();
virtual ~cdroView();
protected:
DeclARE_MESSAGE_MAP()
public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
};
我希望此对话框的背景透明,并显示其背后的内容。我可以使用以下代码完成此操作:
int cdroView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CPaneDialog::OnCreate(lpCreateStruct) == -1)
return -1;
SetWindowLong(m_hWnd,GWL_EXSTYLE,GetWindowLong(m_hWnd,GWL_EXSTYLE) ^ WS_EX_LAYERED);
SetLayeredwindowAttributes(RGB(255,255),LWA_COLORKEY);
// TODO: Add your specialized creation code here
return 0;
}
BOOL cdroView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CRect clientRect ;
getclientRect(&clientRect) ;
pDC->FillSolidRect(clientRect,RGB(255,255)) ; // paint background in magenta
return FALSE;
}
这是在 Popup 模式下对话框的外观: TransParent Dialog
问题在于,一旦我尝试移动/调整大小/停靠此对话框,程序就会崩溃,并且我收到此错误消息: “在3DNavigator.exe中,在0x51e8b340(mfc100d.dll)处未处理的异常:0xC0000005:访问冲突读取位置0x00000000。”
该错误在afxpane.cpp文件内部的CPane :: FloatPane(CRect rectFloat,AFX_DOCK_METHOD dockMethod,bool bShow)方法内部显示在该行上:
if (bShow)
{
GetParentMiniFrame()->AdjustLayout();
}
Error Message when trying to move the Dialog
现在这是奇怪的地方。如果我将对话框样式更改为 Child 而不是 Popup ,则如图所示:Child Style我现在可以自由移动,调整大小甚至停靠此对话框而不会崩溃,但...透明度不再起作用,对话框如下所示:Child Dialog
因此,我需要解决允许以 Popup 模式移动/调整对话框大小/停靠对话框的问题,或者使Dialog Transparency代码在 Child 下工作时可以工作模式。为什么存在这些问题的任何想法?谢谢