Hi Andy,
I have tried what you said, but not having any success. I can't figure
out how to get the .NET control to actually do the drawing onto the MFC
DC. I thought that if I got the window handle (.net window) and its
associated DC then that would suffice. I had thought that if I had the
actual device context of the .NET control then it should already have
rendered it's content to the DC, but apparently this is not the case.
Perhaps you might be able to spot the problem in the code below
Thanks in advance,
Martin
m_ContainedControl->Visible = true;
IWin32Window^ win32Win =
cli::safe_cast<IWin32Window^>(m_ContainedControl.GetControl());
System::IntPtr ptr = win32Win->Handle;
HWND hwnd = (HWND)ptr.ToPointer();
CWnd* pWnd = CWnd::FromHandle(hwnd);
ASSERT(pWnd);
CClientDC netCtrlDC(pWnd); // This will automatically GetDC and
ReleaseDC
// After creating and configuring the memDC
CRect boundingBox(0,0,0,0);
netCtrlDC.GetClipBox(&boundingBox);
CDC memDC;
CBitmap memBitmap;
memDC.CreateCompatibleDC(&netCtrlDC);
netCtrlDC.LPtoDP(&boundingBox);
memBitmap.CreateCompatibleBitmap(&netCtrlDC, boundingBox.Width(),
boundingBox.Height());
AutoSelector selectBitmap(&memDC, &memBitmap);
memDC.SetMapMode(netCtrlDC.GetMapMode());
memDC.SetWindowExt(netCtrlDC.GetWindowExt());
memDC.SetViewportExt(netCtrlDC.GetViewportExt());
netCtrlDC.DPtoLP(&boundingBox);
memDC.SetWindowOrg(boundingBox.left, boundingBox.top);
memDC.FillSolidRect(boundingBox, netCtrlDC.GetBkColor());
// Blit the contents of the .NetCtrl to the memDC
memDC.BitBlt(boundingBox.left,
boundingBox.top,
boundingBox.Width(),
boundingBox.Height(),
&netCtrlDC,
boundingBox.left,
boundingBox.top,
SRCCOPY);
// Debugging Crap Just Draw an X
AutoSelector selectPen(&memDC, BLACK_PEN); // Automatically Deslect
on exit
memDC.MoveTo(boundingBox.TopLeft());
memDC.LineTo(boundingBox.BottomRight());
memDC.MoveTo(boundingBox.right, boundingBox.top);
memDC.LineTo(boundingBox.left, boundingBox.bottom);
// End Debugging Crap
m_ContainedControl->Visible = false;
// Blit the contents of the MemDC to the real DC
CRect thisBoundingBox = GetBaseRgn().GetBounds();
pDC->BitBlt(thisBoundingBox.left,
thisBoundingBox.top,
thisBoundingBox.Width(),
thisBoundingBox.Height(),
&memDC,
boundingBox.left,
boundingBox.top,
SRCCOPY);