Click here to Skip to main content
Rate this: bad
good
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));
	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 4-Nov-10 3:23am
tlillys216

1 solution

Rate this: bad
good
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?
  Permalink  
v2
Comments
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()).
 
Ted

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

  Print Answers RSS
0 OriginalGriff 499
1 Maciej Los 325
2 Sergey Alexandrovich Kryukov 234
3 DamithSL 233
4 Mathew Soji 195
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 4 Nov 2010
Copyright © CodeProject, 1999-2014
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