
// SampleDlg.cpp : 구현 파일
//

#include "stdafx.h"
#include "Sample.h"
#include "SampleDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CSampleDlg 대화 상자




CSampleDlg::CSampleDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSampleDlg::IDD, pParent)
	, m_strPort(_T(""))
	, m_strTrack1(_T(""))
	, m_strTrack2(_T(""))
	, m_strTrack3(_T(""))
	, m_bMsrMsgUsed(FALSE)
	, m_iMethodOption(0)
	, m_strFullTrack(_T(""))
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSampleDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_PORTNAME, m_strPort);
	DDX_Text(pDX, IDC_STATIC_1, m_strTrack1);
	DDX_Text(pDX, IDC_STATIC_2, m_strTrack2);
	DDX_Text(pDX, IDC_STATIC_3, m_strTrack3);
	DDX_Check(pDX, IDC_CHECK_MSRMSG, m_bMsrMsgUsed);
	DDX_Radio(pDX, IDC_RADIO2, m_iMethodOption);
	DDX_Text(pDX, IDC_STATIC_4, m_strFullTrack);
}

BEGIN_MESSAGE_MAP(CSampleDlg, CDialog)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_BTN_OPENPORT, &CSampleDlg::OnBnClickedBtnOpenport)
	ON_BN_CLICKED(IDC_BTN_CLOSEPORT, &CSampleDlg::OnBnClickedBtnCloseport)
	ON_BN_CLICKED(IDC_BTN_FEED, &CSampleDlg::OnBnClickedBtnFeed)
	ON_BN_CLICKED(IDOK, &CSampleDlg::OnBnClickedOk)
	ON_BN_CLICKED(IDC_BTN_BITMAP, &CSampleDlg::OnBnClickedBtnBitmap)
	ON_BN_CLICKED(IDC_BTN_1DBARCODE, &CSampleDlg::OnBnClickedBtn1dbarcode)
	ON_BN_CLICKED(IDC_BTN_PRINTTEXT, &CSampleDlg::OnBnClickedBtnPrinttext)
	ON_BN_CLICKED(IDC_BTN_SAMPLE, &CSampleDlg::OnBnClickedBtnSample)
	ON_BN_CLICKED(IDC_BTN_2DBARCODE, &CSampleDlg::OnBnClickedBtn2dbarcode)
	ON_BN_CLICKED(IDC_BUTTON_DIRECTIO, &CSampleDlg::OnBnClickedButtonDirectio)
	ON_BN_CLICKED(IDC_BTN_STATUS, &CSampleDlg::OnBnClickedBtnStatus)
	ON_BN_CLICKED(IDC_BTN_PROPERTY, &CSampleDlg::OnBnClickedBtnProperty)
	ON_BN_CLICKED(IDC_BTN_LABEL, &CSampleDlg::OnBnClickedBtnLabel)
	ON_BN_CLICKED(IDC_BTN_RECEIPT, &CSampleDlg::OnBnClickedBtnReceipt)
	ON_BN_CLICKED(IDC_BTN_AUTOCALIBRATION, &CSampleDlg::OnBnClickedBtnAutocalibration)
	ON_BN_CLICKED(IDC_BTN_PAGE, &CSampleDlg::OnBnClickedBtnPage)
	ON_BN_CLICKED(IDC_BTN_PSAMPLE, &CSampleDlg::OnBnClickedBtnPsample)
	ON_BN_CLICKED(IDC_BUTTON_MSRSTART, &CSampleDlg::OnBnClickedButtonMsrstart)
	ON_BN_CLICKED(IDC_BUTTON_MSRCANCEL, &CSampleDlg::OnBnClickedButtonMsrcancel)
	ON_WM_TIMER()
END_MESSAGE_MAP()


// CSampleDlg 메시지 처리기

BOOL CSampleDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	SetIcon(m_hIcon, TRUE);			// 큰 아이콘을 설정합니다.
	SetIcon(m_hIcon, FALSE);		// 작은 아이콘을 설정합니다.

	m_strPort = "COM1:115200";

	GetDlgItem(IDC_BTN_FEED)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_BITMAP)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_1DBARCODE)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_PRINTTEXT)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_SAMPLE)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_2DBARCODE)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_DIRECTIO)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_STATUS)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_PROPERTY)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_LABEL)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_RECEIPT)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_AUTOCALIBRATION)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_PAGE)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_PSAMPLE)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_MSRSTART)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_MSRCANCEL)->EnableWindow(FALSE);

	m_bMode = FALSE;
	UpdateData(FALSE);

	return TRUE;  // 포커스를 컨트롤에 설정하지 않으면 TRUE를 반환합니다.
}

// 대화 상자에 최소화 단추를 추가할 경우 아이콘을 그리려면
//  아래 코드가 필요합니다. 문서/뷰 모델을 사용하는 MFC 응용 프로그램의 경우에는
//  프레임워크에서 이 작업을 자동으로 수행합니다.

void CSampleDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 그리기를 위한 디바이스 컨텍스트

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 클라이언트 사각형에서 아이콘을 가운데에 맞춥니다.
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 아이콘을 그립니다.
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// 사용자가 최소화된 창을 끄는 동안에 커서가 표시되도록 시스템에서
//  이 함수를 호출합니다.
HCURSOR CSampleDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


void CSampleDlg::OnBnClickedBtnOpenport()
{
	UpdateData(TRUE);

	long lResult = 0;

	lResult = PrinterOpen(m_strPort, 1000);	
	//	lResult = PrinterOpen("COM1:115200", 1000);	

	if(lResult != BXL_SUCCESS && lResult != BXL_WATING_OPEN)
	{
		CString strdata;
		strdata.Format("Error Code = %d", lResult);
		AfxMessageBox(strdata);		
		return ;
	}

	GetDlgItem(IDC_BTN_FEED)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_BITMAP)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_1DBARCODE)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_PRINTTEXT)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_SAMPLE)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_2DBARCODE)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_DIRECTIO)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_STATUS)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_PROPERTY)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_LABEL)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_RECEIPT)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_AUTOCALIBRATION)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_PAGE)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_PSAMPLE)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_MSRSTART)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_MSRCANCEL)->EnableWindow(TRUE);
}

void CSampleDlg::OnBnClickedBtnCloseport()
{
	PrinterClose();

	GetDlgItem(IDC_BTN_FEED)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_BITMAP)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_1DBARCODE)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_PRINTTEXT)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_SAMPLE)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_2DBARCODE)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_DIRECTIO)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_STATUS)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_PROPERTY)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_LABEL)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_RECEIPT)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_AUTOCALIBRATION)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_PAGE)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_PSAMPLE)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_MSRSTART)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_MSRCANCEL)->EnableWindow(FALSE);
}

void CSampleDlg::OnBnClickedBtnFeed()
{
	LineFeed(10);
}

void CSampleDlg::OnBnClickedOk()
{
	// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
	OnOK();
}

void CSampleDlg::OnBnClickedBtnBitmap()
{
	CString strError;
	long lResult = 0;
	lResult = CheckPrinter();
	//Printer State Check
	if( lResult != BXL_SUCCESS)
	{		
		strError.Format("Printer is Error = %d", lResult);
		AfxMessageBox(strError);
		return;
	}

	lResult = GetStat();
	if( lResult != BXL_STS_NORMAL)
	{
		strError.Format("Printer State is Error = %d", lResult);
		AfxMessageBox(strError);
		return;
	}

	CString strFile;
	CFileDialog FileDlg(TRUE, "", strFile, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, "Image File(*.bmp)|*.bmp|Image File(*.jpg)|*.jpg|Image File(*.gif)|*.gif||");

	if(FileDlg.DoModal() == IDOK)
	{
		strFile = FileDlg.GetPathName();
	}else
		return;

	PrintBitmap(strFile, BXL_WIDTH_FULL, BXL_ALIGNMENT_CENTER, 50);
}

void CSampleDlg::OnBnClickedBtn1dbarcode()
{
	CString strError;
	long lResult = 0;
	lResult = CheckPrinter();
	//Printer State Check
	if( lResult != BXL_SUCCESS)
	{		
		strError.Format("Printer is Error = %d", lResult);
		AfxMessageBox(strError);
		return;
	}

	lResult = GetStat();
	if( lResult != BXL_STS_NORMAL)
	{
		strError.Format("Printer State is Error = %d", lResult);
		AfxMessageBox(strError);
		return;
	}

	int i = 0;
	//UPCA Printing

	for(i = 2; i < 7; i+=2 )
	{	
		PrintText("BARCODE : UPCA\n", BXL_ALIGNMENT_LEFT, 0,0);
		PrintBarcode("123456789012", BXL_BCS_UPCA, 50, i, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);	
		LineFeed(2);		
	}

	//UPCE Printing
	for(i = 2; i < 7; i+=2 )
	{	
		PrintText("BARCODE : UPCE\n", BXL_ALIGNMENT_LEFT, 0,0);
		PrintBarcode("012345678901", BXL_BCS_UPCE, 50, i, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);
		LineFeed(2);		
	}	

	//JAN,EAN8 Printing	
	for(i = 2; i < 7; i+=2 )
	{	
		PrintText("BARCODE : JAN/EAN8\n", BXL_ALIGNMENT_LEFT, 0,0);
		PrintBarcode("12345678", BXL_BCS_JAN8, 50, i, BXL_ALIGNMENT_RIGHT, BXL_BC_TEXT_ABOVE);
		LineFeed(2);		
	}


	//JAN,EAN8 Printing	
	for(i = 2; i < 7; i+=2 )
	{	
		PrintText("BARCODE : JAN/EAN13\n", BXL_ALIGNMENT_LEFT, 0,0);
		PrintBarcode("1234567890123", BXL_BCS_EAN13, 50, i, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);
		LineFeed(2);		
	}

	for(i = 2; i < 7; i+=2 )
	{	
		PrintText("BARCODE : CODE39\n", BXL_ALIGNMENT_LEFT, 0,0);
		PrintBarcode("12", BXL_BCS_CODE39, 50, i, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);
		LineFeed(2);		
	}

	for(i = 2; i < 7; i+=2 )
	{	
		PrintText("BARCODE : ITF\n", BXL_ALIGNMENT_LEFT, 0,0);
		PrintBarcode("1234", BXL_BCS_ITF, 50, i, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);
		LineFeed(2);		
	}

	for(i = 2; i < 7; i+=2 )
	{	
		PrintText("BARCODE : CODEBAR\n", BXL_ALIGNMENT_LEFT, 0,0);
		PrintBarcode("1234", BXL_BCS_CODABAR, 50, i, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);
		LineFeed(2);		
	}

	for(i = 2; i < 7; i+=2 )
	{	
		PrintText("BARCODE : CODE93\n", BXL_ALIGNMENT_LEFT, 0,0);
		PrintBarcode("1234", BXL_BCS_CODE93, 50, i, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);
		LineFeed(2);		
	}

	for(i = 2; i < 7; i+=2 )
	{	
		PrintText("BARCODE : CODE128\n", BXL_ALIGNMENT_LEFT, 0,0);
		PrintBarcode("1234", BXL_BCS_CODE128, 50, i, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);
		LineFeed(2);		
	}
}

void CSampleDlg::OnBnClickedBtnPrinttext()
{
	SetCharacterSet(BXL_CS_WPC1251);
	SetInterChrSet(BXL_ICS_USA);

	PrintText("Left, Default\n", BXL_ALIGNMENT_LEFT, BXL_FT_DEFAULT, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	PrintText("Center, FontB\n", BXL_ALIGNMENT_CENTER, BXL_FT_FONTB, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	PrintText("Right, FontC\n", BXL_ALIGNMENT_RIGHT, BXL_FT_FONTC, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);

	PrintText("Center, Bold, Default\n", BXL_ALIGNMENT_CENTER, BXL_FT_BOLD | BXL_FT_DEFAULT, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	PrintText("Center, Bold, FontB\n", BXL_ALIGNMENT_CENTER, BXL_FT_BOLD | BXL_FT_FONTB, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	PrintText("Center, Bold, FontC\n", BXL_ALIGNMENT_CENTER, BXL_FT_BOLD | BXL_FT_FONTC, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);

	PrintText("Left, Underline\n", BXL_ALIGNMENT_LEFT, BXL_FT_UNDERLINE | BXL_FT_DEFAULT, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	PrintText("Right, Reverse\n", BXL_ALIGNMENT_RIGHT, BXL_FT_REVERSE | BXL_FT_DEFAULT, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);

	PrintText("Left, Default, 0W 0H\n", BXL_ALIGNMENT_LEFT, BXL_FT_DEFAULT, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	PrintText("Left, Default, 1W 0H\n", BXL_ALIGNMENT_LEFT, BXL_FT_DEFAULT, BXL_TS_1WIDTH | BXL_TS_0HEIGHT);
	PrintText("Left, Default, 0W 1H\n", BXL_ALIGNMENT_LEFT, BXL_FT_DEFAULT, BXL_TS_0WIDTH | BXL_TS_1HEIGHT);
	PrintText("Left, Default, 1W 1H\n", BXL_ALIGNMENT_LEFT, BXL_FT_DEFAULT, BXL_TS_1WIDTH | BXL_TS_1HEIGHT);

	LineFeed(5);
}

void CSampleDlg::OnBnClickedBtnSample()
{
	CString strError;
	long lResult = 0;
	lResult = CheckPrinter();

	//Printer State Check
	if( lResult != BXL_SUCCESS)
	{		
		strError.Format("Printer is Error = %d", lResult);
		AfxMessageBox(strError);
		return;
	}

	lResult = GetStat();
	if( lResult != BXL_STS_NORMAL)
	{
		strError.Format("Printer State is Error = %d", lResult);
		AfxMessageBox(strError);
		return;
	}

	CHAR t[10] = "Receipt";
	PrintText(t, BXL_ALIGNMENT_CENTER, BXL_FT_BOLD | BXL_FT_UNDERLINE, BXL_TS_1WIDTH | BXL_TS_1HEIGHT);	
	PrintText(" \n\n", BXL_ALIGNMENT_CENTER, BXL_FT_BOLD | BXL_FT_UNDERLINE, BXL_TS_1WIDTH | BXL_TS_1HEIGHT);	

	PrintText("------------------------------\n", BXL_ALIGNMENT_CENTER, BXL_FT_DEFAULT, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	PrintText(" Apple      3             $3.0\n", BXL_ALIGNMENT_CENTER, BXL_FT_DEFAULT, BXL_TS_0WIDTH|BXL_TS_0HEIGHT);
	PrintText(" Cola       1             $1.2\n", BXL_ALIGNMENT_CENTER, BXL_FT_DEFAULT, BXL_TS_0WIDTH|BXL_TS_0HEIGHT);	
	PrintText(" Milk       2             $1.8\n", BXL_ALIGNMENT_CENTER, BXL_FT_DEFAULT, BXL_TS_0WIDTH|BXL_TS_0HEIGHT);	
	PrintText(" Juice      1             $2.0\n", BXL_ALIGNMENT_CENTER, BXL_FT_DEFAULT, BXL_TS_0WIDTH|BXL_TS_0HEIGHT);	
	PrintText("------------------------------\n", BXL_ALIGNMENT_CENTER, BXL_FT_DEFAULT, BXL_TS_0WIDTH|BXL_TS_0HEIGHT);	
	PrintText(" Total                    $8.0\n", BXL_ALIGNMENT_CENTER, BXL_FT_BOLD, BXL_TS_0WIDTH|BXL_TS_0HEIGHT);	
	PrintText(" Cash                     $8.0\n", BXL_ALIGNMENT_CENTER, BXL_FT_BOLD, BXL_TS_0WIDTH|BXL_TS_0HEIGHT);	
	PrintText("                          $0.0\n", BXL_ALIGNMENT_CENTER, BXL_FT_BOLD, BXL_TS_0WIDTH|BXL_TS_0HEIGHT);	

	//////////////////////////////////////////////////////////////////////////
	//Set multi attribute in one line.
	PrintText("Test", BXL_ALIGNMENT_CENTER, BXL_FT_BOLD, BXL_TS_0WIDTH|BXL_TS_0HEIGHT);	
	PrintText("BBB", BXL_ALIGNMENT_CENTER, BXL_FT_FONTB | BXL_FT_BOLD, BXL_TS_0WIDTH|BXL_TS_0HEIGHT);	
	PrintText("CCC", BXL_ALIGNMENT_CENTER, BXL_FT_FONTB | BXL_FT_REVERSE, BXL_TS_0WIDTH|BXL_TS_0HEIGHT);	
	PrintText("DDD", BXL_ALIGNMENT_CENTER, BXL_FT_BOLD | BXL_FT_UNDERLINE, BXL_TS_0WIDTH|BXL_TS_0HEIGHT);	
	PrintText("\n", BXL_ALIGNMENT_CENTER, BXL_FT_BOLD | BXL_FT_UNDERLINE, BXL_TS_0WIDTH|BXL_TS_0HEIGHT);	

	PrintBarcode("12345678", BXL_BCS_ITF, 100, 2, BXL_ALIGNMENT_CENTER, BXL_BC_TEXT_BELOW);

	lResult = LineFeed(5);
	if(lResult != BXL_SUCCESS)
	{
		AfxMessageBox("Error LineFeeding");
	}

}

void CSampleDlg::OnBnClickedBtn2dbarcode()
{
	CString strError;
	long lResult ;

	//////////////////////////////////////////////////////////////////////////

	lResult = PrintText("BARCODE : PDF417\n", BXL_ALIGNMENT_LEFT, 0,0);
	if(lResult != BXL_SUCCESS)
	{
		strError.Format("PrintTExt is Error = %d", lResult);
		AfxMessageBox(strError);
		return;
	}

	lResult = PrintBarcode("12345647890123456478901234564789012345647890", BXL_BCS_PDF417, 255, 2, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);		
	if(lResult != BXL_SUCCESS)
	{
		strError.Format("PrintBarcode is Error = %d", lResult);
		AfxMessageBox(strError);
		return;
	}

	lResult = PrintBarcode("12345647890123456478901234564789012345647890", BXL_BCS_PDF417, 255, 3, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);		
	if(lResult != BXL_SUCCESS)
	{
		strError.Format("PrintBarcode is Error = %d", lResult);
		AfxMessageBox(strError);
		return;
	}
	LineFeed(2);	

	//////////////////////////////////////////////////////////////////////////
	lResult = PrintText("BARCODE : QRCode\n", BXL_ALIGNMENT_LEFT, 0,0);
	if(lResult != BXL_SUCCESS)
	{
		strError.Format("PrintTExt is Error = %d", lResult);
		AfxMessageBox(strError);
		return;
	}

	int i = 0;
	for(i =0; i<8; i++)
	{
		lResult = PrintBarcode("12345647890123456478901234564789012345647890", BXL_BCS_QRCODE_MODEL1, 255, i, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);		
		if(lResult != BXL_SUCCESS)
		{
			strError.Format("PrintBarcode is Error = %d", lResult);
			AfxMessageBox(strError);
			return;
		}
	}

	for(i = 0; i<8; i++)
	{
		lResult = PrintBarcode("12345647890123456478901234564789012345647890", BXL_BCS_QRCODE_MODEL2, 255, i, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);		
		if(lResult != BXL_SUCCESS)
		{
			strError.Format("PrintBarcode is Error = %d", lResult);
			AfxMessageBox(strError);
			return;
		}
	}
	LineFeed(2);	
	//////////////////////////////////////////////////////////////////////////

	lResult = PrintText("BARCODE : DataMatrix\n", BXL_ALIGNMENT_LEFT, 0,0);
	if(lResult != BXL_SUCCESS)
	{
		strError.Format("PrintTExt is Error = %d", lResult);
		AfxMessageBox(strError);
		return;
	}

	for(i=2; i<7; i++)
	{
		lResult = PrintBarcode("12345647890123456478901234564789012345647890", BXL_BCS_DATAMATRIX, 255, i, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);		
		if(lResult != BXL_SUCCESS)
		{
			strError.Format("PrintBarcode is Error = %d", lResult);
			AfxMessageBox(strError);
			return;
		}
	}
	LineFeed(2);	
	//////////////////////////////////////////////////////////////////////////

	lResult = PrintText("BARCODE : MaxiCode\n", BXL_ALIGNMENT_LEFT, 0,0);
	if(lResult != BXL_SUCCESS)
	{
		strError.Format("PrintTExt is Error = %d", lResult);
		AfxMessageBox(strError);
		return;
	}

	lResult = PrintBarcode("[)>\x1E\x30\x31\x1D\x39\x36TABCDE\x1D\x30\x30\x37\x1d\x32\x35\x30\x1dTTTBCDE12345647890123456478901234564789012345647890", BXL_BCS_MAXICODE_MODE2, 255, 2, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);		
	if(lResult != BXL_SUCCESS)
	{
		strError.Format("PrintBarcode is Error = %d", lResult);
		AfxMessageBox(strError);
		return;
	}

	lResult = PrintBarcode("[)>\x1E\x30\x31\x1D\x39\x36TAE\x1D\x30\x30\x37\x1d\x32\x35\x30\x1dTTT12345647890123456478901234564789012345647890", BXL_BCS_MAXICODE_MODE3, 255, 2, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);		
	if(lResult != BXL_SUCCESS)
	{
		strError.Format("PrintBarcode is Error = %d", lResult);
		AfxMessageBox(strError);
		return;
	}

	lResult = PrintBarcode("12345647890123456478901234564789012345647890", BXL_BCS_MAXICODE_MODE4, 255, 2, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);		
	if(lResult != BXL_SUCCESS)
	{
		strError.Format("PrintBarcode is Error = %d", lResult);
		AfxMessageBox(strError);
		return;
	}

	LineFeed(2);	
}

void CSampleDlg::OnBnClickedButtonDirectio()
{
	CHAR dbRead = 0;
	UINT dwRead = 1;

	CHAR dbCmd[3] = {0x10, 0x04, 0x02};
	long lResult = DirectIO(dbCmd, 3, &dbRead, dwRead);

	if (lResult != BXL_SUCCESS)
	{
		CString strEr;
		strEr.Format("Error code = %d", lResult);
		AfxMessageBox(strEr);		
		return;
	}
	else
	{
		CString strRet ;
		strRet.Format("Readdata Read %02x",dbRead);	
		AfxMessageBox(strRet);
	}
}

void CSampleDlg::OnBnClickedBtnStatus()
{
	long lResult = CheckPrinter();
	if(lResult == BXL_NOT_OPENED)
		return;
	int lState = (int)GetStat();
	CString strStatus;

	strStatus = "Printer Status =";
	if( (lState & BXL_STS_PAPEREMPTY)	== BXL_STS_PAPEREMPTY)
	{
		strStatus += "PaperEmpty ";
	}

	if( (lState & BXL_STS_COVEROPEN)	== BXL_STS_COVEROPEN)
	{
		strStatus += "CoverOpen ";
	}

	if( (lState & BXL_STS_MSR_READY)	== BXL_STS_MSR_READY)
	{
		strStatus += "MSRReady ";
	}	

	if( (lState & BXL_STS_ERROR)	== BXL_STS_ERROR)
	{
		strStatus += "Error ";
	}

	if( (lState & BXL_STS_NOT_OPEN)	== BXL_STS_NOT_OPEN)
	{
		strStatus += "NotOpenPort ";
	}

	if( lState== BXL_STS_NORMAL)
	{
		strStatus += "Normal ";
	}

	long lPower = GetPowerValue();

	switch(lPower)
	{
	case BXL_PWR_FULL:		
		strStatus += "\r\nPower Status:FULL";
		break;
	case BXL_PWR_HIGH:
		strStatus += "\r\nPower Status:HIGH";
		break;
	case BXL_PWR_MIDDLE:
		strStatus += "\r\nPower Status:MIDDLE";
		break;
	case BXL_PWR_LOW:
		strStatus += "\r\nPower Status:LOW";
		break;
	default :
		strStatus += "\r\nPower Status:Unknown";
		break;

	}
	AfxMessageBox(strStatus	);

}

void CSampleDlg::OnBnClickedBtnProperty()
{
	SetCharacterSet(1); //katakana
	//SetCharacterSet(437); //USA : Default CodePage

	for(int i = 128; i < 256; i++)
	{
		CString strText;
		strText.Format("%c\n",i);
		PrintText(strText, BXL_ALIGNMENT_LEFT, 0, 0);
	}
}

void CSampleDlg::OnBnClickedBtnLabel()
{
	SelectMode(true);
}

void CSampleDlg::OnBnClickedBtnReceipt()
{
	SelectMode(false);
}

void CSampleDlg::OnBnClickedBtnAutocalibration()
{
	AutoCalibration();
}

void CSampleDlg::OnBnClickedBtnPage()
{
	SelectPageMode(true);
}

void CSampleDlg::OnBnClickedBtnPsample()
{
	InitializePrinter();
	SelectPageMode(true);
	SetPrintAreaInPM(0, 0, 416, 416);
	SetPrintDirectionInPM(BXL_PD_TOP_TO_BOTTOM);

	SetVerticalPositionInPM(70);
	SetHorizontalPositionInPM(5);

	PrintBarcode("1234567890123", BXL_BCS_CODE93, 50, 2, BXL_ALIGNMENT_LEFT, BXL_BC_TEXT_NONE);

	SetVerticalPositionInPM(155);
	SetHorizontalPositionInPM(80);
	PrintText("1234567890123", BXL_ALIGNMENT_CENTER, BXL_FT_DEFAULT, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);

	SetVerticalPositionInPM(200);
	SetHorizontalPositionInPM(0);
	PrintText("Name :", BXL_ALIGNMENT_CENTER, BXL_ExFT_CHINA_FONTB, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	SetVerticalPositionInPM(200);
	SetHorizontalPositionInPM(90);

	PrintText(" Frank  ", BXL_ALIGNMENT_LEFT, BXL_ExFT_CHINA_FONTA | BXL_FT_UNDERTHICK | BXL_FT_BOLD, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	SetVerticalPositionInPM(200);
	SetHorizontalPositionInPM(180);
	PrintText("Sex  :", BXL_ALIGNMENT_CENTER, BXL_ExFT_CHINA_FONTA | BXL_TS_0WIDTH, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	SetVerticalPositionInPM(200);
	SetHorizontalPositionInPM(260);
	PrintText("  male   ", BXL_ALIGNMENT_LEFT, BXL_ExFT_CHINA_FONTA | BXL_FT_UNDERTHICK | BXL_FT_BOLD, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);

	SetVerticalPositionInPM(250);
	SetHorizontalPositionInPM(0);
	PrintText("Age  :", BXL_ALIGNMENT_CENTER, BXL_ExFT_CHINA_FONTA, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	SetVerticalPositionInPM(250);
	SetHorizontalPositionInPM(90);
	PrintText("  30  ", BXL_ALIGNMENT_CENTER, BXL_ExFT_CHINA_FONTA | BXL_FT_UNDERTHICK | BXL_FT_BOLD, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	SetVerticalPositionInPM(250);
	SetHorizontalPositionInPM(180);
	PrintText("City :", BXL_ALIGNMENT_CENTER, BXL_ExFT_CHINA_FONTA | BXL_TS_0WIDTH, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	SetVerticalPositionInPM(250);
	SetHorizontalPositionInPM(260);
	PrintText("  Seoul  ", BXL_ALIGNMENT_CENTER, BXL_ExFT_CHINA_FONTA | BXL_FT_UNDERTHICK | BXL_FT_BOLD, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);


	SetVerticalPositionInPM(360);
	SetHorizontalPositionInPM(60);
	PrintText("abcdefgHIJK-123", BXL_ALIGNMENT_CENTER, BXL_FT_DEFAULT, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);

	PrintDataInPageMode();

	LineFeed(2);
}

void CSampleDlg::OnBnClickedButtonMsrstart()
{
	KillTimer(100);
	m_bMode = FALSE;
	MsrReadReady();	

	if(GetStat() != BXL_STS_MSR_READY)
	{
		m_strTrack1.Format("Not MSR Ready Mode : %d", GetStat());
		UpdateData(FALSE);
		return;
	}	

	UpdateData(TRUE);
	if(!m_bMsrMsgUsed)
	{
		if(m_iMethodOption == 0)
			SetTimer(100,100, NULL);		
		else
			SetTimer(1000, 100, NULL);
	}
}

void CSampleDlg::OnBnClickedButtonMsrcancel()
{
	m_bMode = TRUE;
	UpdateData(TRUE);

	if (!m_bMsrMsgUsed)
	{	
		if (m_iMethodOption == 0)
			KillTimer(100);		
		else
			KillTimer(1000);	
	}

	m_strTrack1 = L"- Cancel to Read Card";		
	m_strTrack2 = L"";
	m_strTrack3 = L"";

	UpdateData(FALSE);
	MsrReadCancel();	
}


void CSampleDlg::OnTimer(UINT nIDEvent) 
{
	// if you set sentinel option, you could allocate enough memory.
	CHAR dbTrack1[200];
	CHAR dbTrack2[200];
	CHAR dbTrack3[200];

	BOOL bTrack1 = FALSE;
	BOOL bTrack2 = FALSE;
	BOOL bTrack3 = FALSE;
	memset(dbTrack1, 0, sizeof(dbTrack1));
	memset(dbTrack2, 0, sizeof(dbTrack2));
	memset(dbTrack3, 0, sizeof(dbTrack3));		

	if (nIDEvent != 100)
	{
		KillTimer(1000);

		if( MsrReadFullTrack(dbFullTrack, 600) != BXL_SUCCESS)
		{
			m_strFullTrack = TEXT("Wait to swipe card");
			m_strTrack1 = "";		
			m_strTrack2 = "..";	
			m_strTrack3 = "";
			UpdateData(FALSE);
			SetTimer(1000, 100, NULL);
			return;		
		}
		else
		{	
			m_strTrack1 = "Use MsrReadFullTrack Functions";
			m_strFullTrack = dbFullTrack;
			UpdateData(FALSE);
			memset(dbFullTrack, 0, 600);
		}

		return;
	}

	KillTimer(100);
	long lResult = MsrReadTrack(dbTrack1, dbTrack2, dbTrack3);

	if (lResult == BXLMSR_DATAEMPTY)
	{		
		if (!m_bMode) {
			m_strTrack1 = "Wait to Read Card";		
			m_strTrack2 = "..";		
			m_strTrack3 = "";
			UpdateData(FALSE);


			SetTimer(100,100, NULL);				
		}
		else
		{
			m_strTrack1 = L"Cancel to Read Card";	
			m_strTrack2 = "";
			m_strTrack3 = "";
			UpdateData(FALSE);
		}		
		return;		
	}
	else
	{
		CString strData1(dbTrack1);
		m_strTrack1 = strData1;
		CString strData2(dbTrack2);
		m_strTrack2 = strData2;
		CString strData3(dbTrack3);
		m_strTrack3 = strData3;			
	}

	UpdateData(FALSE);

	CDialog::OnTimer(nIDEvent);
}
