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

#include "stdafx.h"
#include "LabelPrinter.h"
#include "LabelPrinterDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CLabelPrinterDlg 대화 상자
CLabelPrinterDlg *pDlg;

CLabelPrinterDlg::CLabelPrinterDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLabelPrinterDlg::IDD, pParent)
	, m_nInterface(0)
	, m_nConnectionType(0)
	, m_strPort(_T(""))
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	pDlg = this;
}

void CLabelPrinterDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CLabelPrinterDlg, CDialog)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_RADIO3, &CLabelPrinterDlg::OnBnClickedRadio3)
	ON_BN_CLICKED(IDC_RADIO4, &CLabelPrinterDlg::OnBnClickedRadio4)
	ON_BN_CLICKED(IDC_RADIO5, &CLabelPrinterDlg::OnBnClickedRadio5)	
	ON_BN_CLICKED(IDC_RADIO6, &CLabelPrinterDlg::OnBnClickedRadio6)
	ON_BN_CLICKED(IDC_RADIO7, &CLabelPrinterDlg::OnBnClickedRadio7)
	ON_BN_CLICKED(IDC_BTN_DEVICE, &CLabelPrinterDlg::OnBnClickedBtnDevice)
	ON_BN_CLICKED(IDC_BTN_IMAGE, &CLabelPrinterDlg::OnBnClickedBtnImage)
	ON_BN_CLICKED(IDC_BTN_VECTOR, &CLabelPrinterDlg::OnBnClickedBtnVector)
	ON_BN_CLICKED(IDC_BTN_1D, &CLabelPrinterDlg::OnBnClickedBtn1d)
	ON_BN_CLICKED(IDC_BTN_2D, &CLabelPrinterDlg::OnBnClickedBtn2d)
	ON_BN_CLICKED(IDC_BTN_INFO, &CLabelPrinterDlg::OnBnClickedBtnInfo)
END_MESSAGE_MAP()


// CLabelPrinterDlg 메시지 처리기

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

	// TODO: 여기에 추가 초기화 작업을 추가합니다.
	pDevice = new CMPosControllerDevices();
	pLabelPrinter = new CMPosControllerLabelPrinter();

#if _DEBUG
	//set usb interface
 	CButton* pButton = (CButton*)GetDlgItem(IDC_RADIO5);
 	pButton->SetCheck(true); 

	pButton = (CButton*)GetDlgItem(IDC_RADIO6);
	pButton->SetCheck(true); 

	m_nInterface = MPOS_INTERFACE_USB;
	m_nConnectionType = MPOS_MODE_DEFAULT;
	GetDlgItem(IDC_IPADDRESS1)->ShowWindow(FALSE);
	GetDlgItem(IDC_EDIT2)->ShowWindow(TRUE);
	m_strPort = _T("");
#else
	CButton* pButton = (CButton*)GetDlgItem(IDC_RADIO3);
	pButton->SetCheck(true); 

	m_nInterface = MPOS_INTERFACE_ETHERNET;
	GetDlgItem(IDC_IPADDRESS1)->ShowWindow(TRUE);
	GetDlgItem(IDC_EDIT2)->ShowWindow(FALSE);
#endif

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

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

void CLabelPrinterDlg::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 CLabelPrinterDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


void CLabelPrinterDlg::OnBnClickedRadio3()
{
	m_nInterface = MPOS_INTERFACE_ETHERNET;
	GetDlgItem(IDC_IPADDRESS1)->ShowWindow(TRUE);
	GetDlgItem(IDC_IPADDRESS1)->SetWindowText(_T("192.168.0.10"));
	GetDlgItem(IDC_EDIT2)->ShowWindow(FALSE);
	UpdateData(FALSE);
}

void CLabelPrinterDlg::OnBnClickedRadio4()
{
	m_nInterface = MPOS_INTERFACE_BLUETOOTH;
	GetDlgItem(IDC_IPADDRESS1)->ShowWindow(FALSE);
	GetDlgItem(IDC_EDIT2)->ShowWindow(TRUE);
	m_strPort = "COM3";
	UpdateData(FALSE);
}

void CLabelPrinterDlg::OnBnClickedRadio5()
{
	m_nInterface = MPOS_INTERFACE_USB;
	GetDlgItem(IDC_IPADDRESS1)->ShowWindow(FALSE);
	GetDlgItem(IDC_EDIT2)->ShowWindow(TRUE);
	m_strPort = _T("");
	UpdateData(FALSE);
}

void CLabelPrinterDlg::OnBnClickedRadio6()
{
	m_nConnectionType = MPOS_MODE_DEFAULT;
}

void CLabelPrinterDlg::OnBnClickedRadio7()
{
	m_nConnectionType = MPOS_MODE_BYPASS;
}

void CLabelPrinterDlg::OnBnClickedBtnDevice()
{
	UpdateData(TRUE);
	if(m_nInterface == MPOS_INTERFACE_ETHERNET) GetDlgItemText(IDC_IPADDRESS1, m_strPort);
	pLabelPrinter->selectInterface(m_nInterface, m_strPort);
	pLabelPrinter->selectCommandMode(m_nConnectionType);
	long lResult = pLabelPrinter->openService();
	if(lResult == RES_ALREADY_OPEN)
		return;
	if(lResult != RES_SUCCESS)
	{
		CString strdata;
		strdata.Format(_T("Error Code = %d"), lResult);
		AfxMessageBox(strdata);		
		return ;
	}
	
	pLabelPrinter->drawTextDeviceFont(_T("Font : 1"), 50, 50, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, 0);
	pLabelPrinter->drawTextDeviceFont(_T("Font : 3"), 450, 50, LABEL_DEVICE_FONT_12PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, 0);
	pLabelPrinter->drawTextDeviceFont(_T("Font :中国话 简化字"), 50, 150, LABEL_DEVICE_FONT_GB2312, 2, 2, 2, LABEL_ROTATION_0, false, false, false, 0);	//m = gb = 간체
	pLabelPrinter->drawTextDeviceFont(_T("Font :中國語 簡體字"), 50, 250, LABEL_DEVICE_FONT_BIG5, 2, 2, 2, LABEL_ROTATION_0, false, false, false, 0);	//n = big = 번체
	pLabelPrinter->drawTextDeviceFont(_T("日本語 : あいうえお"), 50, 350, LABEL_DEVICE_FONT_SHIFT_JIS, 2, 2, 2, LABEL_ROTATION_0, false, false, false, 0);
	pLabelPrinter->drawTextDeviceFont(_T("한글 : 가나다라마바사"), 50, 450, 'c', 2, 2, 2, 0, LABEL_ROTATION_0, true, false, 0);
	
	pLabelPrinter->drawTextDeviceFont(_T("Reverse"), 50, 550, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, true, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawTextDeviceFont(_T("Bold"), 500, 550, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, true, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawTextDeviceFont(_T("Right to Left"), 300, 650, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, true, LABEL_ALIGNMENT_LEFT);

	pLabelPrinter->drawTextDeviceFont(_T("rotaion0"), 400, 950, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, 0, 0, 0, 0);
	pLabelPrinter->drawTextDeviceFont(_T("rotaion90"), 400, 950, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_90, 0, 0, 0, 0);
	pLabelPrinter->drawTextDeviceFont(_T("rotaion180"), 400, 950, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_180, 0, 0, 0, 0);
	pLabelPrinter->drawTextDeviceFont(_T("rotaion270"), 400, 950, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_270, 0, 0, 0, 0);

	pLabelPrinter->printBuffer(1);
	pLabelPrinter->closeService(1000);
}

void CLabelPrinterDlg::OnBnClickedBtnVector()
{
	UpdateData(TRUE);
	if(m_nInterface == MPOS_INTERFACE_ETHERNET) GetDlgItemText(IDC_IPADDRESS1, m_strPort);
	pLabelPrinter->selectInterface(m_nInterface, m_strPort);
	pLabelPrinter->selectCommandMode(m_nConnectionType);
	long lResult = pLabelPrinter->openService();
	if(lResult == RES_ALREADY_OPEN)
		return;
	if(lResult != RES_SUCCESS)
	{
		CString strdata;
		strdata.Format(_T("Error Code = %d"), lResult);
		AfxMessageBox(strdata);		
		return ;
	}
	
	pLabelPrinter->drawTextVectorFont(_T("ASCII : ABCDEFG abcdefg"), 50, 50, LABEL_VECTOR_FONT_ASCII, 50, 50, 2, LABEL_ROTATION_0, false, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawTextVectorFont(_T("KS5601 : 가나다라마바사"), 50, 150, LABEL_VECTOR_FONT_KS5601, 50, 50, 2, LABEL_ROTATION_0, false, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawTextVectorFont(_T("BIG5 : 中國語 簡體字"), 50, 250, LABEL_VECTOR_FONT_BIG5, 50, 50, 2, LABEL_ROTATION_0, false, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawTextVectorFont(_T("GB2312 : 中国话 简化字"), 50, 350, LABEL_VECTOR_FONT_GB2312, 50, 50, 2, LABEL_ROTATION_0, false, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawTextVectorFont(_T("SHIFT_JIS : 日本語あいうえお"), 50, 450, LABEL_VECTOR_FONT_SHIFT_JIS, 50, 50, 2, LABEL_ROTATION_0, false, false, false, false, LABEL_ALIGNMENT_LEFT);
	
	pLabelPrinter->drawTextVectorFont(_T("Reverse"), 50, 550, LABEL_VECTOR_FONT_ASCII, 50, 50, 2, LABEL_ROTATION_0, true, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawTextVectorFont(_T("Bold"), 400, 550, LABEL_VECTOR_FONT_ASCII, 50, 50, 2, LABEL_ROTATION_0, false, true, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawTextVectorFont(_T("Italic"), 600, 550, LABEL_VECTOR_FONT_ASCII, 50, 50, 2, LABEL_ROTATION_0, false, false, true, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawTextVectorFont(_T("Right To Left"), 300, 650, LABEL_VECTOR_FONT_ASCII, 50, 50, 2, LABEL_ROTATION_0, false, false, false, true, LABEL_ALIGNMENT_LEFT);

	pLabelPrinter->drawTextVectorFont(_T("rotation0"), 400, 950, LABEL_VECTOR_FONT_ASCII, 50, 50, 2, LABEL_ROTATION_0, false, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawTextVectorFont(_T("rotation0"), 400, 950, LABEL_VECTOR_FONT_ASCII, 50, 50, 2, LABEL_ROTATION_90, false, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawTextVectorFont(_T("rotation180"), 400, 950, LABEL_VECTOR_FONT_ASCII, 50, 50, 2, LABEL_ROTATION_180, false, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawTextVectorFont(_T("rotation0"), 400, 950, LABEL_VECTOR_FONT_ASCII, 50, 50, 2, LABEL_ROTATION_270, false, false, false, false, LABEL_ALIGNMENT_LEFT);

	pLabelPrinter->printBuffer(1);
	pLabelPrinter->closeService(1000);
}

void CLabelPrinterDlg::OnBnClickedBtnImage()
{
	UpdateData(TRUE);
	if(m_nInterface == MPOS_INTERFACE_ETHERNET) 
		GetDlgItemText(IDC_IPADDRESS1, m_strPort);

	pLabelPrinter->selectInterface(m_nInterface, m_strPort);
	pLabelPrinter->selectCommandMode(m_nConnectionType);
	long lResult = pLabelPrinter->openService();
	//long lResult = pLabel->openServiceById(MPOS_DEVICE_LABEL_PRINTER, 3000);
	if(lResult == RES_ALREADY_OPEN)
		return;
	if(lResult != RES_SUCCESS)
	{
		CString strdata;
		strdata.Format(_T("Error Code(Label) = %d"), lResult);
		AfxMessageBox(strdata);
		return;
	}
	TCHAR szFilters[] = _T("All Files(*.*)|*.*||");
	
	CFileDialog FileDlg(TRUE, _T("*.bmp"), _T(""), OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, szFilters);
	
	if(FileDlg.DoModal() != IDOK)
	return;
	
	CString fileName;
	fileName = FileDlg.GetPathName();

	pLabelPrinter->drawImageFile(fileName, 100, 100, 200, 1, LABEL_DITHER_NONE, LABEL_IMAGE_NONE);
	pLabelPrinter->drawImageFile(fileName, 100, 600, 400, 200, LABEL_DITHER1, LABEL_IMAGE_RLE);

	pLabelPrinter->printBuffer(1);
	pLabelPrinter->closeService(1000);
}

void CLabelPrinterDlg::OnBnClickedBtnInfo()
{
	UpdateData(TRUE);
	if(m_nInterface == MPOS_INTERFACE_ETHERNET) 
		GetDlgItemText(IDC_IPADDRESS1, m_strPort);

	pLabelPrinter->selectInterface(m_nInterface, m_strPort);
	pLabelPrinter->selectCommandMode(m_nConnectionType);
	long lResult = pLabelPrinter->openService();
	//long lResult = pLabel->openServiceById(MPOS_DEVICE_LABEL_PRINTER, 3000);
	if(lResult == RES_ALREADY_OPEN)
		return;
	if(lResult != RES_SUCCESS)
	{
		CString strdata;
		strdata.Format(_T("Error Code(Label) = %d"), lResult);
		AfxMessageBox(strdata);
		return;
	}
	CString modelName, fwVersion;
	int DPI, maxWidth;
	modelName = pLabelPrinter->getModelName();
	fwVersion = pLabelPrinter->getFirmwareVersion();
	DPI = pLabelPrinter->getPrinterDPI();
	maxWidth = pLabelPrinter->getMaxWidth();

	CString strModel, strFW, strDPI, strWidth;
	strModel.Format(_T("Model Name : %s"), modelName);
	strFW.Format(_T("FW Ver : %s"), fwVersion);
	strDPI.Format(_T("Printer DPI : %d"), DPI);
	strWidth.Format(_T("Printer MaxWidth : %d"), maxWidth);

	pLabelPrinter->drawTextDeviceFont(strModel, 50, 100, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawTextDeviceFont(strFW, 50, 200, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawTextDeviceFont(strDPI, 50, 300, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawTextDeviceFont(strWidth, 50, 400, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);

	pLabelPrinter->printBuffer(1);
	pLabelPrinter->closeService(1000);
}

void CLabelPrinterDlg::OnBnClickedBtn1d()
{
	UpdateData(TRUE);
	if(m_nInterface == MPOS_INTERFACE_ETHERNET) 
		GetDlgItemText(IDC_IPADDRESS1, m_strPort);

	pLabelPrinter->selectInterface(m_nInterface, m_strPort);
	pLabelPrinter->selectCommandMode(m_nConnectionType);
	long lResult = pLabelPrinter->openService();
	//long lResult = pLabel->openServiceById(MPOS_DEVICE_LABEL_PRINTER, 3000);
	if(lResult == RES_ALREADY_OPEN)
		return;
	if(lResult != RES_SUCCESS)
	{
		CString strdata;
		strdata.Format(_T("Error Code(Label) = %d"), lResult);
		AfxMessageBox(strdata);
		return;
	}
	
	CString data = _T("0123456789");
	pLabelPrinter->drawTextDeviceFont(_T("CODE39"), 50, 50, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcode1D(data, 50, 100, LABEL_BARCODE_CODE39, 2, 5, 50, LABEL_BARCODE_TEXT_BELOW_1, 5, LABEL_ROTATION_0);

	pLabelPrinter->drawTextDeviceFont(_T("CODE128"), 50, 200, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcode1D(data, 50, 250, LABEL_BARCODE_CODE128, 2, 5, 50, LABEL_BARCODE_TEXT_BELOW_1, 5, LABEL_ROTATION_0);

	pLabelPrinter->drawTextDeviceFont(_T("I2OF5"), 50, 350, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcode1D(data, 50, 400, LABEL_BARCODE_I2OF5, 2, 5, 50, LABEL_BARCODE_TEXT_BELOW_1, 5, LABEL_ROTATION_0);

	pLabelPrinter->drawTextDeviceFont(_T("CODABAR"), 50, 500, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcode1D(data, 50, 550, LABEL_BARCODE_CODABAR, 2, 5, 50, LABEL_BARCODE_TEXT_BELOW_1, 5, LABEL_ROTATION_0);

	pLabelPrinter->drawTextDeviceFont(_T("UPC_A"), 50, 650, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcode1D(data, 50, 700, LABEL_BARCODE_UPC_A, 2, 5, 50, LABEL_BARCODE_TEXT_BELOW_1, 5, LABEL_ROTATION_0);

	pLabelPrinter->drawTextDeviceFont(_T("EAN13"), 50, 800, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcode1D(data, 50, 850, LABEL_BARCODE_EAN13, 2, 5, 50, LABEL_BARCODE_TEXT_BELOW_1, 5, LABEL_ROTATION_0);

	pLabelPrinter->drawTextDeviceFont(_T("CODE11"), 50, 950, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcode1D(data, 50, 1000, LABEL_BARCODE_CODE11, 2, 5, 50, LABEL_BARCODE_TEXT_BELOW_1, 5, LABEL_ROTATION_0);

	pLabelPrinter->printBuffer(1);

	pLabelPrinter->drawTextDeviceFont(_T("PLANET"), 50, 50, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcode1D(data, 50, 100, LABEL_BARCODE_PLANET, 2, 5, 50, LABEL_BARCODE_TEXT_BELOW_1, 5, LABEL_ROTATION_0);

	pLabelPrinter->drawTextDeviceFont(_T("INDUSTRIAL_2OF5"), 50, 200, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcode1D(data, 50, 250, LABEL_BARCODE_INDUSTRIAL_2OF5, 2, 5, 50, LABEL_BARCODE_TEXT_BELOW_1, 5, LABEL_ROTATION_0);

	pLabelPrinter->drawTextDeviceFont(_T("STANTARD_2OF5"), 50, 350, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcode1D(data, 50, 400, LABEL_BARCODE_STANDARD_2OF5, 2, 5, 50, LABEL_BARCODE_TEXT_BELOW_1, 5, LABEL_ROTATION_0);

	pLabelPrinter->drawTextDeviceFont(_T("LOGMARS"), 50, 500, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcode1D(data, 50, 550, LABEL_BARCODE_LOGMARS, 2, 5, 50, LABEL_BARCODE_TEXT_BELOW_1, 5, LABEL_ROTATION_0);

	pLabelPrinter->drawTextDeviceFont(_T("POSTNET"), 50, 650, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcode1D(data, 50, 700, LABEL_BARCODE_POSTNET, 2, 5, 50, LABEL_BARCODE_TEXT_BELOW_1, 5, LABEL_ROTATION_0);

	pLabelPrinter->printBuffer(1);
	pLabelPrinter->closeService(1000);
}

void CLabelPrinterDlg::OnBnClickedBtn2d()
{
	UpdateData(TRUE);
	if(m_nInterface == MPOS_INTERFACE_ETHERNET) 
		GetDlgItemText(IDC_IPADDRESS1, m_strPort);

	pLabelPrinter->selectInterface(m_nInterface, m_strPort);
	pLabelPrinter->selectCommandMode(m_nConnectionType);
	long lResult = pLabelPrinter->openService();
	//long lResult = pLabel->openServiceById(MPOS_DEVICE_LABEL_PRINTER, 3000);
	if(lResult == RES_ALREADY_OPEN)
		return;
	if(lResult != RES_SUCCESS)
	{
		CString strdata;
		strdata.Format(_T("Error Code(Label) = %d"), lResult);
		AfxMessageBox(strdata);
		return;
	}

	CString data = _T("0123456789");
	pLabelPrinter->drawTextDeviceFont(_T("MAXI CODE"), 50, 50, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcodeMaxiCode(_T("999,840,06810,7317"), 50, 100, 0);
	
	pLabelPrinter->drawTextDeviceFont(_T("PDF417"), 400, 50, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcodePDF417(data, 400, 100, 30, 5, 0, LABEL_PDF417_DATA_COMPRESSION_TEXT, 1, 1, 3, 20, LABEL_ROTATION_0);

	pLabelPrinter->drawTextDeviceFont(_T("QR CODE"), 50, 350, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcodeQRCode(data, 50, 400, 4, LABEL_QRCODE_MODEL_1, LABEL_QRCODE_ECC_M, LABEL_ROTATION_0);

	pLabelPrinter->drawTextDeviceFont(_T("AZTEC"), 400, 350, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcodeAztec(data, 400, 400, 5, FALSE, 0, false, 2, _T("10"), LABEL_ROTATION_0);

	pLabelPrinter->drawTextDeviceFont(_T("CODE49"), 50, 500, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcodeCode49(data, 50, 550, 3, 7, 20, 2, 7, LABEL_ROTATION_0);

	pLabelPrinter->drawTextDeviceFont(_T("CODABLOCK"), 400, 500, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcodeCodaBlock(data, 400, 550, 2, 5, 5, 0, 10, LABEL_CODABLOCK_MODE_A, 18);
	
	pLabelPrinter->drawTextDeviceFont(_T("MICRO PDF"), 50, 800, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcodeMicroPDF(data, 50, 870, 2, 3, 20, LABEL_ROTATION_0);

	pLabelPrinter->printBuffer(1);

	pLabelPrinter->drawTextDeviceFont(_T("IMB"), 50, 50, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcodeIMB(_T("01234567890123456789"), 50, 100, TRUE, LABEL_ROTATION_0);

	pLabelPrinter->drawTextDeviceFont(_T("PLESSEY"), 50, 200, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcodePlessey(data, 50, 250, 1, 3, 50, false, 0, 0);

	pLabelPrinter->drawTextDeviceFont(_T("TLC39"), 50, 350, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcodeTLC39(data, 50, 400, 2, 5, 100, 3, 2, 0);

	pLabelPrinter->drawTextDeviceFont(_T("RSS"), 50, 550, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcodeRSS(data, 50, 600, LABEL_RSS14, 2, 1, 10, 4, LABEL_ROTATION_0);

	pLabelPrinter->drawTextDeviceFont(_T("MSI"), 50, 700, LABEL_DEVICE_FONT_8PT, 2, 2, 2, LABEL_ROTATION_0, false, false, false, LABEL_ALIGNMENT_LEFT);
	pLabelPrinter->drawBarcodeMSI(data, 50, 750, 2, 7, 100, 1, true, 1, LABEL_ROTATION_0);

	pLabelPrinter->printBuffer(1);
	pLabelPrinter->closeService(1000);
}


