
// MFCDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MFC.h"
#include "MFCDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CMFCDlg dialog




CMFCDlg::CMFCDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMFCDlg::IDD, pParent)
	, m_strMsg(_T(""))
	, m_strReceivedata(_T(""))
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMFCDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO2, m_cb1);
	DDX_Control(pDX, IDC_COMBO1, m_portCtrl);
	DDX_Control(pDX, IDC_COMBO3, m_baudCtrl);
	DDX_Control(pDX, IDC_COMBO4, m_msrCtrl);
	DDX_Text(pDX, IDC_ANSWER, m_strMsg);
	DDX_Text(pDX, IDC_EDIT1, m_strReceivedata);
	DDX_Control(pDX, IDC_IPADDRESS1, m_ipCtrl);

}

BEGIN_MESSAGE_MAP(CMFCDlg, CDialog)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_CBN_SELCHANGE(IDC_COMBO2, &CMFCDlg::OnCbnSelchangeCombo2)
	ON_BN_CLICKED(IDC_BUTTON1, &CMFCDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CMFCDlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CMFCDlg::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON4, &CMFCDlg::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON5, &CMFCDlg::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON6, &CMFCDlg::OnBnClickedButton6)
	ON_BN_CLICKED(IDC_BUTTON7, &CMFCDlg::OnBnClickedButton7)
	ON_BN_CLICKED(IDC_BUTTON11, &CMFCDlg::OnBnClickedButton11)
	ON_BN_CLICKED(IDC_BUTTON8, &CMFCDlg::OnBnClickedButton8)
	ON_BN_CLICKED(IDC_BUTTON10, &CMFCDlg::OnBnClickedButton10)
	ON_BN_CLICKED(IDC_BUTTON12, &CMFCDlg::OnBnClickedButton12)
	ON_BN_CLICKED(IDC_BUTTON15, &CMFCDlg::OnBnClickedButton15)
	ON_BN_CLICKED(IDC_OK, &CMFCDlg::OnBnClickedOk)
	ON_BN_CLICKED(IDC_BUTTON9, &CMFCDlg::OnBnClickedButton9)
END_MESSAGE_MAP()


// CMFCDlg message handlers

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

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here

	m_cb1.SetCurSel(0);
	OnCbnSelchangeCombo2();
	m_portCtrl.SetCurSel(0);
	m_baudCtrl.SetCurSel(3);
	m_msrCtrl.SetCurSel(1);
	
	GetDlgItem(IDC_STAtus)->GetFont()->GetLogFont(&Logfont);
	Logfont.lfWeight = 1000;
	Logfont.lfHeight = 20;
	m_font.CreateFontIndirect(&Logfont);
	GetDlgItem(IDC_STAtus)->SetFont(&m_font);
	GetDlgItem(IDC_STATIC_MSR)->SetFont(&m_font);

	GetDlgItem(IDC_ANSWER)->GetFont()->GetLogFont(&Logfont2);
	Logfont2.lfWeight = 0;
	Logfont2.lfHeight = 15;
	m_font2.CreateFontIndirect(&Logfont2);
	GetDlgItem(IDC_ANSWER)->SetFont(&m_font2);

	GetDlgItem(IDC_IPADDRESS1)->SetWindowText(_T("192.168.0.10"));
	GetDlgItem(IDC_iPort)->SetWindowText(_T("1470"));

	GetDlgItem(IDC_TEXT)->SetWindowText(_T("This mode only use \"WOOSIM\" printer\r\n"));

	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMFCDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

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

		// Center icon in client rectangle
		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;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMFCDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


void CMFCDlg::OnCbnSelchangeCombo2()
{
	// TODO: Add your control notification handler code here
	if(m_cb1.GetCurSel() == 0)	//Serial
	{
		GetDlgItem(IDC_IPADDRESS1)->ShowWindow(false);
		GetDlgItem(IDC_COMBO1)->ShowWindow(true);
		GetDlgItem(IDC_COMBO3)->ShowWindow(true);
		GetDlgItem(IDC_STATIC_PORT)->ShowWindow(true);
		GetDlgItem(IDC_STATIC_BAUD)->ShowWindow(true);
		GetDlgItem(IDC_BUTTON1)->SetWindowText(_T("Connect"));
		GetDlgItem(IDC_BUTTON2)->SetWindowText(_T("Close"));
		GetDlgItem(IDC_TEXT)->ShowWindow(false);
		GetDlgItem(IDC_STATIC_iPort)->ShowWindow(false);
		GetDlgItem(IDC_iPort)->ShowWindow(false);
	}
	else if(m_cb1.GetCurSel() == 1) // Wifi
	{	
		GetDlgItem(IDC_IPADDRESS1)->ShowWindow(true);
		GetDlgItem(IDC_COMBO1)->ShowWindow(false);
		GetDlgItem(IDC_COMBO3)->ShowWindow(false);
		GetDlgItem(IDC_STATIC_PORT)->ShowWindow(false);
		GetDlgItem(IDC_STATIC_BAUD)->ShowWindow(false);
		GetDlgItem(IDC_BUTTON1)->SetWindowText(_T("Connect"));
		GetDlgItem(IDC_BUTTON2)->SetWindowText(_T("Close"));
		GetDlgItem(IDC_TEXT)->ShowWindow(false);
		GetDlgItem(IDC_STATIC_iPort)->ShowWindow(true);
		GetDlgItem(IDC_iPort)->ShowWindow(true);
	}
	else									// USB
	{	
		GetDlgItem(IDC_IPADDRESS1)->ShowWindow(false);
		GetDlgItem(IDC_COMBO1)->ShowWindow(false);
		GetDlgItem(IDC_COMBO3)->ShowWindow(false);
		GetDlgItem(IDC_STATIC_PORT)->ShowWindow(false);
		GetDlgItem(IDC_STATIC_BAUD)->ShowWindow(false);
		GetDlgItem(IDC_BUTTON1)->SetWindowText(_T("USB Connect"));
		GetDlgItem(IDC_BUTTON2)->SetWindowText(_T("USB Close"));
		GetDlgItem(IDC_TEXT)->ShowWindow(true);
		GetDlgItem(IDC_STATIC_iPort)->ShowWindow(false);
		GetDlgItem(IDC_iPort)->ShowWindow(false);
	}		
}
//Connection Open
void CMFCDlg::OnBnClickedButton1()
{
	// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
	if(m_cb1.GetCurSel() == 0)	//Serial
	{
		int connectStatus = 0;
		CString CSportName,CSbaudRate;		
		m_portCtrl.GetLBText(m_portCtrl.GetCurSel(),CSportName);
		m_baudCtrl.GetLBText(m_baudCtrl.GetCurSel(),CSbaudRate);

		int size = strlen(CT2A(CSportName));
		char *portname = new char[size+1];
		strcpy(portname,CT2A(CSportName));

		int bautRate = _ttoi(CSbaudRate);
		connectStatus = ConnectSerialPrinter(portname,bautRate);

		switch(connectStatus)
		{
			case SUCCESS:
				m_strMsg = _T("SUCCESS");
				break;
			case ALREADY_OPENED : 
				m_strMsg = _T("ALREADY OPEND");
				break;
			case UNABLE_TO_OPEN_THE_PORT : 
				m_strMsg = _T("UNABLE TO OPEN THE PORT");
				break;
			case UNABLE_TO_CONFIGURE_THE_SERIAL_PORT : 
				m_strMsg = _T("UNABLE_TO_CONFIGURE_THE_SERIAL_PORT");
				break;
			case UNABLE_TO_SET_THE_TIMEOUT_PARAMETERS : 
				m_strMsg = _T("UNABLE_TO_SET_THE_TIMEOUT_PARAMETERS");
				break;
			case TIMEOUT : 
				m_strMsg = _T("TIMEOUT");
				break;
		}
		delete [] portname;
	}
	if(m_cb1.GetCurSel() == 1) // Wifi
	{	
		BYTE IP_a, IP_b, IP_c, IP_d;
		int connectStatus = 0;
		CString ipaddr;
		CString CSiPortnum;
		CString err = _T("");
		
		m_ipCtrl.GetAddress(IP_a, IP_b, IP_c, IP_d);
		ipaddr.Format(_T("%d.%d.%d.%d"),IP_a, IP_b, IP_c, IP_d);		
		
		char* Wlan_buff = new char[strlen(CT2A(ipaddr))+1];
		strcpy(Wlan_buff, CT2A(ipaddr));

		GetDlgItem(IDC_iPort)->GetWindowText(CSiPortnum);
		int portnum = _ttoi(CSiPortnum);
	
		connectStatus = ConnectWirelessPrinter(Wlan_buff,portnum,1000);			
	
		switch(connectStatus)
		{
		case SUCCESS:
			m_strMsg = _T("SUCCESS");
			break;
		case SOCKET_ERROR:
			m_strMsg = _T("SOCKET ERROR");
			break;
		case CONNECT_FAIL:
			m_strMsg = _T("CONNECT FAIL");
			break;
		case ALREADY_OPENED:
			m_strMsg = _T("ALREADY CONNECTED");
			break;
		case TIMEOUT : 
			m_strMsg = _T("TIMEOUT");
			break;
		default:
			err.Format(_T("%d"),connectStatus);
			AfxMessageBox(err);
			break;
		}
	}
	if(m_cb1.GetCurSel() == 2)		// USB
	{	
		int connectStatus = 0;

		connectStatus = ConnectUSBPrinter(1000,FALSE);

		switch(connectStatus)
		{
			case SUCCESS:
				m_strMsg = _T("SUCCESS");
				break;
			case ALREADY_OPENED : 
				m_strMsg = _T("ALREADY OPEND");
				ClosePrinterConnection();
				break;
			case UNABLE_TO_MAKE_CONNECTION : 
				m_strMsg = _T("UNABLE_TO_MAKE_CONNECTION");
				ClosePrinterConnection();
				break;
			case UNABLE_TO_GET_INFOMATION : 
				m_strMsg = _T("UNABLE_TO_GET_INFOMATION");
				ClosePrinterConnection();
				break;
			case NOT_WOOSIM_PRINTER : 
				m_strMsg = _T("NOT_WOOSIM_PRINTER");
				ClosePrinterConnection();
				break;
			case TIMEOUT : 
				m_strMsg = _T("TIMEOUT");
				ClosePrinterConnection();
				break;
		}
	}
	UpdateData(false);
}

//Connection Close
void CMFCDlg::OnBnClickedButton2()
{
	// Close any connection (Serial, Wlan or USB)
	m_strMsg = _T("Connection closed");
	ClosePrinterConnection();
	UpdateData(FALSE);
}

//Button Box&Lines
void CMFCDlg::OnBnClickedButton3()
{
	//Initialization & make page
	InitPageMode(0,0,_2INCH,_3INCH);

	//Draw Black & long box
	Page_DrawBox(_2INCH-80,30,30,150,20);
	Page_DrawBox(_2INCH-80,200,30,_3INCH-200-30,1);
	
	//Contained text "TEXT"
	Page_DrawBox(214,224,50,258,1);
	
	//Boxes in Box
	Page_DrawBox(60,234,104,44,1);
	Page_DrawBox(60,312,28,150,1);
	Page_DrawBox(98,312,28,150,1);
	Page_DrawBox(136,312,28,150,1);
	Page_DrawBox(50,224,124,258,3);

	//Draw vertical lines
	Page_DrawBox(205,30,0,140,1);
	Page_DrawBox(235,30,0,140,1);
	Page_DrawBox(265,30,0,140,1);

	//Draw horizontal lines
	Page_DrawBox(185,55,100,0,1);
	Page_DrawBox(185,95,100,0,1);
	Page_DrawBox(185,135,100,0,1);

	//Draw outline-Box
	Page_DrawBox(30,0,_2INCH - 60, _3INCH, 1 );

	Page_SetDirection(3);// Clockwise rotation
	Page_SetPosition(214,30);//Y_pos, X_pos
	SetTextStyle(0,false,1,1,false);
	TextSaveSpool("Text");
	Page_SetPosition(270,70);
	QRCodeSaveSpool(0,'H',2,"www.woosim.com/english");

	SetTextStyle(0,true,1,0,false);
	Page_SetPosition(126,256); //Y_pos, X_pos
	TextSaveSpool("TEXT");
	Page_Print_StandardMode();

	Page_SetDirection(0);
	InitPageMode(0,0,_2INCH,_2INCH);
	
	Page_DrawBox(0,30,_2INCH,0,5);
	Page_DrawBox(30,0,0,_2INCH,5);
	Page_DrawLine(30,30,170,160,3);
	Page_DrawLine(170,160,130,190,3);
	Page_DrawLine(130,190,210,250,3);
	Page_DrawLine(210,250,190,270,3);
	Page_DrawLine(190,270,270,340,3);
	Page_DrawLine(270,340,210,370,3);
	Page_Newline();
	Page_Print();

	Page_ClearCurrentData();
	Page_DrawBox(0,_1INCH,_2INCH,0,5);
	Page_DrawBox(_1INCH,0,0,_2INCH,5);
	Page_DrawBox(_1INCH/2,_1INCH,_1INCH,0,0);
	Page_DrawEllipse(_1INCH,_1INCH,_1INCH/2,_1INCH-20,3);
	Page_Print_StandardMode();

	PrintSpool();

	Page_Print_StandardMode();
	PrintSpool();
}

//Button Text
void CMFCDlg::OnBnClickedButton4()
{
	InitPrinterStatus();

	// TODO: Add your control notification handler code here
	TextSaveSpool("   매 출 전 표\r\n");
	TextSaveSpool("--------------------------------\r\n");
	
	//Company
	
	TextSaveSpool("상점명             Woosim Coffee\r\n");
	TextSaveSpool("사업자등록번호      119-81-36382\r\n");
	//Reg Number
	TextSaveSpool("대표자                  이 일 복\r\n");
	//Address
	TextSaveSpool("서울특별시 금천구 가산동 448번지\r\n대륭테크노타운 3차, 501호\r\n");
	//Tel
	TextSaveSpool("문의                02-2107-3709\r\n");
	TextSaveSpool("--------------------------------\r\n\r\n");
	TextSaveSpool("    우심 비자 카드\r\n");
	TextSaveSpool("--------------------------------\r\n");
	//Card number
	TextSaveSpool("카드번호     9445 4103 9533 2096\r\n");
	TextSaveSpool("유효 기간                2012/10\r\n");
	TextSaveSpool("--------------------------------\r\n");
	TextSaveSpool("거 래 일 자           2011/04/11\r\n");
	TextSaveSpool("거 래 종 류       [신용거래승인]\r\n");
	TextSaveSpool("단 말 번 호            123456789\r\n");
	TextSaveSpool("승 인 번 호            987654321\r\n");
	TextSaveSpool("결 제 금 액             50,000원\r\n");
	TextSaveSpool("--------------------------------\r\n");
	TextSaveSpool("서명: \r\n\r\n\r\n\r\n");
	TextSaveSpool("--------------------------------\r\n\r\n");
	
	/*
	TextSaveSpool("  SALES  SLIP\n");
	TextSaveSpool("--------------------------------\n");
	//Company
	TextSaveSpool("MERCHANT NAME      Woosim Coffee\n");
	//Reg Number
	TextSaveSpool("MASTER                LEE IL BOK\n");
	//Address
	TextSaveSpool("ADDRESS\n #501, DaerungTechnotown3th 448,\n  Gasan-dong, Geumchun-gu, Seoul\n  Korea\n");
	//Tel
	TextSaveSpool("HELP DESK       (+82-2)2107-3714\n");
	TextSaveSpool("--------------------------------\n\n");
	TextSaveSpool("        WOOSIM  CARD \n");
	TextSaveSpool("--------------------------------\n");
	TextSaveSpool("CARD NO.     4428-8819-0118-****\n");
	TextSaveSpool("EXPIRY                   2012/10\n");
	TextSaveSpool("--------------------------------\n");
	TextSaveSpool("TRANS. YEAR & DATE   2008/04/15\n");
	TextSaveSpool("TRANS CLASS             [Credit]\n");
	TextSaveSpool("TERMINAL ID.           123456789\n");
	TextSaveSpool("APPROVAL NO.           987654321\n");
	TextSaveSpool("AMOUNT                   500.00$\n");
	TextSaveSpool("--------------------------------\n");
	TextSaveSpool("SIGNATURE: \n\n");
	TextSaveSpool("--------------------------------\n\n");
	*/
			
    PrintSpool();
}

//Button Image
void CMFCDlg::OnBnClickedButton5()
{
	if(PathFileExists(_T("./woosim.bmp")))
	{
		InitPrinterStatus();

		//Normal BMP file print
		TextSaveSpool("Print Bmp file \"woosim.bmp\"");	PrintData();
		NormalBmpSaveSpool("./woosim.bmp");
		PrintLineFeed(2);

		//BMP file print using Compressed algorithm
		TextSaveSpool("Print Bmp file using compressed algorithm");	PrintData();
		CompressedBmpSaveSpool("./woosim.bmp");
		PrintLineFeed(2);

		//Print pre-download image.
		TextSaveSpool("Print pre-downloaded image file #0");	PrintData();
		LoadLogoSaveSpool(0);	PrintData();

		PrintSpool();
	}
	else
		AfxMessageBox(_T("\"woosim.bmp\" is not found!"));
}

//Button 1D barcode
void CMFCDlg::OnBnClickedButton6()
{
	InitPrinterStatus();
	TextSaveSpool("UPCA\r\n");
	OneDimensionBarcodeSaveSpool(UPCA, 2, 100, true, "012100000642"); PrintData();

	TextSaveSpool("UPCE\r\n");
	OneDimensionBarcodeSaveSpool(UPCE, 2, 100, true, "065100004328"); PrintData();

	TextSaveSpool("EAN13\r\n");
	OneDimensionBarcodeSaveSpool(EAN13, 2, 100, true, "123456478901"); PrintData();

	TextSaveSpool("EAN8\r\n");
	OneDimensionBarcodeSaveSpool(EAN8, 2, 100, true, "12345678"); PrintData();

	TextSaveSpool("CODE39\r\n");
	OneDimensionBarcodeSaveSpool(CODE39, 2, 100, true, "12345678901"); PrintData();

	TextSaveSpool("ITF\r\n");
	OneDimensionBarcodeSaveSpool(ITF, 2, 100, true, "123456"); PrintData();

	TextSaveSpool("CODABAR\r\n");
	OneDimensionBarcodeSaveSpool(CODABAR, 2, 100, true, "123456"); PrintData();

	TextSaveSpool("CODE93\r\n");
	OneDimensionBarcodeSaveSpool(CODE93, 2, 100, true, "12345678901"); PrintData();

	TextSaveSpool("CODE128\r\n");
	OneDimensionBarcodeSaveSpool(CODE128, 2, 100, true, "12345678901"); PrintData();

	PrintSpool();
}

//Button 2D barcode
void CMFCDlg::OnBnClickedButton7()
{
		InitPrinterStatus();

	TextSaveSpool("PDF417");
	PrintData();
	PDF417SaveSpool(2,2,2,2,"0123456789",false);
	PrintData();

	TextSaveSpool("DataMatrix");
	PrintData();
	DataMatrixSaveSpool(36,36,2,"0123456789");
	PrintLineFeed(1);

	TextSaveSpool("QR Code");
	PrintData();
	QRCodeSaveSpool(0,'H',3,"0123456789");
	PrintDotFeed(30);
	
	TextSaveSpool("Micro PDF417");
	PrintData();
	MicroPDF417SaveSpool(2,1,0,2,"01234567",false);
	PrintDotFeed(30);

	TextSaveSpool("Truncated PDF417");
	PrintData();
	TruncatedPDF417SaveSpool(2,2,2,2,"0123456789",false);
	PrintData();

	TextSaveSpool("Maxicode");
	PrintData();
	MaxicodeSaveSpool(4,"0123456789");
	PrintData();

	PrintSpool();
}

//Button Get Printer status
void CMFCDlg::OnBnClickedButton11()
{
	GetPrinterStatus(1000);
	//GetPrinterStatusEx(1000);	
}

//Button Get Printer model name & MCU ver.
void CMFCDlg::OnBnClickedButton8()
{
	GetPrinterModelName();
	GetFirmwareVersion();
}

//Button Print page mode with complex data
void CMFCDlg::OnBnClickedButton10()
{
	InitPageMode(0,0,_2INCH,700);
	SetTextStyle(false,true,1,1,false);
	TextSaveSpool("Woosim Cafe\r\n");

	SetTextStyle(false,false,0,0,false);
	TextSaveSpool("Coffee, tea and bread\r\n");
	Page_DotFeed(15);
	SetFontSize(1);
	Page_SetPosition(277,105);
	TextSaveSpool("2015-01-27\r\n");
	SetFontSize(0);

	Page_SetPosition(290,5);
	QRCodeSaveSpool(0,'H',2,"www.woosim.com/english");
	
	Page_DrawBox(0,130,_2INCH,0,2);
	Page_DotFeed(5);
	TextSaveSpool(" #      Item      Num    Charge\r\n");
	TextSaveSpool(" 1      Latte      1     $ 3.35");	Page_Newline();
	TextSaveSpool(" 2  House Coffee   2     $ 3.98");	Page_Newline();
	TextSaveSpool(" 3       Tea	       1     $ 1.95");	Page_DotFeed(10);
	Page_DrawBox(0,270,_2INCH,0,2);	Page_Newline();

	Page_DrawBox(0,310,115,0,2); Page_DrawBox(260,310,124,0,2); Page_DotFeed(15);
	Page_SetPosition(123,300);
	TextSaveSpool("Credit Card\r\n");

	TextSaveSpool("Number:         ");
	SetFontSize(1);
	TextSaveSpool("6688-9988-6644-3311");	Page_Newline();
	SetFontSize(0);
	TextSaveSpool("Payment:                $ 9.50 ");	Page_Newline();

	Page_DrawBox(0,400,120,0,2);	Page_DrawBox(250,400,134,0,2);Page_DotFeed(15);
	Page_SetPosition(145,390);
	TextSaveSpool("Payment\r\n");

	TextSaveSpool("Price:                  $ 9.28");	Page_Newline();
	TextSaveSpool("Tax:                    $ 0.22");	Page_Newline();

	Page_DrawBox(0,490,_2INCH,0,2);	Page_DotFeed(15);
	TextSaveSpool("Total:                  $ 9.50");	Page_Newline();
	TextSaveSpool("Credit Card:            $ 9.50");	Page_Newline();

	Page_SetPosition(40,580);
	OneDimensionBarcodeSaveSpool(CODE128,2,50,TRUE,"20150127123456789");
	Page_LineFeed(2);

	Page_Print_StandardMode();
	PrintSpool();
}

//Button Card read mode start
void CMFCDlg::OnBnClickedButton12()
{
	int modeSelect = 0;

	//MSR sample is based 12Track magnetic card
	switch(m_msrCtrl.GetCurSel())
	{
	case 0:
		modeSelect = 0;//Read 1T. If 23T card, read 2T.
		break;
	
	case 1:
		modeSelect = 1;//Read 2T. If 23T card, read 3T.
		break;
	
	case 2:
		modeSelect = 4;//Read 3T. It only use for 123T.
		break;
	
	case 3:
		modeSelect = 2;//Read 12T. If 23T card, read 23T.
		break;
	
	case 4:
		modeSelect = 3;//Read 123T. It only use for 123T.
		break;
	}

	EnterMSRMode(modeSelect);
}

//Button Card read mode cancel
void CMFCDlg::OnBnClickedButton15()
{
	CancelMSRMode();
}

void CMFCDlg::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	OnBnClickedButton2();
	OnCancel();
}

LRESULT CMFCDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
	if(message == ::RegisterWindowMessage(MSG_RECEIVE_CHECK))
	{
		WPARAM chk;
		UINT length;

		chk = (wParam>>32);
		length = LOWORD(wParam);

		switch (chk)
		{

		case STATUS_ANSWER:
			BYTE *tempBuff;
			tempBuff = (BYTE*)lParam;
			m_strMsg = _T("STATUS_ANSWER");
			m_strReceivedata.Format(_T("%02X"), tempBuff[0]);
			break;

		case DATA:		
			CString temp;
			temp = _T("");
			strDataHex =  _T("");
			BYTE *data = (BYTE *)lParam;
			m_strMsg = _T("DATA");

			strDataHex.Format(_T("Receive %dbyte\r\n"), length ); 
			for(int i=0; i < length; i++)
			{
				if(i%32 == 0)
					strDataHex = strDataHex + _T("\r\n");
				temp.Format(_T("%c"),data[i]);
				strDataHex = strDataHex + temp;
			}

			m_strReceivedata = strDataHex;	

			break;
		}
		UpdateData(FALSE);
	}
	return CDialog::DefWindowProc(message, wParam, lParam);
}

void CMFCDlg::OnBnClickedButton9()
{
	// TODO: Add your control notification handler code here
	SetFontForTTF("WSTTFL.ttf");
	PrintSpoolForTTF("Woosim System Inc.",10,18);
	PrintSpool();
}
