
// 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_strScrCommand(_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_EDIT_SCR_COMMAND, m_strScrCommand);
}

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(IDOK, &CSampleDlg::OnBnClickedOk)
	
	ON_BN_CLICKED(IDC_BTN_FEED, &CSampleDlg::OnBnClickedBtnFeed)
	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_BUTTON1, &CSampleDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CSampleDlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CSampleDlg::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BTN_SMARTCARD, &CSampleDlg::OnBnClickedBtnSmartcard)
	ON_BN_CLICKED(IDC_BTN_SAM1, &CSampleDlg::OnBnClickedBtnSam1)
	ON_BN_CLICKED(IDC_BTN_SAM2, &CSampleDlg::OnBnClickedBtnSam2)
	ON_BN_CLICKED(IDC_BTN_SCR_DRIECT_IO, &CSampleDlg::OnBnClickedBtnScrDriectIo)
END_MESSAGE_MAP()


// CSampleDlg 메시지 처리기

BOOL CSampleDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	SetIcon(m_hIcon, TRUE);			// 큰 아이콘을 설정합니다.
	SetIcon(m_hIcon, FALSE);		// 작은 아이콘을 설정합니다.

	m_strPort = "COM3: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_BUTTON1)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON3)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_SMARTCARD)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_SAM1)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_SAM2)->EnableWindow(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);	
	
	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_BUTTON1)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON2)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON3)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_SMARTCARD)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_SAM1)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_SAM2)->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_BUTTON1)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON3)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_SMARTCARD)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_SAM1)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_SAM2)->EnableWindow(FALSE);

}

void CSampleDlg::OnBnClickedBtnFeed()
{
	//NextPrintPos();
	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_FT_DEFAULT, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	SetVerticalPositionInPM(200);
	SetHorizontalPositionInPM(90);

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

	SetVerticalPositionInPM(250);
	SetHorizontalPositionInPM(0);
	PrintText("Age  :", BXL_ALIGNMENT_CENTER, BXL_FT_DEFAULT, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	SetVerticalPositionInPM(250);
	SetHorizontalPositionInPM(90);
	PrintText("  30  ", BXL_ALIGNMENT_CENTER, BXL_FT_DEFAULT | BXL_FT_UNDERTHICK | BXL_FT_BOLD, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	SetVerticalPositionInPM(250);
	SetHorizontalPositionInPM(180);
	PrintText("City :", BXL_ALIGNMENT_CENTER, BXL_FT_DEFAULT | BXL_TS_0WIDTH, BXL_TS_0WIDTH | BXL_TS_0HEIGHT);
	SetVerticalPositionInPM(250);
	SetHorizontalPositionInPM(260);
	PrintText("  Seoul  ", BXL_ALIGNMENT_CENTER, BXL_FT_DEFAULT | 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::OnBnClickedButton1()
{
	
	// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
	CHAR cAtr[512] = {0,};
	UINT lAtrLen = 512;
	CHAR cResponseS = 0xff;

	long lResult;

	lResult = ScrPowerUp(cAtr, lAtrLen, &cResponseS);

	if (lResult != BXL_SUCCESS || cResponseS != 0x00)
	{
		AfxMessageBox("scrPowerUp fail.");
		return;
	}

	AfxMessageBox("SCR power up");
	
}

void CSampleDlg::OnBnClickedButton2()
{
	
	// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
	CHAR cResponseS = 0xff;

	long lResult;

	lResult = ScrPowerDown(&cResponseS);

	if (lResult != BXL_SUCCESS || cResponseS != 0x00)
	{
		AfxMessageBox("scrPowerUp fail.");
		return;
	}


	AfxMessageBox("SCR power down");
	
}

void CSampleDlg::OnBnClickedButton3()
{
	
	// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
	CHAR cResponseS = 0xff;
	long lResult;
	CHAR cStatus = 0x00;
	cResponseS = 0x00;

	lResult = ScrChkCardStatus(&cStatus, &cResponseS);

	if (lResult != BXL_SUCCESS || cResponseS != 0x00)
	{
		AfxMessageBox("scChkCardStatus fail.");
		return;
	}

	CString strStatus;

	if ((cStatus & 0x03) == BXL_SCR_STS_5V)
	{
		strStatus = "Power : 5V,";
	}
	else if ((cStatus & 0x03) == BXL_SCR_STS_3V)
	{
		strStatus = "Power : 3V,";
	}
	else 
	{
		strStatus = "Power : 1.8V,";
	}

	if ((cStatus & BXL_SCR_STS_POWERED) != 0)
	{
		strStatus += "  Card Powered,";
	}
	else
	{
		strStatus += "  Card not powered,";
	}

	if ((cStatus & BXL_SCR_STS_INSERTED) != 0)
	{
		strStatus += "  Card inserted.";
	}
	else
	{
		strStatus += "  Card not inserted.";
	}

	AfxMessageBox(strStatus);
	
}

void CSampleDlg::OnBnClickedBtnSmartcard()
{
	// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
	CHAR cResponseS = 0xff;

	long lResult;

	lResult = ScrSelectCard(BXL_SCR_SMARTCARD, &cResponseS);

	if (lResult != BXL_SUCCESS || cResponseS != 0x30)
	{
		AfxMessageBox("Fail to select smart card.");
		return;
	}

	AfxMessageBox("success to select smart card.");
}

void CSampleDlg::OnBnClickedBtnSam1()
{
	// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
	CHAR cResponseS = 0xff;

	long lResult;

	lResult = ScrSelectCard(BXL_SCR_SAM1, &cResponseS);

	if (lResult != BXL_SUCCESS || cResponseS != 0x31)
	{
		AfxMessageBox("Fail to select SAM1.");
		return;
	}

	AfxMessageBox("success to select SAM1.");
}

void CSampleDlg::OnBnClickedBtnSam2()
{
	// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
	CHAR cResponseS = 0xff;

	long lResult;

	lResult = ScrSelectCard(BXL_SCR_SAM2, &cResponseS);

	if (lResult != BXL_SUCCESS || cResponseS != 0x32)
	{
		AfxMessageBox("Fail to select SAM2.");
		return;
	}

	AfxMessageBox("success to select SAM2.");
}

void CSampleDlg::OnBnClickedBtnScrDriectIo()
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	m_strScrCommand.Remove(' ');

	long lResult = 0;
	BYTE byTxBuffer[256] = { 0 }, byRxBuffer[1024] = { 0 };
	DWORD dwTxSize = 0, dwRxSize = 0;

	dwTxSize = ConvertHexaToInteger((LPBYTE)m_strScrCommand.GetBuffer(0), m_strScrCommand.GetLength(), byTxBuffer);
	m_strScrCommand.ReleaseBuffer();

	lResult = SmartCardDirectIO(byTxBuffer, dwTxSize, byRxBuffer, &dwRxSize);
	if(lResult == BXL_SUCCESS && dwRxSize > 0)
	{
		CString strTemp;
		m_strScrCommand.Format("Res : ");

		for(DWORD i = 0; i < dwRxSize; i++)
		{
			strTemp.Format("%02X ", byRxBuffer[i]);
			m_strScrCommand += strTemp;
		}

		UpdateData(FALSE);
	}
	else
	{
		AfxMessageBox("Fail to smart card direct I/O.");
	}
}

DWORD CSampleDlg::ConvertHexaToInteger(LPBYTE szHexa, int nSize, LPBYTE szIntr)
{
	BYTE  ch1, ch2, bData;
	DWORD i = 0;
	int   j = 0;
	//AddListMessage(szHexa);
	while ( j < nSize )
	{
		ch1 = CONVERTINT(szHexa[j]);	bData  = (BYTE)(ch1 << 4);	j++;
		ch2 = CONVERTINT(szHexa[j]);	bData += (ch2 & 0x0f);		j++;
		szIntr[i] = bData;	i++;
		//dbg.Format("%02X%02X -> %02X",ch1,ch2,szIntr[i-1]);	AddListMessage(dbg);
	}
    return i;
}