⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printerdlg.cpp

📁 友善之臂2410开发版上写的一个串口打印程序
💻 CPP
字号:
// PrinterDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Printer.h"
#include "PrinterDlg.h"
#include "CESeries.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPrinterDlg dialog

CPrinterDlg::CPrinterDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPrinterDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPrinterDlg)
	m_text = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPrinterDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPrinterDlg)
	DDX_Control(pDX, IDC_COMBO1, m_combox);
	DDX_Text(pDX, IDC_EDIT_SEND, m_text);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPrinterDlg, CDialog)
	//{{AFX_MSG_MAP(CPrinterDlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_WM_DESTROY()
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPrinterDlg message handlers

BOOL CPrinterDlg::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
	GetDlgItem(IDC_BUTTON1)->EnableWindow(false);
	
//	m_combox.AddString(L"COM1");
//	m_combox.AddString(L"COM2");
	return TRUE;  // return TRUE  unless you set the focus to a control
}



void CPrinterDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	if(ceSeries->PrintString(m_text))
		AfxMessageBox(_T("Message is sent"));

//	ceSeries->ClosePort();
	
}

void CPrinterDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	ceSeries = new CCESeries();
	CComboBox *pComboBox;
	pComboBox =(CComboBox*)GetDlgItem(IDC_COMBO1);
	ceSeries->OpenPort(this ,pComboBox->GetCurSel()+1,9600,NOPARITY,8,1);
//	TCHAR buf[20];
//	MessageBox(_itow(pComboBox->GetCurSel(),buf,10));
	GetDlgItem(IDC_BUTTON2)->EnableWindow(false);
	GetDlgItem(IDC_BUTTON1)->EnableWindow(true);
	
}

void CPrinterDlg::OnDestroy() 
{
	ceSeries->ClosePort();
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	
}

void CPrinterDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	ceSeries->ClosePort();
	CDialog::OnClose();
}

int CPrinterDlg::String2Hex(CString str,CByteArray &senddata)
{
	int hexdata,lowhexdata;
	int hexdatalen=0;
	int len=str.GetLength();
	senddata.SetSize(len/2);
	for(int i=0;i<len;)
	{
		char lstr,hstr=str[i];
		if(hstr==' ')
		{
			i++;
			continue;
		}
	i++;
	if(i>=len)
		break;
	lstr=str[i];
	hexdata=ConvertHexChar(hstr);
	lowhexdata=ConvertHexChar(lstr);
	if((hexdata==16)||(lowhexdata==16))
		break;
	else 
		hexdata=hexdata*16+lowhexdata;
	i++;
	senddata[hexdatalen]=(char)hexdata;
	hexdatalen++;
	}
senddata.SetSize(hexdatalen);
return hexdatalen;


}

char CPrinterDlg::ConvertHexChar(char ch)
{

	if((ch>='0')&&(ch<='9'))
	return ch-0x30;
	else if((ch>='A')&&(ch<='F'))
	return ch-'A'+10;
	else if((ch>='a')&&(ch<='f'))
	return ch-'a'+10;
	else return (-1);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -