// Card123Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "Card123.h"
#include "Card123Dlg.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CWoosimPrinter woosimprinter;
/////////////////////////////////////////////////////////////////////////////
// CCard123Dlg dialog

CCard123Dlg::CCard123Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCard123Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCard123Dlg)
	m_strCardNo = _T("");
	m_strValidDate = _T("");
	m_strStatus = _T("");
	m_strMsg = _T("");
	m_strReceiveData = _T("");
	m_strIP = _T("192.168.0.7");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCard123Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCard123Dlg)
	DDX_Control(pDX, IDC_CHECK_TCPIP, m_chkCtrlTcpip);
	DDX_Control(pDX, IDC_COMBO2, m_cboCtrlProtocol);
	DDX_Control(pDX, IDC_COMBO1, m_cboCtrlSetPort);
	DDX_Control(pDX, IDC_BUTTON_ASCII, m_btnCtrlAscii);
	DDX_Control(pDX, IDC_BUTTON_HEX, m_btnCtrlHex);
	DDX_Control(pDX, IDC_COMBO_BAUD_RATE, m_cboCtrlBaud);
	DDX_Text(pDX, IDC_STATIC_CARD_NO, m_strCardNo);
	DDX_Text(pDX, IDC_STATIC_VALID_DATE, m_strValidDate);
	DDX_Text(pDX, IDC_STATIC_PORT_STATUS, m_strStatus);
	DDX_Text(pDX, IDC_STATIC_PRINTER_MSG, m_strMsg);
	DDX_Text(pDX, IDC_EDIT_RECEIVE_DATA, m_strReceiveData);
	DDX_Text(pDX, IDC_EDIT_IP, m_strIP);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCard123Dlg, CDialog)
	//{{AFX_MSG_MAP(CCard123Dlg)
	ON_BN_CLICKED(IDC_BUTTON_PRINT, OnButtonPrint)
	ON_BN_CLICKED(IDC_BUTTON_CARD_CANCEL, OnButtonCardCancel)
	ON_BN_CLICKED(IDC_BUTTON_CARD1, OnButtonCard1)
	ON_BN_CLICKED(IDC_BUTTON_CARD2, OnButtonCard2)
	ON_BN_CLICKED(IDC_BUTTON_RE_CONNECT, OnButtonReConnect)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BUTTON_ASCII, OnButtonAscii)
	ON_BN_CLICKED(IDC_BUTTON_HEX, OnButtonHex)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON_2D_BAR, OnButton2dBar)
	ON_BN_CLICKED(IDC_BUTTON_KOR_PRINT, OnButtonKorPrint)
	ON_BN_CLICKED(IDC_BUTTON_CLOSE, OnButtonClose)
	ON_BN_CLICKED(IDC_BUTTON_1D_BAR2, OnButton1dBar2)

	//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCard123Dlg message handlers

BOOL CCard123Dlg::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
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here
	m_cboCtrlBaud.SetCurSel(5);
	m_cboCtrlSetPort.SetCurSel(7);
	m_cboCtrlProtocol.SetCurSel(0);
	m_chkCtrlTcpip.SetCheck(FALSE);
	m_btnCtrlHex.EnableWindow(FALSE);
	m_btnCtrlHex.ShowWindow(SW_HIDE);
	m_btnCtrlAscii.EnableWindow(FALSE);
	m_btnCtrlAscii.ShowWindow(SW_HIDE);	

	UpdateData(FALSE);

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



void CCard123Dlg::OnButtonCardCancel() 
{
	// TODO: Add your control notification handler code here
	m_strMsg = _T("");
	m_strCardNo = _T("");
	m_strValidDate = _T("");
	m_strReceiveData = _T("");
	m_btnCtrlHex.EnableWindow(FALSE);
	m_btnCtrlHex.ShowWindow(SW_HIDE);
	m_btnCtrlAscii.EnableWindow(FALSE);
	m_btnCtrlAscii.ShowWindow(SW_HIDE);	
	UpdateData(FALSE);
	woosimprinter.CardCancel();
}

void CCard123Dlg::OnButtonCard1() 
{
	// TODO: Add your control notification handler code here
	m_strMsg = _T(""); 
	m_strCardNo = _T("");
	m_strValidDate = _T("");
	m_strReceiveData = _T("");
	m_btnCtrlHex.EnableWindow(FALSE);
	m_btnCtrlHex.ShowWindow(SW_HIDE);
	m_btnCtrlAscii.EnableWindow(FALSE);
	m_btnCtrlAscii.ShowWindow(SW_HIDE);	
	UpdateData(FALSE);
	woosimprinter.CardRead(FALSE);
}



void CCard123Dlg::OnButtonCard2() 
{
	// TODOx: Add your control notification handler code here
	m_strMsg = _T("");
	m_strCardNo = _T("");
	m_strValidDate = _T("");
	m_strReceiveData = _T("");
	m_btnCtrlHex.EnableWindow(FALSE);
	m_btnCtrlHex.ShowWindow(SW_HIDE);
	m_btnCtrlAscii.EnableWindow(FALSE);
	m_btnCtrlAscii.ShowWindow(SW_HIDE);	
	UpdateData(FALSE);
	woosimprinter.CardRead(TRUE);
}


void CCard123Dlg::OnButtonReConnect() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);	
	m_strStatus = _T("");
	UpdateData(FALSE);

	//Close Port
	woosimprinter.ClosePrinter();

	int BaudRate;
	CString SetPort;
	switch (m_cboCtrlSetPort.GetCurSel())
	{
	
		case 0 : SetPort = _T("BSP2:");
			break;
		case 1 : SetPort = _T("COM1:");
			break;
		case 2 : SetPort = _T("COM2:");
			break;
		case 3 : SetPort = _T("COM3:");
			break;
		case 4 : SetPort = _T("COM4:");
			break;
		case 5 : SetPort = _T("COM5:");
			break;
		case 6 : SetPort = _T("COM6:"); 
			break;
		case 7 : SetPort = _T("COM7:");
			break;
		case 8 : SetPort = _T("COM8:");
			break;
	
		case 9 : SetPort = _T("COM9:");
			break;
		case 10 : SetPort = _T("COM10:");
			break;
	}
	switch (m_cboCtrlBaud.GetCurSel())
	{
	
		case 0 : BaudRate = 2400;
			break;
		case 1 : BaudRate = 4800;
			break;
		case 2 : BaudRate = 9600;
			break;
		case 3 : BaudRate = 19200;
			break;
		case 4 : BaudRate = 38400;
			break;
		case 5 : BaudRate = 57600; 
			break;
		case 6 : BaudRate = 115200; 
			break;
	}


	if(m_chkCtrlTcpip.GetCheck())
	{
		
		switch(m_cboCtrlProtocol.GetCurSel())
		{
			case 0 :
				intReturnValue = woosimprinter.InitWlanPrinter(m_strIP.GetBuffer(m_strIP.GetLength()),1470, 3000, FALSE);
				break;
			case 1 :
				intReturnValue = woosimprinter.InitWlanPrinter(m_strIP.GetBuffer(m_strIP.GetLength()),1470, 3000, TRUE);
				break;
		}
		switch (intReturnValue)
		{


			case 1 : 
				m_strStatus = _T("Success");
				break;
			case -1 : 
				m_strStatus = _T("Socket Error");
				break;
			
			case -2 : 
				m_strStatus = _T("Connect Fail");
				break;
			case -3 : 
				m_strStatus =_T("Already Connected");
				break;
			case -5 : 
				m_strStatus =_T("No response from printer");
				break;	
			default :
				m_strStatus.Format(_T("%d"),intReturnValue);
				break;		
		}

	}
	else
	{
		switch (m_cboCtrlProtocol.GetCurSel())
		{
			case 0 : 
				intReturnValue= woosimprinter.InitPrinter(SetPort.GetBuffer(SetPort.GetLength()) , BaudRate,FALSE);
				break;
			case 1 :
				intReturnValue= woosimprinter.InitPrinter(SetPort.GetBuffer(SetPort.GetLength()), BaudRate,TRUE);
				break;
		}
		switch (intReturnValue)
		{
			case 1 : 
				m_strStatus = _T("Success");
				break;
			case -1 : 
				m_strStatus = _T("Already opened");
				break;
			case -2 : 
				m_strStatus =_T("Unable to open the port");
				break;
			case -3 : 
				m_strStatus = _T("Unable to configure the serial port");
				break;
			case -4 : 
				m_strStatus =_T("Unable to set the timeout parameters");
				break;		
			case -5 : 
				m_strStatus =_T("No response from printer");
			default :
				m_strStatus.Format(_T("%d"),intReturnValue);
				break;		
		}

	}

	UpdateData(FALSE);
}


void CCard123Dlg::OnOK() 
{
	// TODO: Add extra validation here
	woosimprinter.ClosePrinter();
	CDialog::OnOK();
}

void CCard123Dlg::OnDestroy() 
{
	CDialog::OnDestroy();
	woosimprinter.ClosePrinter();
}

void CCard123Dlg::OnButtonAscii() 
{
	// TODO: Add your control notification handler code here
	m_btnCtrlAscii.EnableWindow(FALSE);
	m_btnCtrlAscii.ShowWindow(SW_HIDE);
	m_btnCtrlHex.EnableWindow(TRUE);
	m_btnCtrlHex.ShowWindow(SW_SHOW);
	m_strReceiveData = strDataAscii;
	UpdateData(FALSE);
}
void CCard123Dlg::OnButtonHex() 
{
	// TODO: Add your control notification handler code here
	m_btnCtrlHex.EnableWindow(FALSE);
	m_btnCtrlHex.ShowWindow(SW_HIDE);
	m_btnCtrlAscii.EnableWindow(TRUE);
	m_btnCtrlAscii.ShowWindow(SW_SHOW);
	m_strReceiveData = strDataHex;
	UpdateData(FALSE);
}


void CCard123Dlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	BYTE Card23[]  = {0x1b,0x4d,0x45};
   	woosimprinter.ControlCommand(Card23, 3);
	woosimprinter.PrintSpool();
}

void CCard123Dlg::OnButton2dBar() 
{
	
	// TODO: Add your control notification handler code here

	//Printer initialization ESC @
	BYTE Print_init[] ={ 0x1b, 0x40 };
	woosimprinter.ControlCommand(Print_init, 2);
	
	//Barcode print 
	BYTE FF[] = { 0x0c };
	
	woosimprinter.SaveSpool(_T("PDF417\r\n"), 0, 0);
	
	//Select 2D barcode type GS Z  n (0 = PDF417 / 1 = DATAMATRIX / 2 = QR-CODE / 3 = Micro PDF417 / 4 = Trunc PDF417)
	BYTE GS_Z[] = { 0x1d, 0x5a, 0x00 };
	woosimprinter.ControlCommand(GS_Z, 3);
	
	BYTE GS_W[] = { 0x1d, 0x77, 0x03 };
	woosimprinter.ControlCommand(GS_W, 3);
	
	
	//Print 2D barcode
	BYTE ESC_Z[] = {0x1b, 0x5a,
					0x01 , 0x00, 0X03, 0x0f, 0x00, 
					0x41,0x42,0x43,0x44,0x45,0x31,0x32,0x33,0x34,0x35,0x61,0x62,0x63,0x64,0x65};
	woosimprinter.ControlCommand(ESC_Z, 22);
	
	woosimprinter.ControlCommand(FF, 1);
	
	BYTE LF[] ={ 0x0a };
	woosimprinter.ControlCommand(LF, 1);
	
	
	woosimprinter.SaveSpool(_T("Micro PDF417\r\n"), 0, 0);
	//Select 2D barcode type GS Z  n (0 = PDF417 / 1 = DATAMATRIX / 2 = QR-CODE / 3 = Micro PDF417 / 4 = Trunc PDF417)
	BYTE GS_Z1[] = { 0x1d, 0x5a, 0x03 };
	woosimprinter.ControlCommand(GS_Z1, 3);
	
	woosimprinter.ControlCommand(GS_W, 3);
	
	woosimprinter.ControlCommand(ESC_Z, 22);
	
	woosimprinter.ControlCommand(LF, 1);
	
	woosimprinter.SaveSpool(_T("Truncated PDF417\r\n"), 0, 0);
	//Select 2D barcode type GS Z  n (0 = PDF417 / 1 = DATAMATRIX / 2 = QR-CODE / 3 = Micro PDF417 / 4 = Trunc PDF417)
	BYTE GS_Z2[] = { 0x1d, 0x5a, 0x04 };
	woosimprinter.ControlCommand(GS_Z2, 3);
	
	woosimprinter.ControlCommand(GS_W, 3);
	
	woosimprinter.ControlCommand(ESC_Z, 22);
	
	woosimprinter.ControlCommand(LF, 1);
	
	woosimprinter.SaveSpool(_T("DATAMAREIX\r\n"), 0, 0);
	//Select 2D barcode type GS Z  n (0 = PDF417 / 1 = DATAMATRIX / 2 = QR-CODE / 3 = Micro PDF417 / 4 = Trunc PDF417)
	BYTE GS_Z3[] = { 0x1d, 0x5a, 0x01 };
	woosimprinter.ControlCommand(GS_Z3, 3);
		
	//Print 2D barcode
	BYTE ESC_Z1[] = {0x1b, 0x5a,
					 0x00 , 0x00, 0X03, 0x0f, 0x00, 
					 0x41,0x42,0x43,0x44,0x45,0x31,0x32,0x33,0x34,0x35,0x61,0x62,0x63,0x64,0x65};
	woosimprinter.ControlCommand(ESC_Z1, 22);
	
	woosimprinter.ControlCommand(LF, 1);
	
	woosimprinter.SaveSpool(_T("QR-CODE\r\n"), 0, 0);
	//Select 2D barcode type GS Z  n (0 = PDF417 / 1 = DATAMATRIX / 2 = QR-CODE / 3 = Micro PDF417 / 4 = Trunc PDF417)
	BYTE GS_Z4[] = { 0x1d, 0x5a, 0x02 };
	woosimprinter.ControlCommand(GS_Z4, 3);
	
	
	//Print 2D barcode
	BYTE ESC_Z2[] = {0x1b, 0x5a,
					 0x00 , 0x4d, 0X03, 0x0f, 0x00, 
					 0x41,0x42,0x43,0x44,0x45,0x31,0x32,0x33,0x34,0x35,0x61,0x62,0x63,0x64,0x65};
	woosimprinter.ControlCommand(ESC_Z2, 22);
	
	woosimprinter.ControlCommand(LF, 1);
    woosimprinter.PrintSpool(1);
}

void CCard123Dlg::OnButtonKorPrint() 
{
	// TODO: Add your control notification handler code here
	PrtForm1();

}

void CCard123Dlg::PrtForm1()
{

	m_strMsg = _T("");
	UpdateData(FALSE);
	UpdateData();

	CString strTmp;
	
	//print init
	BYTE init[]={0x1b,0x40};
	woosimprinter.ControlCommand(init, 2);
	
	//Title
	woosimprinter.SaveSpool( _T("  SALES  SLIP\r\n"), 3, TRUE);
	woosimprinter.SaveSpool( _T("--------------------------------\r\n"), 0,FALSE );
	
	//Company
	woosimprinter.SaveSpool( _T("MERCHANT NAME      Woosim Coffee\r\n"), 0, TRUE);
	
	//Reg Number
	woosimprinter.SaveSpool( _T("MASTER                LEE IL BOK\r\n"), 0 ,FALSE);
	
	//Address
	woosimprinter.SaveSpool( _T("ADDRESS\r\n #501, DaerungTechnotown3th 448,\r\n  Gasan-dong, Geumchun-gu, Seoul\r\n  Korea\r\n"), 0,0 );
	
	//Tel
	woosimprinter.SaveSpool( _T("HELP DESK       (+82-2)2107-3714\r\n"), 0 ,FALSE);
    woosimprinter.SaveSpool( _T("--------------------------------\r\n\r\n"), 0 ,FALSE);
	woosimprinter.SaveSpool( _T("        WOOSIM  CARD \r\n"), 1 ,0);
	woosimprinter.SaveSpool( _T("--------------------------------\r\n"), 0 ,FALSE);
	
	//Card number
	strTmp.Format( _T("CARD NO.     %s\r\n"), m_strCardNo );
	woosimprinter.SaveSpool( strTmp.GetBuffer(strTmp.GetLength())  , 0, TRUE );
	

	strTmp.Format( _T("EXPIRY     %s\r\n"), m_strValidDate );
	woosimprinter.SaveSpool( strTmp.GetBuffer(strTmp.GetLength())  , 0, TRUE );
	
	woosimprinter.SaveSpool( _T("--------------------------------\r\n"), 0,FALSE );
	
	COleDateTime oltTime = COleDateTime::GetCurrentTime();
	strTmp.Format( _T("TRANS. YEAR & DATE    %04d/%02d/%02d\r\n"), oltTime.GetYear(), oltTime.GetMonth(), oltTime.GetDay());
	woosimprinter.SaveSpool( strTmp.GetBuffer(strTmp.GetLength()), 0,FALSE);
	
	strTmp = _T("TRANS CLASS             [Credit]\r\n");
	woosimprinter.SaveSpool( strTmp.GetBuffer(strTmp.GetLength()), 0 ,FALSE);
	
	strTmp = _T("TERMINAL ID.           123456789\r\n");
	woosimprinter.SaveSpool( strTmp.GetBuffer(strTmp.GetLength()), 0 ,FALSE);   
	
	strTmp = _T("APPROVAL NO.           987654321\r\n");
	woosimprinter.SaveSpool( strTmp.GetBuffer(strTmp.GetLength()), 0 ,FALSE);
	
	strTmp = _T("AMOUNT                   500.00$\r\n");
	woosimprinter.SaveSpool( strTmp.GetBuffer(strTmp.GetLength()), 0 ,FALSE);
	
	woosimprinter.SaveSpool( _T("--------------------------------\r\n"), 0 ,FALSE);
	
	strTmp = _T("SIGNATURE: \r\n\r\n\r\n\r\n\r\n");
	woosimprinter.SaveSpool( strTmp.GetBuffer(strTmp.GetLength()), 0,FALSE);
	
	woosimprinter.SaveSpool( _T("--------------------------------\r\n"), 0 ,FALSE);

	woosimprinter.PrintSpool();


}

LRESULT CCard123Dlg::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))
	{
		switch (wParam)
		{
			
			case STATUS_ANSWER:
				m_strMsg = _T("STATUS_ANSWER");
	  			m_strReceiveData.Format(_T("H%02x"), (BYTE)lParam);
				break;
			case NACK:
				m_strMsg = _T("NACK");
				break;
			case EOT:
				m_strMsg = _T("EOT");
				break;
			case ETX:
				m_strMsg = _T("ETX");
				break;
			case MSR_FAIL:
				m_strMsg = _T("MSR_FAIL");
				break;
			case CAN:
				m_strMsg = _T("CAN");
				break;
			case DATA:
				CString data,temp;
				data = _T("");
				temp = _T("");
				strDataHex =  _T("");
				strDataAscii =  _T("");

		
				switch (m_cboCtrlProtocol.GetCurSel())
				{
					case 0:
						data      = (LPCSTR)(unsigned char*)lParam;
						m_strCardNo.Format(_T("%s %s %s %s"), data.Mid(4,4),data.Mid(8,4),data.Mid(12,4),data.Mid(16,4)); 
						m_strValidDate.Format(_T("%s Month / %s Year"),data.Mid(23,2),data.Mid(21,2)); 
						m_strMsg = _T("DATA");
						break;
					case 1 :
						data      = (LPCSTR)(unsigned char*)lParam;
						m_strCardNo.Format(_T("%s %s %s %s"), data.Mid(1,4),data.Mid(5,4),data.Mid(9,4),data.Mid(13,4)); 
						m_strValidDate.Format(_T("%s Month / %s Year"),data.Mid(20,2),data.Mid(18,2)); 
						m_strMsg = _T("DATA");
						break;
				}
				
				//Hex  
				strDataHex.Format(_T("Receive %dbyte"),data.GetLength() ); 
				for(int i=0; i < data.GetLength(); i++)
				{
					
					if(i%8==0)
					{	
						temp.Format(_T("%s\r\n"),strDataHex); 
						strDataHex = temp ;
					}
						temp.Format(_T("%sH%02x "),strDataHex,data[i]); 
						strDataHex = temp;
				
				}
				
				m_strReceiveData = strDataHex;
				
				//Ascii 
				strDataAscii.Format(_T("Receive %dbyte"),data.GetLength() ); 
				for(i=0; i < data.GetLength(); i++)
				{
					
					if(i%24==0)
					{	
						temp.Format(_T("%s\r\n"),strDataAscii); 
						strDataAscii = temp ;
					}
						temp.Format(_T("%s%c"),strDataAscii,data[i]); 
						strDataAscii = temp;
				
				}
				m_btnCtrlAscii.EnableWindow(TRUE);
				m_btnCtrlAscii.ShowWindow(SW_SHOW);
				m_btnCtrlHex.EnableWindow(FALSE);
				m_btnCtrlHex.ShowWindow(SW_HIDE);


				break;
			
		}
		UpdateData(FALSE);

	}

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

void CCard123Dlg::OnButtonClose() 
{
	// TODO: Add your control notification handler code here
	m_strStatus = _T("");
	UpdateData(FALSE);
	woosimprinter.ClosePrinter();
}




void CCard123Dlg::OnButtonPrint() 
{
	// TODO: Add your control notification handler code here
	m_strMsg = _T("");
	UpdateData(FALSE);
	UpdateData();
	CString strTmp;
	
	//printer init
	BYTE Print_init[]={0x1b,0x40};
	woosimprinter.ControlCommand(Print_init, 2);
	
	//page mode
	BYTE Pagemode[]={0x1b,0x4c};
	woosimprinter.ControlCommand(Pagemode, 2);
	
	//page area setting
	//1inch printer width : 192dot = 0xC0
	//2inch printer width : 384dot = 0x180
	//3inch printer width : 576dot = 0x240
	//4inch printer width : 832dot = 0x340
	
	
	//page area set
	//3inch printer width : 576dot = 0x240
	//Page Size setting ESC W   384x176x2 bitmap
	// 1dot = 0.0125cm  
	// calculation : X : 0x180 => 384(decimal,2inch width)  
	//	              Y : 0xa7  => 167(decimal) => 167*0.0125 = 2.08cm
	BYTE Pagesize[]={0x1b,0x57, 0x00,0x00, 0x00,0x00, 0x80,0x01,0xa7,0x00};
	woosimprinter.ControlCommand(Pagesize, 10);
	
	//page area clear
	BYTE can[]={0x18};
	woosimprinter.ControlCommand(can, 1);
	
	//bitmap
	woosimprinter.BmpSaveSpool(_T("\\woosim.bmp"),0,0);
	
	//page area print
	BYTE FF[]={0x0c};
	woosimprinter.ControlCommand(FF, 1);
	
	
	woosimprinter.PrintSpool();
}

void CCard123Dlg::OnButton1dBar2() 
{
	// TODO: Add your control notification handler code here
	m_strMsg = _T("");
	UpdateData(FALSE);
	UpdateData();
	CString strTmp;
	
	///////////////////////
	// Barcode    
	//
	//barcode type	

	//#define UPCA									65
	//#define UPCE									66
	//#define EAN13									67
	//#define EAN8									68
	//#define CODE39									69
	//#define ITF										70
	//#define CODABAR									71
	//#define CODE93									72
	//#define CODE128									73
	
	//printer width
	//#define _2INCH									384
	//#define _3INCH									576
	//#define _4INCH									832
	
	//Printer initialization ESC @
	BYTE Print_init[] = { 0x1b, 0x40 };
	woosimprinter.ControlCommand(Print_init, 2);
	
	//Barcode Print	
	woosimprinter.BarcodeSaveSpool(UPCA, 2, 100, true, _T("12345678901"), _2INCH, 200, 50);
	woosimprinter.BarcodeSaveSpool(UPCE, 2, 100, true, _T("02345678901"), _2INCH, 200, 50);
	woosimprinter.BarcodeSaveSpool(EAN13, 2, 100, true, _T("12345678901"), _2INCH, 200, 100);
	woosimprinter.BarcodeSaveSpool(EAN8, 2, 100, true, _T("12345678"), _2INCH, 200, 150);
	woosimprinter.BarcodeSaveSpool(CODE39, 2, 100, true, _T("12345678901"), _2INCH, 200, 200);
	woosimprinter.BarcodeSaveSpool(ITF, 2, 100, true, _T("123456"), _2INCH, 200, 250);
	woosimprinter.BarcodeSaveSpool(CODABAR, 2, 100, true, _T("123456"), _2INCH, 200, 0);
	woosimprinter.BarcodeSaveSpool(CODE93, 2, 100, true, _T("12345678901"), _2INCH, 200, 0);
	woosimprinter.BarcodeSaveSpool(CODE128, 2, 100, true, _T("12345678901"), _2INCH, 200, 0);
	
	woosimprinter.PrintSpool(1);

	///////////////////////////////////////////////////////////////
	//Barcode command
	//
	/*
	//Printer initialization ESC @
	BYTE Print_init[]={0x1b,0x40};
	woosimprinter.ControlCommand(Print_init, 2);
	
	//print 
	BYTE FF[]={0x0c};
		
	//Barcode height GS k
	BYTE GS_h[] = {0x1d, 0x68, 0x44};
	woosimprinter.ControlCommand(GS_h,3);
	
	//barcode width GS w
	BYTE GS_w[] = {0x1d, 0x77, 0x02};
	woosimprinter.ControlCommand(GS_w,3);
	
	//HRI  character print  GS H
	BYTE GS_H[] = {0x1d, 0x48, 0x01};
	
	
	woosimprinter.SaveSpool(_T("UPC-A\r\n"),0);
	BYTE GS_k41[] = {0x1d, 0x6b, 0x41 , 0x0b, 0X30, 0x31 , 0x32 , 0x33 , 0x34 , 0x35 , 0x36 , 0x37 , 0x38 , 0x39, 0x30};
	woosimprinter.ControlCommand(GS_k41,15);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);
	
	
	woosimprinter.SaveSpool(_T("UPC-E\r\n"),0);	
	BYTE GS_k42[] = {0x1d, 0x6b, 0x42 , 0x0b, 0x30, 0X30, 0x31 , 0x32 , 0x33 , 0x34 , 0x35 , 0x36 , 0x37 , 0x38 , 0x39};
	woosimprinter.ControlCommand(GS_k42,15);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);
	
	
	woosimprinter.SaveSpool(_T("EAN13\r\n"),0);
	BYTE GS_k43[] = {0x1d, 0x6b, 0x43 , 0x0b, 0x31 , 0x32 , 0x33 , 0x34 , 0x35 , 0x36 , 0x37 , 0x38 , 0x39, 0x30, 0x31};
	woosimprinter.ControlCommand(GS_k43,15);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);
	
	
	woosimprinter.SaveSpool(_T("EAN8 Data 7\r\n"),0);
	BYTE GS_k44[] = {0x1d, 0x6b, 0x44 , 0x07, 0x31 , 0x32 , 0x33 , 0x34 , 0x35 , 0x36 ,0x37};
	woosimprinter.ControlCommand(GS_k44,11);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);
	
	
	woosimprinter.SaveSpool(_T("code39 Even\r\n"),0);
	BYTE GS_k45[] = {0x1d, 0x6b, 0x45 , 0x0b, 0x41, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x5a};
	woosimprinter.ControlCommand(GS_k45,15);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);
	
	
	woosimprinter.SaveSpool(_T("ITF\r\n"),0);
	BYTE GS_k46[] = {0x1d, 0x6b, 0x46 , 0x06, 0x31 , 0x32 , 0x33 , 0x34 , 0x35 , 0x36};
	woosimprinter.ControlCommand(GS_k46,10);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);
	
	
	woosimprinter.SaveSpool(_T("codabar\r\n"),0);
	BYTE GS_k47[] = {0x1d, 0x6b, 0x47 , 0x0b, 0x41, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x44};
	woosimprinter.ControlCommand(GS_k47,15);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);
	
	
	woosimprinter.SaveSpool(_T("code93\r\n"),0);
	BYTE GS_k48[] = {0x1d, 0x6b, 0x48 , 0x0b, 0x21, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,0x7d};
	woosimprinter.ControlCommand(GS_k48,15);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);


	woosimprinter.SaveSpool(_T("code128\r\n"),0);
	BYTE GS_k49[] = {0x1d, 0x6b, 0x49 , 0x0b, 0x21, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,0x7d};
	woosimprinter.ControlCommand(GS_k49,15);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);
	
	woosimprinter.PrintSpool();
	*/
}
