ircomdlg.cpp

来自「利用嵌入式终端的红外传输协议」· C++ 代码 · 共 227 行

CPP
227
字号
// ircomDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ircom.h"
#include "ircomDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CIrcomDlg dialog

CIrcomDlg::CIrcomDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CIrcomDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CIrcomDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CIrcomDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CIrcomDlg)
	DDX_Control(pDX, IDC_PRINTHELP, m_PrintHelp);
	DDX_Control(pDX, IDC_TEST, m_Test);
	DDX_Control(pDX, IDC_IROPEN, m_Open);
	DDX_Control(pDX, IDC_IRCLOSE, m_Close);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CIrcomDlg, CDialog)
	//{{AFX_MSG_MAP(CIrcomDlg)
	ON_BN_CLICKED(IDC_IROPEN, OnIropen)
	ON_BN_CLICKED(IDC_IRCLOSE, OnIrclose)
	ON_BN_CLICKED(IDC_TEST, OnTest)
	ON_WM_TIMER()
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_PRINTHELP, OnPrinthelp)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIrcomDlg message handlers

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

	hinst=NULL;
	lpfIRClose=NULL;
	lpfIROpen=NULL;
	lpfIRIsOpen=NULL;
	lpfIRWrite=NULL;
	lpfIRTimer=NULL;
	lpfIRPrintHelp=NULL;


	// 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
	SetTimer(1,200,NULL);
	return TRUE;  // return TRUE  unless you set the focus to a control
}



int CIrcomDlg::LoadDll(CString dllname)
{
	BOOL ret=TRUE;
	FreeDll();

	hinst=LoadLibrary(dllname);
	if(hinst==NULL) return FALSE;

	//----------------------get function address-----------------
	lpfIROpen=(xIROpen*)GetProcAddress(hinst,_T("IROpen"));
	if(lpfIROpen==NULL) {ret=FALSE;AfxMessageBox(_T("1"));}
	

	lpfIRClose=(xIRClose*)GetProcAddress(hinst,_T("IRClose"));
	if(lpfIRClose==NULL) {ret=FALSE;AfxMessageBox(_T("2"));}

	lpfIRIsOpen=(xIRIsOpen*)GetProcAddress(hinst,_T("IRIsOpen"));
	if(lpfIRIsOpen==NULL) {ret=FALSE;AfxMessageBox(_T("3"));}

	lpfIRWrite=(xIRWrite*)GetProcAddress(hinst,_T("IRWrite"));
	if(lpfIRWrite==NULL) {ret=FALSE;AfxMessageBox(_T("4"));}

	lpfIRTimer=(xIRTimer*)GetProcAddress(hinst,_T("IRTimer"));
	if(lpfIRTimer==NULL) {ret=FALSE;AfxMessageBox(_T("4"));}

	lpfIRPrintHelp=(xIRPrintHelp*)GetProcAddress(hinst,_T("IRPrintHelp"));
	if(lpfIRPrintHelp==NULL) {ret=FALSE;AfxMessageBox(_T("5"));}


	if(!ret)
	{
		FreeDll();
		return ret;
	}
	return ret;
}


void CIrcomDlg::FreeDll()
{
	if(hinst!=NULL)
	{
		lpfIROpen=NULL;
		lpfIRClose=NULL;
		lpfIRIsOpen=NULL;
		lpfIRWrite=NULL;
		lpfIRTimer=NULL;
		lpfIRPrintHelp=NULL;

		FreeLibrary(hinst);
		hinst=NULL;
	}
}


void CIrcomDlg::OnIropen() 
{
	// TODO: Add your control notification handler code here
	if(lpfIROpen==NULL) 	LoadDll((char*)("xircom.dll"));
	if(lpfIROpen==NULL) AfxMessageBox(_T("Load dll failure!"));
	else
	{
		CString ret=lpfIROpen(CBR_115200);
		if(ret!=NULL) AfxMessageBox(ret);
	}
}

void CIrcomDlg::OnIrclose() 
{
	// TODO: Add your control notification handler code here
	if(lpfIRClose!=NULL)
	{
		lpfIRClose();
		FreeDll();
	}
}
#define ESC 0x1b
void CIrcomDlg::OnTest() 
{
	// TODO: Add your control notification handler code here
	if(lpfIRWrite==NULL) return;
	char xbuf[256];

	//init to default settings
	sprintf((char*)xbuf,(const char*)"%c@",ESC);
	lpfIRWrite((unsigned char *)xbuf,strlen((const char*)xbuf));

	
	sprintf((char*)xbuf,(const char*)"%c!%c24点阵粗体!\n",ESC,0x08);
	lpfIRWrite((unsigned char *)xbuf,strlen((const char*)xbuf));

	sprintf((char*)xbuf,(const char*)"%c!%c24点阵倍高!\n",ESC,0x10);
	lpfIRWrite((unsigned char *)xbuf,strlen((const char*)xbuf));

	sprintf((char*)xbuf,(const char*)"%c!%c24点阵倍宽!\n",ESC,0x20);
	lpfIRWrite((unsigned char *)xbuf,strlen((const char*)xbuf));

	sprintf((char*)xbuf,(const char*)"%c!%c24点阵倍高宽!\n",ESC,0x30);
	lpfIRWrite((unsigned char *)xbuf,strlen((const char*)xbuf));


	SYSTEMTIME time;
	GetSystemTime(&time);

	sprintf((char*)xbuf,(const char*)"%c!%c-----%04d-%02d-%02d %02d:%02d:%02d-----\n\n",ESC,0x01,time.wYear,time.wMonth,time.wDay,time.wHour,time.wMinute,time.wSecond);
	lpfIRWrite((unsigned char *)xbuf,strlen((const char*)xbuf));

	//init to default settings
	sprintf((char*)xbuf,(const char*)"%c@",ESC);
	lpfIRWrite((unsigned char *)xbuf,strlen((const char*)xbuf));
}

void CIrcomDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(hinst!=NULL)
	{
		m_Close.EnableWindow(TRUE);
		m_Test.EnableWindow(TRUE);
		m_Open.EnableWindow(FALSE);
		m_PrintHelp.EnableWindow(TRUE);
		lpfIRTimer();
	}
	else 
	{
		m_Close.EnableWindow(FALSE);
		m_Test.EnableWindow(FALSE);
		m_Open.EnableWindow(TRUE);
		m_PrintHelp.EnableWindow(FALSE);
	}
	CDialog::OnTimer(nIDEvent);
}



void CIrcomDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	FreeDll();
}

void CIrcomDlg::OnPrinthelp() 
{
	// TODO: Add your control notification handler code here
	if(lpfIRPrintHelp!=NULL) lpfIRPrintHelp();
}

⌨️ 快捷键说明

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