Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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));
	m_pBrush->SetColor(m_Color);
}


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++)
        {
            if(m_bShowIndex)
                nIndex = i+1;
            else
                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);
            pQuad->Draw(pDC,m_pTfw);
        }
    }
}


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

Thanks in advance
Ted
Posted

1 solution

Pardon me if you've already done this, but have you initialized GDI+ with a call to GdiplusStartup?
 
Share this answer
 
v2
Comments
tlillys 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()).

Ted

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900