#include <Symbol.h>
#include <MyFrame.h>

#include <BarCode.h>

void far PaintBarCode_BarCode(int nX, int nY, char* pStrBarCode, int nBarCodeStyle, float fBei)
{
	char buf[256],buf1[100];


	_fstrcpy(buf, pStrBarCode);
	CRegister::TrimLeft(buf);
	CRegister::TrimRight(buf);

	::_fstrupr(buf);


	int nOldMouse = ::GetMouse();
	::CloseMouse();

	//::SetFillStyle(1,WHITE);
	//::Bar(222,209,613,275);

	CBarCode mBarCode;
	mBarCode.SetStyle(nBarCodeStyle);
	mBarCode.SetRect(nX, nY, 310, 40);

	mBarCode.SetModifyHeight(FALSE);

	if(nBarCodeStyle == BARCODE_ISBN) mBarCode.SetISBNAttrib(3,3,1);
	if(nBarCodeStyle == BARCODE_ISSN) mBarCode.SetISSNAttrib(1);
	if(nBarCodeStyle == BARCODE_39)   mBarCode.Set39Attrib(TRUE);
	if(nBarCodeStyle == BARCODE_X25)  mBarCode.SetX25Attrib(TRUE,FALSE);

	mBarCode.DrawBarCode(buf);


	::SetMouse(nOldMouse);

}

void far OnDraw_BarCodeDemo(CObject* pCurObj)
{
	CDialog *pDialog = (CDialog *)pCurObj;


	//UPC_A
	::PaintBarCode_BarCode(5, 10, "12345678901", BARCODE_UPC_A, 1.0f);
	::ChPrintf(5, 40 + 10, WHITE, BLACK, 1, 0, "UPC_A条码");

	//UPC_E
	::PaintBarCode_BarCode(5, 70, "0123456", BARCODE_UPC_E, 1.0f);
	::ChPrintf(5, 40 + 70, WHITE, BLACK, 1, 0, "UPC_E条码");

	//EAN_13
	::PaintBarCode_BarCode(5, 130, "123456789012", BARCODE_EAN_13, 1.0f);
	::ChPrintf(5, 40 + 130, WHITE, BLACK, 1, 0, "EAN_13条码");

	//EAN_8
	::PaintBarCode_BarCode(5, 190, "1234567", BARCODE_EAN_8, 1.0f);
	::ChPrintf(5, 40 + 190, WHITE, BLACK, 1, 0, "EAN_8条码");

	//39
	::PaintBarCode_BarCode(5, 250, "Sail-1234567", BARCODE_39, 1.0f);
	::ChPrintf(5, 40 + 250, WHITE, BLACK, 1, 0, "39条码");

	//ISBN
	::PaintBarCode_BarCode(5, 310, "123456789", BARCODE_ISBN, 1.0f);
	::ChPrintf(5, 40 + 310, WHITE, BLACK, 1, 0, "ISBN条码");

	//ISSN
	::PaintBarCode_BarCode(5, 370, "123456789", BARCODE_ISSN, 1.0f);
	::ChPrintf(5, 40 + 370, WHITE, BLACK, 1, 0, "ISSN条码");

	//X25
	::PaintBarCode_BarCode(320, 10, "1234567", BARCODE_X25, 1.0f);
	::ChPrintf(320, 40 + 10, WHITE, BLACK, 1, 0, "X25条码");

	//Codabar
	::PaintBarCode_BarCode(320, 70, "1234567", BARCODE_CODABAR, 1.0f);
	::ChPrintf(320, 40 + 70, WHITE, BLACK, 1, 0, "Codabar条码");

	//128
	::PaintBarCode_BarCode(320, 130, "1234567", BARCODE_128, 1.0f);
	::ChPrintf(320, 40 + 130, WHITE, BLACK, 1, 0, "128条码");

}
void far BarCodeDemo()
{
	CDialog* pDialog = new CDialog;
	pDialog->CreateWindow(0, 0, 640, 480, "BarCode Demo");
	pDialog->Center();

	new CCloseButton(pDialog);

	pDialog->SetDrawFc(OnDraw_BarCodeDemo);



	pDialog->ShowWindow();
	pDialog->DoModal();
	delete pDialog;
	return;
}