?? ircomdlg.cpp
字號:
// 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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -