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

📄 test1dlg.cpp

📁 常用的金融读写卡机ghc715 上位机程序。
💻 CPP
字号:
// test1Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "test1.h"
#include "test1Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//My CODE STARTS HEAR
/////////////////////
#ifdef __cpluscpus
extern "C"{
#endif


//The instance of the Mydll.dll library
//gLibMydll:存储dll句柄,初始化为NULL

HINSTANCE gLibMyDLL = NULL;
// declar
//定义指向DLL库中readcard指针
typedef int (__stdcall *MYBEEP)(int comport,int track,char data1[37],char data2[104],int model);
MYBEEP readcard;
//declare
//定义指向DLL库中writecard指针
typedef int  (__stdcall *MYDELAY)(int comport,int track,char data1[37],char data2[104],int model);
MYDELAY writecard;

/////////////////////////////////////////////////////////////////////////////
// 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 void OnDoubleclickedOk();
	//}}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)
	ON_BN_DOUBLECLICKED(IDOK, OnDoubleclickedOk)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTest1Dlg dialog

CTest1Dlg::CTest1Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTest1Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTest1Dlg)
	m_sData1 = _T("");
	m_sData2 = _T("");
	m_bWrite=0;
	m_nTrack = 1;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTest1Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTest1Dlg)
	DDX_Text(pDX, IDC_DATA1, m_sData1);
	DDX_Text(pDX, IDC_DATA2, m_sData2);
	DDX_Radio(pDX, IDC_READ,m_bWrite);
	DDX_Text(pDX, IDC_TRACK, m_nTrack);
	DDV_MinMaxInt(pDX, m_nTrack, 1, 5);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTest1Dlg, CDialog)
	//{{AFX_MSG_MAP(CTest1Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_READ, OnRead)
	ON_BN_CLICKED(IDC_WRITE, OnWrite)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTest1Dlg message handlers

BOOL CTest1Dlg::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
	UpdateData(FALSE);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTest1Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	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 CTest1Dlg::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();
	}
}

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

void CTest1Dlg::OnOK() 
{
	// TODO: Add extra validation here
	
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(gLibMyDLL == NULL)
	{
		//MessageBox("You load");
		OnButton5();		
	}
	if(gLibMyDLL==NULL)
		return;
	
	
	if(m_bWrite)//write
	{
		//AfxMessageBox("write");
		BeginWaitCursor();
		int code=writecard(1,m_nTrack,m_sData1.GetBuffer(150),m_sData2.GetBuffer(150),1);
		EndWaitCursor();
		if(code==0)
		{				
			CString s;
			s.Format("Write %d  success\n",m_nTrack);
			MessageBox(s);			
		}
		else
		{
			CString s;
			s.Format("Write card error: code=%d\n",code);
			MessageBox(s);
		}
	}
	else
	{
		//AfxMessageBox("read");
		char data1[100],data2[100];
		BeginWaitCursor();
		int code=readcard(1,m_nTrack,data1,data2,1);//////////////////////////
		EndWaitCursor();
		if(code==0)
		{	
			CString s;
			s.Format("Read %d  success\n",m_nTrack);
			MessageBox(s);
			m_sData1="";
			m_sData2="";

			if(m_nTrack==1||m_nTrack==3)	//1,3
			{
				m_sData2=CString(data2);	//2
			}
			else if(m_nTrack==2)
			{
				m_sData1=CString(data1);
			}
			else 
			{
				m_sData1=CString(data1);	//1or3
				m_sData2=CString(data2);	//2
			}
			UpdateData(FALSE);
		}
		else
		{
			CString s;
			s.Format("Read card error: code=%d\n",code);
			MessageBox(s);
		}
			

	}
	
}

void CTest1Dlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	// TODO: Add your control notification handler code here
	CDialog::OnCancel();
}

void CTest1Dlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	
    if(gLibMyDLL == NULL)
	{
		MessageBox("You load");
		return;
	}
	char data1[37],data2[104];
	if(readcard(1,1,data1,data2,2)==1)
	{	
		printf(data1);
		MessageBox("Read 1 success\n");
		MessageBox(data1);
	}
	else
		MessageBox("Read 1 Error");
}

void CTest1Dlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	if(gLibMyDLL == NULL)
{
	MessageBox("You load");
    return;
}
char data1[37],data2[104];
if(readcard(1,2,data1,data2,2)==1)
{ printf(data2);
  MessageBox("Read success\n");
  MessageBox(data2);
}
else
  MessageBox("Read 3 Error");
}

void CTest1Dlg::OnButton5() 
{
	// TODO: Add your control notification handler code here
	if(gLibMyDLL!= NULL)
	{
		MessageBox("The Mydll.Dll Dll has alread been loaded");
		return;
	}
	gLibMyDLL = LoadLibrary("ghc715.DLL");
	if(gLibMyDLL == NULL)
	{
		char msg[300];
		strcpy(msg,"Cannot load the MYDLL.DLL DLL.");
        strcat(msg,"Make sure that the file MYDLL.DLL");
		strcat(msg,"os om upir \\ WINDOWS\\SYSTEM directory,");
		MessageBox(msg);
	}
	readcard = (MYBEEP)GetProcAddress(gLibMyDLL,"readcard");	
	writecard = (MYDELAY)GetProcAddress(gLibMyDLL,"writecard");

}

void CTest1Dlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
if(gLibMyDLL == NULL)
{
	MessageBox("You load");
    return;
}
char data1[37],data2[104];
strcpy(data1,"1111134241\x0");
strcpy(data2,"111123411\x0");
if(writecard(1,1,data1,data2,2)==1)
{ printf(data1);
  MessageBox("Write 1 success\n");
}  
else
  MessageBox("write 1 Error");	

}

void CTest1Dlg::OnButton4() 
{
	// TODO: Add your control notification handler code here
if(gLibMyDLL == NULL)
{
	MessageBox("You load");
    return;
}
char data1[37],data2[104];
strcpy(data2,"0987654321\x0");
strcpy(data1,"0983948345\x0");
if(writecard(1,2,data1,data2,2)==1)
{
	printf(data2);
	MessageBox("Write 2 success\n");  
}
else
  MessageBox("write 2 Error");	

}

void CAboutDlg::OnDoubleclickedOk() 
{
	// TODO: Add your control notification handler code here
	
}

void CTest1Dlg::OnRead() 
{
	// TODO: Add your control notification handler code here
	m_bWrite=0;
	m_sData1="";
	m_sData2="";
	UpdateData(FALSE);
	
}

void CTest1Dlg::OnWrite() 
{
	// TODO: Add your control notification handler code here
	m_bWrite=1;
	UpdateData(FALSE);
	
}
#ifdef __cpluscpus
}
#endif

⌨️ 快捷键说明

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