I'm having trouble making a CDockablePane/CDialog/CPaneDialog Transparent


here is the issue im having. i have derived a CPaneDialog Class

class CDroView : public CPaneDialog

    virtual ~CDroView();


    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);

I want the background of this dialog to be transparent and show what is behind it. I am able to accomplish this using the following code:

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,0,255),0, 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,0,255)) ;  // paint background in magenta

     return FALSE;


this is what the Dialog Looks like when in Popup mode: TransParent Dialog

The Problem is that as soon as I try to Move/resize/dock this dialog, the program crashes, and i get this error message: "Unhandled exception at 0x51e8b340 (mfc100d.dll) in 3DNavigator.exe: 0xC0000005: Access violation reading location 0x00000000."

the error shows up on this line, inside the CPane::FloatPane(CRect rectFloat, AFX_DOCK_METHOD dockMethod, bool bShow) method, inside the afxpane.cpp file:

if (bShow)

Error Message when trying to move the Dialog

Now here's where it gets weird. if i change the Dialog Style to Child instead of Popup, pictured here:Child StyleI can now freely move, resize, and even dock this dialog without any crashing, BUT... the transparency no longer works, and the Dialog looks like this: Child Dialog

So i need to either solve the problem of allowing the Dialog to be moved/resized/docked in Popup mode, OR making the Dialog Transparency code work while in Child mode. any ideas to why either of these problems exist? thanks

asked on Stack Overflow Jan 22, 2020 by NatB

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0