Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
kenberkun  
#1 Posted : Sunday, June 12, 2005 4:44:00 PM(UTC)
kenberkun

Rank: Member

Groups: Member
Joined: 1/5/2005(UTC)
Posts: 20

I am trying to draw a rubberband selection box in C++. I took the example code you posted for the de-warping routine and converted it to C++. The problem is that the iembeddedgraphics interface doesn't provide access to the HDC, so there is no doublebuffering and it writes directly onto the bitmap, not onto the viewer. Furthermore, I can't figure out how to change pen colors/sizes, etc.

Here is my code for the doublebuffer event. Clearly I need to be doing something different, as this leaves lines all over the bitmap. Note the comments in Capitals.

Thanks,
Ken

Code:
void CDeWarp::DoubleBufferPaintDewarppreviewer(long Hdc)
{
	VARIANT_BOOL bLoaded;
	m_piUnchangedPreview->get_IsLoaded(&bLoaded);
    if(bLoaded)  // there is something in the viewer
	{

        //Attach Graphics to the temporary DC (control's double buffer)
		// HOW TO DO THIS IN C++?
		//objGraphics.Hdc = Hdc 
        //Adjust pen and brush // HOW TO DO THIS IN C++?
		//objGraphics.Pen.ForeColor = &HFFFF0000
		//Scale pen weight proportionally to zoom
		//objGraphics.Pen.Weight = 2

        //Recalculate anchor points from bitmap coordinates to the control ones
		long i;
        long arrControlPointX[4], arrControlPointY[4];
        for (i=0;i<4 ;i++ )
		{
			piPreviewBox->BitmapToControlXCoord(arrSrcPointX[i],&arrControlPointX[i]);
			piPreviewBox->BitmapToControlXCoord(arrSrcPointY[i],&arrControlPointY[i]);
		}


        //Draw fitting quadrangle - LEAVES LINES ALL OVER THE BITMAP
		m_piPreviewGraphics->DrawLine(arrControlPointX[0], arrControlPointY[0],
            arrControlPointX[1], arrControlPointY[1]);

        m_piPreviewGraphics->DrawLine(arrControlPointX[1], arrControlPointY[1],
		arrControlPointX[2], arrControlPointY[2]);

        m_piPreviewGraphics->DrawLine(arrControlPointX[2], arrControlPointY[2],
            arrControlPointX[3], arrControlPointY[3]);

        m_piPreviewGraphics->DrawLine(arrControlPointX[3], arrControlPointY[3],
            arrControlPointX[0], arrControlPointY[0]);

        //Draw anchor points
       for(i=0; i<4; i++) 
		m_piPreviewGraphics->DrawRectangle(arrControlPointX[i] - 3, arrControlPointY[i] - 3, 7, 7, FALSE, TRUE,0);
	} //end .isloaded
	piPreviewBox->put_AutoUpdate(FALSE);
}

Edited by user Sunday, December 23, 2007 5:59:11 PM(UTC)  | Reason: Not specified

Andrew  
#2 Posted : Monday, June 13, 2005 2:08:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 863

Thanks: 2 times
Was thanked: 25 time(s) in 25 post(s)
1. You can create Graphics object instead of using IEmbeddedGraphics interface (which is always accosiated with a bitmap). It exposes IGraphics interface which supports get_Hdc/put_Hdc property.

2. To get access to Pen and Brush settings in C++, you need to get IPen and IBrush interface and then modify properties, something like this (error handling is omitted for brevity):

Code:
CComPtr<IGraphics> piGraphics;
piGraphics.CoCreateInstance(CLSID_Graphics);

CComPtr<IPen> piPen;
piGraphics->get_Pen(&piPen);

piPen->put_ForeColor(0xFFFF0000);
...


Hope this helps.

Edited by user Sunday, December 23, 2007 5:59:23 PM(UTC)  | Reason: Not specified

kenberkun  
#3 Posted : Tuesday, June 14, 2005 3:34:00 AM(UTC)
kenberkun

Rank: Member

Groups: Member
Joined: 1/5/2005(UTC)
Posts: 20

Thank you, that worked perfectly. I did not understand about the CoCreateInstance.

Ken
Andrew  
#4 Posted : Tuesday, June 14, 2005 4:59:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 863

Thanks: 2 times
Was thanked: 25 time(s) in 25 post(s)
CoCreateInstance is a single way to create new instance of the COM object. It is an analogue to VB6 function CreateObject.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.