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

📄 icdemodlg.cpp

📁 IC卡操作Demo 包括了常见的IC卡种类。可执行写入、读出、校验、密码修改、批量作业等功能。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// IcDemoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "IcDemo.h"
#include "IcDemoDlg.h"
#include "frmport.h"
#include "type.h"
#include "RDcard.h"
#include "ChkSc.h"
#include "WrSm.h"
#include "PageRd.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIcDemoDlg dialog

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

void CIcDemoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CIcDemoDlg)
	DDX_Control(pDX, IDC_PAGE, m_page);
	DDX_Control(pDX, cmdClear, m_clscard);
	DDX_Control(pDX, cmdKill, m_killcard);
	DDX_Control(pDX, cmdChkAll, m_chkall);
	DDX_Control(pDX, IDC_sPwd, m_spwd);
	DDX_Control(pDX, IDC_schk, m_schk);
	DDX_Control(pDX, cmdLst, m_lst);
	DDX_Control(pDX, cmdFst, m_fst);
	DDX_Control(pDX, cmdCheck, m_check);
	DDX_Control(pDX, cmdChkPwd, m_chkpwd);
	DDX_Control(pDX, cmdWrCard, m_wrcard);
	DDX_Control(pDX, cmdReadCard, m_readcard);
	DDX_Control(pDX, cmdPowerOff, m_poweroff);
	DDX_Control(pDX, cmdPowerOn, m_poweron);
	DDX_Control(pDX, cmdPort, m_port);
	DDX_Control(pDX, cmdCardtype, m_CardType);
	DDX_Control(pDX, IDC_Cardtype, m_lblcardtype);
	DDX_Control(pDX, IDC_pwd, m_lblpwd);
	DDX_Control(pDX, IDC_power, m_lblpower);
	DDX_Control(pDX, IDC_port, m_lblport);
	DDX_Control(pDX, IDC_frastatus, m_staus);
	DDX_Control(pDX, cmdPrev, m_prev);
	DDX_Control(pDX, cmdNext, m_next);
	DDX_Control(pDX, IDC_Tit, m_Tit);
	DDX_Control(pDX, IDC_fra, m_fra);
	DDX_Control(pDX, IDC_LIST1, m_lstdata);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CIcDemoDlg, CDialog)
	//{{AFX_MSG_MAP(CIcDemoDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_CREATE()
	ON_BN_CLICKED(ID_cmdexit, Oncmdexit)
	ON_BN_CLICKED(cmdPort, OncmdPort)
	ON_BN_CLICKED(cmdCardtype, OncmdCardtype)
	ON_BN_CLICKED(cmdPowerOn, OncmdPowerOn)
	ON_BN_CLICKED(cmdPowerOff, OncmdPowerOff)
	ON_BN_CLICKED(cmdReadCard, OncmdReadCard)
	ON_BN_CLICKED(cmdPrev, OncmdPrev)
	ON_BN_CLICKED(cmdNext, OncmdNext)
	ON_BN_CLICKED(cmdWrCard, OncmdWrCard)
	ON_BN_CLICKED(cmdChkPwd, OncmdChkPwd)
	ON_BN_CLICKED(cmdCheck, OncmdCheck)
	ON_BN_CLICKED(cmdFst, OncmdFst)
	ON_BN_CLICKED(cmdLst, OncmdLst)
	ON_BN_CLICKED(cmdChkAll, OncmdChkAll)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIcDemoDlg message handlers
extern CIcDemoApp theApp;

static UINT indicators[] =
{
    ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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
	
	// TODO: Add extra initialization here
    m_CardType.EnableWindow(FALSE);
	m_next.EnableWindow(FALSE);
	m_prev.EnableWindow(FALSE);
	m_fst.EnableWindow(FALSE);
	m_lst.EnableWindow(FALSE);
	m_chkpwd.EnableWindow(FALSE);
	m_poweron.EnableWindow(FALSE);
	m_poweroff.EnableWindow(FALSE);
	m_readcard.EnableWindow(FALSE);
	m_wrcard.EnableWindow(FALSE);
	m_chkall.EnableWindow(FALSE);
	m_clscard.EnableWindow(FALSE);
	m_killcard.EnableWindow(FALSE);
	IsChkPwd=0;
    m_check.EnableWindow(FALSE);
	int i,j,nItem;
	CString headstr="";
   	m_lstdata.SetGridStyle(TRUE);
	m_lstdata.SetFontSize(14);  
	m_lstdata.SetFontBold(TRUE); 

	m_lstdata.InsertColumn(1,"位 置",2,70);
    for(i=2;i<12;i++)
	{
      headstr.Format("%.2d",i-2); 
      m_lstdata.InsertColumn(i,headstr,2,30);
	}
	m_lstdata.InsertColumn(12,"文本内容",LVCFMT_LEFT,170);
    for(i=0;i<13;i++)
	{
		headstr.Format("%.4d",i*10);
		nItem=m_lstdata.InsertItem(i,headstr); 
		for(j=1;j<11;j++)
		  m_lstdata.SetItemText(nItem,j,"FF");

	}

    m_Tit.SetFontSize(20);
	m_Tit.SetFontBold(TRUE);
	chkPage=1;
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CIcDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		if (nID==SC_CLOSE)
		{
		  if(MessageBox("真的要退出系统吗?","信息提示",MB_ICONSTOP|MB_YESNO|MB_DEFBUTTON2)==IDYES)
		  {
			  if(theApp.intType!=0 && m_poweroff.IsWindowEnabled()) 
			   //{ 
			    //  MessageBox("尚未下电!","信息提示",MB_ICONSTOP|MB_OK);
			   //   return;
			   //}
			    theApp.surepower_off(); 
		     // CDialog::OnSysCommand(nID, lParam);
			  CDialog::OnCancel(); 
		  }
		}
		else
           CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CIcDemoDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		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;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
	CRect rect;
	GetClientRect(&rect);
	CRect Conrect;
	if(rect.right>=800)
	{
	 ::MoveWindow(m_lstdata.m_hWnd,rect.left+110,rect.top+50,rect.Width()-220,rect.Height()-300 ,TRUE);  
     ::MoveWindow(m_fra.m_hWnd,rect.left+10,rect.top+10,95,rect.Height()-70 ,TRUE); 
	  m_page.GetClientRect(&Conrect);
	 ::MoveWindow(m_page.m_hWnd,rect.left+110,rect.bottom-240,Conrect.Width(),Conrect.Height(),TRUE); 
     m_fst.GetClientRect(&Conrect);
	 ::MoveWindow(m_fst.m_hWnd,rect.right-420,rect.bottom-240,Conrect.Width(),Conrect.Height(),TRUE); 
	 m_next.GetClientRect(&Conrect);
	 ::MoveWindow(m_next.m_hWnd,rect.right-340,rect.bottom-240,Conrect.Width(),Conrect.Height(),TRUE); 
     m_prev.GetClientRect(&Conrect);
	 ::MoveWindow(m_prev.m_hWnd,rect.right-260,rect.bottom-240,Conrect.Width(),Conrect.Height(),TRUE); 
	 m_lst.GetClientRect(&Conrect);
	 ::MoveWindow(m_lst.m_hWnd,rect.right-180,rect.bottom-240,Conrect.Width(),Conrect.Height(),TRUE); 
	 m_staus.GetClientRect(&Conrect);
	 ::MoveWindow(m_staus.m_hWnd,rect.left+110,rect.bottom-210,rect.Width()-220,150,TRUE); 
	  m_lblport.GetClientRect(&Conrect);
	 ::MoveWindow(m_lblport.m_hWnd,rect.left+130,rect.bottom-190,Conrect.Width(),Conrect.Height(),TRUE);
	  m_lblcardtype.GetClientRect(&Conrect);
	 ::MoveWindow(m_lblcardtype.m_hWnd,rect.left+270,rect.bottom-190,Conrect.Width(),Conrect.Height(),TRUE); 
	  m_lblpower.GetClientRect(&Conrect);
	 ::MoveWindow(m_lblpower.m_hWnd,rect.left+450,rect.bottom-190,Conrect.Width(),Conrect.Height(),TRUE); 
	  m_lblpwd.GetClientRect(&Conrect);
	 ::MoveWindow(m_lblpwd.m_hWnd,rect.left+130,rect.bottom-160,Conrect.Width(),Conrect.Height(),TRUE); 
	  m_spwd.GetClientRect(&Conrect);
	 ::MoveWindow(m_spwd.m_hWnd,rect.left+270,rect.bottom-160,Conrect.Width(),Conrect.Height(),TRUE); 
	  m_schk.GetClientRect(&Conrect);
	 ::MoveWindow(m_schk.m_hWnd,rect.left+450,rect.bottom-160,Conrect.Width(),Conrect.Height(),TRUE); 
	  m_StatusBarCtrl->GetClientRect(&Conrect);
	  ::MoveWindow(m_StatusBarCtrl->m_hWnd,rect.left,rect.bottom-Conrect.Height(),Conrect.Width(),Conrect.Height(),TRUE);  
	}
	else
	{
     ::MoveWindow(m_lstdata.m_hWnd,rect.left+110,rect.top+50,rect.Width()-120,rect.Height()-200 ,TRUE);  
    // ::MoveWindow(m_fra.m_hWnd,rect.left+10,rect.top+10,95,rect.Height()-160 ,TRUE); 
	  m_page.GetClientRect(&Conrect);
	 ::MoveWindow(m_page.m_hWnd,rect.left+110,rect.bottom-140,Conrect.Width(),Conrect.Height(),TRUE); 
	 m_fst.GetClientRect(&Conrect);
	 ::MoveWindow(m_fst.m_hWnd,rect.right-380,rect.bottom-140,Conrect.Width(),Conrect.Height(),TRUE); 
	 m_next.GetClientRect(&Conrect);
	 ::MoveWindow(m_next.m_hWnd,rect.right-220,rect.bottom-140,Conrect.Width(),Conrect.Height(),TRUE); 
     m_prev.GetClientRect(&Conrect);
	 ::MoveWindow(m_prev.m_hWnd,rect.right-300,rect.bottom-140,Conrect.Width(),Conrect.Height(),TRUE);  
	 m_lst.GetClientRect(&Conrect);
	 ::MoveWindow(m_lst.m_hWnd,rect.right-140,rect.bottom-140,Conrect.Width(),Conrect.Height(),TRUE);  
	  m_staus.GetClientRect(&Conrect);
	 ::MoveWindow(m_staus.m_hWnd,rect.left+110,rect.bottom-120,rect.Width()-120,Conrect.Height(),TRUE); 
	  m_lblport.GetClientRect(&Conrect);
	 ::MoveWindow(m_lblport.m_hWnd,rect.left+130,rect.bottom-100,Conrect.Width(),Conrect.Height(),TRUE);
	  m_lblcardtype.GetClientRect(&Conrect);
	 ::MoveWindow(m_lblcardtype.m_hWnd,rect.left+270,rect.bottom-100,Conrect.Width(),Conrect.Height(),TRUE); 
	  m_lblpower.GetClientRect(&Conrect);
	 ::MoveWindow(m_lblpower.m_hWnd,rect.left+450,rect.bottom-100,Conrect.Width(),Conrect.Height(),TRUE); 
	  m_lblpwd.GetClientRect(&Conrect);
	 ::MoveWindow(m_lblpwd.m_hWnd,rect.left+130,rect.bottom-70,Conrect.Width(),Conrect.Height(),TRUE); 
	   m_spwd.GetClientRect(&Conrect);
	 ::MoveWindow(m_spwd.m_hWnd,rect.left+270,rect.bottom-70,Conrect.Width(),Conrect.Height(),TRUE); 
	   m_schk.GetClientRect(&Conrect);
	 ::MoveWindow(m_schk.m_hWnd,rect.left+450,rect.bottom-70,Conrect.Width(),Conrect.Height(),TRUE); 
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CIcDemoDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

int CIcDemoDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	::ShowWindow(m_hWnd,3);
	m_StatusBarCtrl=new CStatusBarCtrl();
	CRect rect;
	//const int nParts = 2;
	m_StatusBarCtrl->Create(WS_VISIBLE | CBRS_BOTTOM, rect ,this, 0);
    m_StatusBarCtrl->GetClientRect(&rect);
    int widths[3];
	if (rect.right<800)
	{
	 widths[0] = 100;
	 widths[1]=340;
	 widths[2] =rect.Width();
	}
    else
	{
	 widths[0] = rect.right-700;
	 widths[1]=rect.right-400;
	 widths[2]=rect.Width();
	}
	VERIFY(m_StatusBarCtrl->SetParts(3, widths));
	m_StatusBarCtrl->SetText("待命",0,0);
	return 0;
}
CIcDemoDlg::~CIcDemoDlg(void)
{
	delete m_StatusBarCtrl;
}
void CIcDemoDlg::Oncmdexit() 
{
	// TODO: Add your control notification handler code here
     if(MessageBox("真的要退出系统吗?","信息提示",MB_ICONSTOP|MB_YESNO|MB_DEFBUTTON2)==IDYES)
	 {
		if(theApp.intType!=0 && m_poweroff.IsWindowEnabled()) 
		//{ 
		//	MessageBox("尚未下电!","信息提示",MB_ICONSTOP|MB_OK);
		//	return;
	//}
	     theApp.surepower_off();
		 OnCancel();
	 }
}

void CIcDemoDlg::OncmdPort() 
{
	// TODO: Add your control notification handler code here
    CFrmPort dlg;
	CString str="";
	m_port.EnableWindow(FALSE); 
	m_StatusBarCtrl->SetText("选择串口",0,0);
    int Rn=dlg.DoModal(); 
	if(Rn==IDOK)
	{
	  str.Format("%d",theApp.intCom+1); 
	  m_lblport.SetWindowText("串口位置:COM"+str); 
	  Rn=theApp.sureinit_com(theApp.intCom);
	  if(Rn!=0)
	  {
		 //str=theApp.ReadWriteError(Rn);
	      str="串口初始化错误!";
          MessageBox(str,"信息提示",MB_ICONERROR|MB_OK);
		  m_StatusBarCtrl->SetText(str,1,0);
		  m_port.EnableWindow(TRUE);
		  return;
	  }
	  else
		MessageBox("串口选择正确!","信息提示",MB_ICONINFORMATION|MB_OK);
	  m_CardType.EnableWindow(TRUE);
	  m_StatusBarCtrl->SetText("函数:unsigned power_on()",2,0);
	}
	m_port.EnableWindow(TRUE);
}

void CIcDemoDlg::OncmdCardtype() 
{
	// TODO: Add your control notification handler code here
	CType dlg;
	CString str="";
	m_StatusBarCtrl->SetText("选择卡型",0,0);
    int Rn=dlg.DoModal(); 
	if(Rn==IDOK)
	{
	  str=dlg.m_lstdata.Right(20);
	  str.TrimLeft(' '); 
	  str=str.Left(2);
	  theApp.intType=atoi(str);
     // CString str1;
	 // str1=dlg.m_lstdata.Left(20);
	 // str1=str1.Right(10); 
	  m_StatusBarCtrl->SetText(dlg.m_lstdata,1,0);
	  m_lblcardtype.SetWindowText("卡型代码:" + str);
	 //m_lblcardtype.SetWindowText(dlg.m_lstdata);
	  Rn=theApp.suresele_card(theApp.intType);
	  if(Rn!=0)
	  {
		  str=theApp.ReadWriteError(Rn);
	      m_StatusBarCtrl->SetText(str,0,0);
		  return;
	  }	
	  
	  //m_chkpwd.EnableWindow(FALSE);
	  m_lblpwd.SetWindowText("未核对密码");
	  m_schk.SetWindowText("校验码:");
      m_spwd.SetWindowText("密码:");
	  MessageBox("卡型已选!","信息提示",MB_ICONINFORMATION|MB_OK);
	  m_poweron.EnableWindow(TRUE);
      m_chkpwd.EnableWindow(FALSE);
	 // m_poweron.EnableWindow(FALSE);
	  m_poweroff.EnableWindow(FALSE);
	  m_readcard.EnableWindow(FALSE);
	  m_wrcard.EnableWindow(FALSE);
	  m_chkall.EnableWindow(FALSE);
	  m_clscard.EnableWindow(FALSE);
	  m_killcard.EnableWindow(FALSE);
	
      m_check.EnableWindow(FALSE);
	  m_poweroff.EnableWindow(TRUE);
	  m_readcard.EnableWindow(TRUE);
	  m_wrcard.EnableWindow(TRUE);
	  m_fst.EnableWindow(TRUE);
	  m_lst.EnableWindow(TRUE);
	  //m_chkall.EnableWindow(TRUE);
	  if(theApp.intType>=10 && theApp.intType<20)
	  {
		  m_clscard.EnableWindow(TRUE);
	      m_killcard.EnableWindow(TRUE);
	  }
       if((theApp.intType>=10 && theApp.intType<20) || theApp.intType==42 || theApp.intType==43)
	  {
		  m_chkpwd.EnableWindow(TRUE);
	      m_chkall.EnableWindow(TRUE);
		  m_check.EnableWindow(TRUE);
	  }
	  m_StatusBarCtrl->SetText("函数:unsigned sele_card(unsigned card_type)",2,0);
	  IsChkPwd=0;
	  //m_chkpwd.EnableWindow(TRUE);
	}
}

void CIcDemoDlg::OncmdPowerOn() 
{
	// TODO: Add your control notification handler code here
	
	if(theApp.intType==0)
	{
		MessageBox("发卡器内部储存芯片无须上电","信息提示",MB_OK|MB_ICONSTOP);
        return;
	}
    //m_poweron.EnableWindow(FALSE); 
	int Rn=theApp.surepower_on(); 
	if(Rn!=0)
	{
		m_StatusBarCtrl->SetText(theApp.ReadWriteError(Rn),0,0);
		//m_poweron.EnableWindow(TRUE);
	    return;
	}
  	else
	{
	   if(theApp.intPage>1)
	  {

⌨️ 快捷键说明

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