Home | Products | Download | Purchase | Support 


   

CardPrint Sample

 

 

The cardprint sample demonstrates how to create a card print and label print application, there are three screen shots shows how this application works, the first is the template setting dialog, the second is the designer editor, the third screen shots shows how to view it on print preview mode, this is a good demo that will help you to use XD++ to build card or label print like application.

and

and with print preview:

Steps:

1. Create new toolbox window, and supports drag and drop feature:

CFODrawShape *CCardPrintView::GetOleDataObject(COleDataObject* pDataObject)
{
	CMyListItemObj *pItem = new  CMyListItemObj;
	if(!CFOToolBoxPageWnd::CreateFromOleData (pItem,pDataObject))
	{
		delete pItem;
		pItem = NULL;
		return NULL;
	}

	CFODrawShape *pReturn = NULL;
	if(pItem != NULL)
	{
		CRect rcCreate = CRect(0,0,0,0);
		pReturn = GetCurrentModel()->DoCreateShapeByType(pItem->GetType(),rcCreate,"",pItem);
		delete pItem;
		pItem = NULL;
	}

	return pReturn;
}

2. Create a new template window class CMyNewTemplateWnd that uses CFOTemplateWnd as base class.

BOOL CNewVisualProxy::GetBitmap(const CString &strFile,CFOBitmap &bmp, int cx, int cy,COLORREF crBack)
{
	if(strFile == "BITMAP_350_200")
	{
		CClientDC dc(AfxGetMainWnd());
		CBitmap bitmap;
		bitmap.LoadBitmap(IDB_BITMAP_350_200);
		bmp.MakeNewBitmap(&dc,&bitmap);
	}
	else if(strFile == "BITMAP_8700_5080_MM")
	{
		CClientDC dc(AfxGetMainWnd());
		CBitmap bitmap;
		bitmap.LoadBitmap(IDB_BITMAP_8700_5080_MM);
		bmp.MakeNewBitmap(&dc,&bitmap);
	}
	else if(strFile == "400_200_IN_LABEL")
	{
		CClientDC dc(AfxGetMainWnd());
		CBitmap bitmap;
		bitmap.LoadBitmap(IDB_BITMAP_400_200_IN_LABEL);
		bmp.MakeNewBitmap(&dc,&bitmap);
	}
	else if(strFile == "LABEL_100_34_MM")
	{
		CClientDC dc(AfxGetMainWnd());
		CBitmap bitmap;
		bitmap.LoadBitmap(IDB_BITMAP_LABEL_100_34_MM);
		bmp.MakeNewBitmap(&dc,&bitmap);
	}
	else if(strFile == "262_100_IN_LABEL")
	{
		CClientDC dc(AfxGetMainWnd());
		CBitmap bitmap;
		bitmap.LoadBitmap(IDB_BITMAP_262_100_IN_LABEL);
		bmp.MakeNewBitmap(&dc,&bitmap);
	}
	else if(strFile == "590_463_BACK_IN")
	{
		CClientDC dc(AfxGetMainWnd());
		CBitmap bitmap;
		bitmap.LoadBitmap(IDB_BITMAP_DVD_590_463_BACK_IN);
		bmp.MakeNewBitmap(&dc,&bitmap);
	}
	else if(strFile == "CD_118_118_MM")
	{
		CClientDC dc(AfxGetMainWnd());
		CBitmap bitmap;
		bitmap.LoadBitmap(IDB_BITMAP_CD_118_118_MM);
		bmp.MakeNewBitmap(&dc,&bitmap);
	}
	
	cx;
	cy;
	crBack;

	return TRUE;
}

3. Initial the canvas:

void CCardPrintView::DoChangeModel(CFODataModel * pModel)
{
	CFODrawView::DoChangeModel(pModel);
	if(theApp.nCurOpenMode == 101)
	{
		switch(theApp.nCurSel)
		{
		case 200:
			{
				CFOScaleUint m_Uint;
				int nWidth = m_Uint.ConvertToLogPoint(FUNIT_INCHES,3.50);
				int nHeight = m_Uint.ConvertToLogPoint(FUNIT_INCHES,2.0);
				pModel->SetCanvasSize(CSize(nWidth,nHeight));
			}
			break;
			
		case 201:
			{
				CFOScaleUint m_Uint;
				int nWidth = m_Uint.ConvertToLogPoint(FUNIT_MM,87.0);
				int nHeight = m_Uint.ConvertToLogPoint(FUNIT_MM,50.80);
				pModel->SetCanvasSize(CSize(nWidth,nHeight));
			}
			break;
			
		case 202:
			{
				CFOScaleUint m_Uint;
				int nWidth = m_Uint.ConvertToLogPoint(FUNIT_INCHES,4.0);
				int nHeight = m_Uint.ConvertToLogPoint(FUNIT_INCHES,2.0);
				pModel->SetCanvasSize(CSize(nWidth,nHeight));
			}
			break;
			
		case 203:
			{
				CFOScaleUint m_Uint;
				int nWidth = m_Uint.ConvertToLogPoint(FUNIT_MM,100.0);
				int nHeight = m_Uint.ConvertToLogPoint(FUNIT_MM,34.0);
				pModel->SetCanvasSize(CSize(nWidth,nHeight));

				CRect rc = CRect(0,0,nWidth,nHeight);

				CFORoundRectShape *pReturn = new CFORoundRectShape;
				pReturn->AddRef();
				pReturn->Create(rc,16);
				pReturn->SetBkColor(RGB(233,233,255));
				GetCurrentModel()->GetBackDrawComp()->AddShape(pReturn);
				pReturn->Release();
			}
			break;
			
		case 204:
			{
				CFOScaleUint m_Uint;
				int nWidth = m_Uint.ConvertToLogPoint(FUNIT_INCHES,2.62);
				int nHeight = m_Uint.ConvertToLogPoint(FUNIT_INCHES,1.0);
				pModel->SetCanvasSize(CSize(nWidth,nHeight));
			}
			break;
			
		case 205:
			{
				CFOScaleUint m_Uint;
				int nWidth = m_Uint.ConvertToLogPoint(FUNIT_INCHES,5.90);
				int nHeight = m_Uint.ConvertToLogPoint(FUNIT_INCHES,4.63);
				pModel->SetCanvasSize(CSize(nWidth,nHeight));
			}
			break;
			
		case 206:
			{
				CFOScaleUint m_Uint;
				int nWidth = m_Uint.ConvertToLogPoint(FUNIT_MM,118.0);
				int nHeight = m_Uint.ConvertToLogPoint(FUNIT_MM,118.0);
				pModel->SetCanvasSize(CSize(nWidth,nHeight));

				CRect rc = CRect(0,0,nWidth,nHeight);

				int nWidth1 = (int)(m_Uint.ConvertToLogPoint(FUNIT_INCHES,2.06) / 2.0);
				int nHeight1 = (int)(m_Uint.ConvertToLogPoint(FUNIT_INCHES,2.06) / 2.0);

				CPoint ptCenter = rc.CenterPoint();

				CRect rcSmall = CRect(ptCenter.x - nWidth1,ptCenter.y - nHeight1,ptCenter.x + nWidth1,ptCenter.y + nHeight1);

				CRect rcPos = rc;
				rcPos.NormalizeRect();
				CPoint ptLeft = rcPos.TopLeft();
				if(rcPos.IsRectEmpty()||(rcPos.Width() <= 10 && rcPos.Height() < 20))
				{
					rcPos = CRect(ptLeft,CSize(20,20));
				}

				FOPRect aRect = rcPos;
				FOPSimpleCompositePolygon aXPP;
				FOPSimplePolygon first(aRect,(int)(aRect.Width() / 2.0),(int)(aRect.Height()/2.0));
				aXPP.Insert(first);
				
				aRect = rcSmall;
				FOPSimplePolygon second(aRect,(int)(aRect.Width() / 2.0),(int)(aRect.Height()/2.0));
				aXPP.Insert(second);
				
				CFOPathShape *pReturn = new CFOPathShape;
				pReturn->AddRef();
				pReturn->Create(FOP_DRAW_PATH_PATHFILL,aXPP);
				pReturn->SetBkColor(RGB(233,233,255));

				GetCurrentModel()->GetBackDrawComp()->AddShape(pReturn);
				pReturn->Release();
			}
			break;
		}
	}

	pModel->SetPrinterPageMargin(CRect(0,0,0,0));

	theApp.nCurOpenMode = 100;
	theApp.nCurSel = -1;
}

void CCardPrintView::OnInitialUpdate()
{
	SetCurrentModel(GetDocument()->m_pDataModel);
	CFODrawView::OnInitialUpdate();

}

4. Drawing shapes:

void CCardPrintView::OnDrawBevel() 
{
	// TODO: Add your command handler code here
	m_drawshape = FO_COMP_BEVEL_COMP;
	SetCurrentDrawingCursor(IDC_FO_DRAWRECT_CURSOR);
	m_action_state = State_DrawRect;
	m_bUpRightMode = FALSE;
}

void CCardPrintView::OnUpdateDrawBevel(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	BOOL bDesign = GetCurrentModel()->IsDesignMode();
	pCmdUI->Enable(bDesign);

	pCmdUI->SetCheck(m_drawshape == FO_COMP_BEVEL_COMP && (!m_bUpRightMode));
}

void CCardPrintView::OnDrawCorner() 
{
	// TODO: Add your command handler code here
	m_drawshape = FO_COMP_CORNER_COMP;
	SetCurrentDrawingCursor(IDC_FO_DRAWRECT_CURSOR);
	m_action_state = State_DrawRect;
	m_bUpRightMode = FALSE;
}

void CCardPrintView::OnUpdateDrawCorner(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	BOOL bDesign = GetCurrentModel()->IsDesignMode();
	pCmdUI->Enable(bDesign);

	pCmdUI->SetCheck(m_drawshape == FO_COMP_CORNER_COMP && (!m_bUpRightMode));
}


[ Home | Products | Download Area | Purchase | SupportContact us ]


Copyright ?1998-2007 UCanCode.Net Software, all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.com