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

📄 rfid_desktopreader.cpp

📁 RFID读卡器源码,vc.net编写,bcgp界面控件
💻 CPP
字号:
// RFID_DesktopReader.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "RFID_DesktopReader.h"

#include "MainFrm.h"
#include "RFID_DesktopReaderDoc.h"
#include "RFID_DesktopReaderView.h"
//#include "RFIDScanView.h"

#include "AppLookDlg.h"
#include "ExportFunc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CRFID_DesktopReaderApp

BEGIN_MESSAGE_MAP(CRFID_DesktopReaderApp, CWinApp)
	//{{AFX_MSG_MAP(CRFID_DesktopReaderApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_COMMAND(ID_VIEW_APP_LOOK, OnViewAppLook)
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRFID_DesktopReaderApp construction

CRFID_DesktopReaderApp::CRFID_DesktopReaderApp() :
	CBCGPWorkspace (TRUE)
{
	m_bLoadSaveFrameBarsOnly = TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CRFID_DesktopReaderApp object

CRFID_DesktopReaderApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CRFID_DesktopReaderApp initialization
HINSTANCE g_hInstMaster;


// CRFID_DesktopReaderApp 初始化
int CRFID_DesktopReaderApp::InitMaster()
{
	g_hInstMaster=LoadLibrary(_T("MasterRD.dll"));
	if(g_hInstMaster==NULL)
		return 0;

		(FARPROC&)rf_init_com  = GetProcAddress(g_hInstMaster,"rf_init_com");
	(FARPROC&)rf_get_snr=GetProcAddress(g_hInstMaster,"rf_get_snr");
	(FARPROC&)rf_antenna_sta=GetProcAddress(g_hInstMaster,"rf_antenna_sta");
	(FARPROC&)rf_request=GetProcAddress(g_hInstMaster,"rf_request");
	(FARPROC&)rf_anticoll=GetProcAddress(g_hInstMaster,"rf_anticoll");
	(FARPROC&)rf_select=GetProcAddress(g_hInstMaster,"rf_select");
	(FARPROC&)rf_halt=GetProcAddress(g_hInstMaster,"rf_halt");
	(FARPROC&)rf_M1_authentication2=GetProcAddress(g_hInstMaster,"rf_M1_authentication2");
	(FARPROC&)rf_M1_read=GetProcAddress(g_hInstMaster,"rf_M1_read");
	(FARPROC&)rf_M1_write=GetProcAddress(g_hInstMaster,"rf_M1_write");
	(FARPROC&)rf_ClosePort=GetProcAddress(g_hInstMaster,"rf_ClosePort");
	(FARPROC&)rf_get_snr=GetProcAddress(g_hInstMaster,"rf_get_snr");


//ISO 15692 Func
		(FARPROC&)ISO15693_Inventory    = GetProcAddress(g_hInstMaster,"ISO15693_Inventory");
		(FARPROC&)ISO15693_Inventorys   = GetProcAddress(g_hInstMaster,"ISO15693_Inventorys");
		(FARPROC&)ISO15693_Get_System_Information    = GetProcAddress(g_hInstMaster,"ISO15693_Get_System_Information");
		(FARPROC&)ISO15693_Select           = GetProcAddress(g_hInstMaster,"ISO15693_Select");
		(FARPROC&)ISO15693_Reset_To_Ready           = GetProcAddress(g_hInstMaster,"ISO15693_Reset_To_Ready");
		(FARPROC&)ISO15693_Stay_Quiet           = GetProcAddress(g_hInstMaster,"ISO15693_Stay_Quiet");
		(FARPROC&)ISO15693_Get_Block_Security           = GetProcAddress(g_hInstMaster,"ISO15693_Get_Block_Security");
		(FARPROC&)ISO15693_Read           = GetProcAddress(g_hInstMaster,"ISO15693_Read");
		(FARPROC&)ISO15693_Write           = GetProcAddress(g_hInstMaster,"ISO15693_Write");
		(FARPROC&)ISO15693_Lock_Block           = GetProcAddress(g_hInstMaster,"ISO15693_Lock_Block");
		(FARPROC&)ISO15693_Write_AFI           = GetProcAddress(g_hInstMaster,"ISO15693_Write_AFI");
		(FARPROC&)ISO15693_Lock_AFI           = GetProcAddress(g_hInstMaster,"ISO15693_Lock_AFI");
		(FARPROC&)ISO15693_Write_DSFID           = GetProcAddress(g_hInstMaster,"ISO15693_Write_DSFID");
		(FARPROC&)ISO15693_Lock_DSFID           = GetProcAddress(g_hInstMaster,"ISO15693_Lock_DSFID");
		(FARPROC&)rf_init_type           = GetProcAddress(g_hInstMaster,"rf_init_type");
		(FARPROC&)rf_light           = GetProcAddress(g_hInstMaster,"rf_light");
		(FARPROC&)rf_beep           = GetProcAddress(g_hInstMaster,"rf_beep");
		(FARPROC&)rf_get_device_number          = GetProcAddress(g_hInstMaster,"rf_get_device_number");

		
		
		
		if(
			NULL == rf_init_com           ||
			NULL == rf_antenna_sta    ||
			NULL == rf_request    ||
			NULL == rf_anticoll    ||
			NULL == rf_select    ||
			NULL == rf_halt    ||
			NULL == ISO15693_Inventory    ||
			NULL == ISO15693_Get_System_Information    ||
			NULL == ISO15693_Select    ||
			NULL == ISO15693_Reset_To_Ready    ||
			NULL == ISO15693_Stay_Quiet    ||
			NULL == ISO15693_Get_Block_Security    ||
			NULL == ISO15693_Read    ||
			NULL == ISO15693_Write    ||
			NULL == ISO15693_Select    ||
			NULL == rf_get_device_number    ||
			NULL == rf_ClosePort 
		     ){			
			AfxMessageBox(_T("Load MasterRD.dll failed !"));
			return FALSE;
		}

	return 1;


}

BOOL CRFID_DesktopReaderApp::InitInstance()
{
	// Initialize OLE libraries
//	::CoInitialize(NULL);

	InitMaster();
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_OLE_INIT_FAILED);
		return FALSE;
	}

	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("Vacorp\\RFID_DesktopReader"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	SetActiveFrame (MainFrame);

	// Initialize all Managers for usage. They are automatically constructed
	// if not yet present
	InitContextMenuManager();
	InitKeyboardManager();
	InitShellManager();

	// Enable user-defined tools. If you want allow more than 10 tools,
	// add tools entry to resources (ID_USER_TOOL11, ID_USER_TOOL12,...)
	EnableUserTools (ID_TOOLS_ENTRY, ID_USER_TOOL1, ID_USER_TOOL10);

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CRFID_DesktopReaderDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CRFID_DesktopReaderView));
	AddDocTemplate(pDocTemplate);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	LoadCustomState ();

	// The one and only window has been initialized, so show and update it.
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();

	// Set application general look:
	CAppLookDlg dlg (TRUE);
	dlg.DoModal ();

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CRFID_DesktopReaderApp message handlers

int CRFID_DesktopReaderApp::ExitInstance() 
{
	BCGCBProCleanUp();
	//::CoUninitialize();


	return CWinApp::ExitInstance();
}


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

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

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	CBCGPURLLinkButton	m_bntURL;
	CBCGPURLLinkButton	m_btnMail;
	CString	m_strVersion;
	//}}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)
	virtual BOOL OnInitDialog();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	m_strVersion = _T("");
	//}}AFX_DATA_INIT
	m_strVersion.Format (_T("%d.%d"), _BCGCBPRO_VERSION_MAJOR, _BCGCBPRO_VERSION_MINOR);
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	DDX_Control(pDX, IDC_URL, m_bntURL);
	DDX_Control(pDX, IDC_MAIL, m_btnMail);
	DDX_Text(pDX, IDC_VERSION, m_strVersion);
	//}}AFX_DATA_MAP
}

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

// App command to run the dialog
void CRFID_DesktopReaderApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

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

	m_btnMail.SetURLPrefix (_T("mailto:"));
	m_btnMail.SetURL (_T("info@bcgsoft.com"));
	m_btnMail.SizeToContent ();
	m_btnMail.SetTooltip (_T("Send mail to author"));

	m_bntURL.SizeToContent ();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CRFID_DesktopReaderApp::PreLoadState ()
{

	GetContextMenuManager()->AddMenu (_T("My menu"), IDR_CONTEXT_MENU);

	// TODO: add another context menus here
}

void CRFID_DesktopReaderApp::SetActiveFrame (OUTLOOK_FRAME frame)
{
	CString strOldRegPath = GetRegSectionPath ();

	// Save user tools:
	if (GetUserToolsManager () != NULL)
	{
		GetUserToolsManager ()->SaveState (GetRegSectionPath ());
	}

	switch (frame)
	{
	case MainFrame:
		SetRegistryBase (_T("Main Frame Settings"));
		break;

	//case MailFrame:
	//	SetRegistryBase (_T("Mail Settings"));
	//	break;

	default:
		ASSERT (FALSE);
	}

	// Load user tools:
	if (GetUserToolsManager () != NULL)
	{
		GetUserToolsManager ()->LoadState (strOldRegPath);
	}
}

/////////////////////////////////////////////////////////////////////////////
// CRFID_DesktopReaderApp message handlers

void CRFID_DesktopReaderApp::OnViewAppLook() 
{
	CAppLookDlg dlg (FALSE);
	dlg.DoModal ();
}

bool CRFID_DesktopReaderApp::CreateDBConnection(CString strUDLFile)
{
	if(m_adoConnection.OpenFromUDL(strUDLFile))
        return true;
	else return false;
}

⌨️ 快捷键说明

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