Click here to Skip to main content
11,805,035 members (66,783 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ GDI GDI+ COM
I'm attempting to extend an unmanaged VC++ 6.0 OCX that uses GDI for displaying images and drawing simple graphical elements - lines, points, and rectangles. I am trying to add translucent polygons on top of these elements. Based on articles found here, I believe I've made the code GDI+ ready.

The brush is established:
void CDQuad::SetColor(COLORREF aColor, int alpha)
	m_Color = Color(alpha, GetRValue(aColor), GetGValue(aColor), GetBValue(aColor));

The following is the only code that attempts to use GDI+ and the status comes back 0:
void CDQuad::Draw(CDC *pDC, CTfw* pTfw)
	Point* points = new Point[5];
	CPoint pCurr;
	Graphics* graphics = new Graphics(pDC->m_hDC);
	if(pTfw != NULL)
		for (int i = 0;i < 5; i++){
			pCurr = pTfw->GeoPointToScreen(m_x[i], m_y[i]);
			points[i].X = pCurr.x;
			points[i].Y = pCurr.y;
		Status astatus = graphics->FillPolygon(m_pBrush,points,5);
	delete graphics;
	delete [] points;
	points = NULL;

This code is called in the following method, surrounded by Draw's that utilize GDI:
void CShape::Draw(CDC* pDC, int nVertOffset)
    if(m_bShow && !m_bNoGeo)
        CLine* pLine = NULL;
        CDQuad* pQuad = NULL;
        int nParts = m_objShapeParts.GetSize();
        //draw shape
        int nIndex;
        for (int i=0; i<nParts;i++)
                nIndex = i+1;
                nIndex = 0;
            pLine = (CLine* )m_objShapeParts.GetAt(i);
            pLine->Draw(pDC,m_nOffsetX,m_nOffsetY, m_dZoomFactor, m_nPanX, m_nPanY, m_pPen, m_pTfw, &m_DxfExtent, m_bShowVertex, nIndex, nVertOffset);
        nParts = m_objQuads.GetSize();
        for (i=0; i<nParts;i++)
            pQuad = (CDQuad* )m_objQuads.GetAt(i);

The CLine object is rendered correctly using GDI, but the FillPolygon doesn't appear. Any thoughts? Any more information required?

Thanks in advance
Posted 4-Nov-10 2:23am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Pardon me if you've already done this, but have you initialized GDI+ with a call to GdiplusStartup?
tlillys at 4-Nov-10 12:55pm
Hi, Nishant

Yes, I believe I have added all the necessary initialization in stdafx.h (included gdiplus.h, afx.h and namespace Gdiplus), the application header (declared instances of GdiplusStartupInput and a ULONG_PTR) and implementation file (called GdiplusStartup in InitInstance() and GdiplusShutdown in ExitInstance()).


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 305
1 Sergey Alexandrovich Kryukov 268
2 CPallini 210
3 Richard Deeming 190
4 CHill60 150
0 OriginalGriff 3,255
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 4 Nov 2010
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100