Print Page | Close Window

How to draw Markup with CMetaFileDC?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=11337
Printed Date: 08 November 2025 at 1:29am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to draw Markup with CMetaFileDC?
Posted By: WindFlashing
Subject: How to draw Markup with CMetaFileDC?
Date Posted: 08 July 2008 at 4:25am

I want to draw Markup with CMetaFileDC in CDocObjectServerItem::OnDraw(CDC* pDC, CSize& rSize), but it fails to render.

BOOL CMySrvrItem::OnDraw(CDC* pDC, CSize& rSize)
{
 if (!pDC)
  return FALSE;
 // Remove this if you use rSize
 UNREFERENCED_PARAMETER(rSize);
 // TODO: set mapping mode and extent
 //  (The extent is usually the same as the size returned from OnGetExtent)
 pDC->SetMapMode(MM_ANISOTROPIC);
 pDC->SetWindowOrg(0,0);
 pDC->SetWindowExt(3000, 3000);
 // TODO: add drawing code here.  Optionally, fill in the HIMETRIC extent.
 //  All drawing takes place in the metafile device context (pDC).
 if (m_pUIElement)
 {
  CXTPMarkupDrawingContext dc(pDC->m_hDC);
  CRect rc(0, 0, 3000, 3000);
  m_pUIElement->Measure(&dc, rc.Size());
  m_pUIElement->Arrange(rc);
  m_pUIElement->Render(&dc);
 }
 return TRUE;
}
 
Please help me.



Replies:
Posted By: Oleg
Date Posted: 08 July 2008 at 6:21am
Hi,
 
You can Render it to Buffer DC and then stretch to pDC:
 
 
BOOL CDocSrvrItem::OnDraw(CDC* pDC, CSize& rSize)
{
 // Remove this if you use rSize
 UNREFERENCED_PARAMETER(rSize);
 CDocDoc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);
 // TODO: set mapping mode and extent
 //  (The extent is usually the same as the size returned from OnGetExtent)
 pDC->SetMapMode(MM_TEXT);
 pDC->SetWindowOrg(0,0);
 pDC->SetWindowExt(3000, 3000);
 
 CXTPMarkupContext* pContext = XTPMarkupCreateContext(0);
 
 CXTPMarkupUIElement* pElement = XTPMarkupParseText(pContext, _T("<Ellipse Stroke='Yellow' StrokeThickness='3' Fill='Blue' Width='100' Height='100'/>"));
 
 XTPMarkupMeasureElement(pElement, 100, 100);
 
 CWindowDC dcWindow(0);
 CDC dc;
 dc.CreateCompatibleDC(&dcWindow);
 
 CBitmap bmp;
 bmp.CreateCompatibleBitmap(&dcWindow, 100, 100);
 
 CBitmap* pOldBitmap = dc.SelectObject(&bmp);
 
 dc.FillSolidRect(0, 0, 100, 100, 0xFF);
 
 if (pElement)
 {
  XTPMarkupRenderElement(pElement, dc, CRect(0, 0, 100, 100));
  
  XTPMarkupReleaseElement(pElement);
 }
 
 pDC->StretchBlt(0, 0, 100, 100, &dc, 0, 0, 100, 100, SRCCOPY);
 
 
 dc.SelectObject(pOldBitmap);
 XTPMarkupReleaseContext(pContext);

 return TRUE;
}


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: WindFlashing
Date Posted: 08 July 2008 at 7:11am

Hi oleg,

   it works great!
 
   thanks!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net