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

📄 indentitytestctl.cpp

📁 U盘身份识别软件
💻 CPP
字号:
// IndentityTestCtl.cpp : Implementation of the CIndentityTestCtrl ActiveX Control class.

#include "stdafx.h"
#include "IndentityTest.h"
#include "IndentityTestCtl.h"
#include "IndentityTestPpg.h"
#include "Function.h"
#include "rc4.h"

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


IMPLEMENT_DYNCREATE(CIndentityTestCtrl, COleControl)


/////////////////////////////////////////////////////////////////////////////
// Message map

BEGIN_MESSAGE_MAP(CIndentityTestCtrl, COleControl)
	//{{AFX_MSG_MAP(CIndentityTestCtrl)
	// NOTE - ClassWizard will add and remove message map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG_MAP
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// Dispatch map

BEGIN_DISPATCH_MAP(CIndentityTestCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CIndentityTestCtrl)
	DISP_FUNCTION(CIndentityTestCtrl, "InitU", InitU, VT_BOOL, VTS_NONE)
	DISP_FUNCTION(CIndentityTestCtrl, "IndentityJudge", IndentityJudge, VT_I2, VTS_NONE)
	DISP_FUNCTION(CIndentityTestCtrl, "GetUData", GetUData, VT_BSTR, VTS_NONE)
	//}}AFX_DISPATCH_MAP
	DISP_FUNCTION_ID(CIndentityTestCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()


/////////////////////////////////////////////////////////////////////////////
// Event map

BEGIN_EVENT_MAP(CIndentityTestCtrl, COleControl)
	//{{AFX_EVENT_MAP(CIndentityTestCtrl)
	// NOTE - ClassWizard will add and remove event map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_EVENT_MAP
END_EVENT_MAP()


/////////////////////////////////////////////////////////////////////////////
// Property pages

// TODO: Add more property pages as needed.  Remember to increase the count!
BEGIN_PROPPAGEIDS(CIndentityTestCtrl, 1)
	PROPPAGEID(CIndentityTestPropPage::guid)
END_PROPPAGEIDS(CIndentityTestCtrl)


/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid

IMPLEMENT_OLECREATE_EX(CIndentityTestCtrl, "INDENTITYTEST.IndentityTestCtrl.1",
	0x74150f45, 0x3407, 0x4f8e, 0xab, 0xfd, 0x39, 0xa2, 0x5e, 0xb, 0xd2, 0x44)

//74150F45-3407-4F8E-ABFD-39A25E0BD244
/////////////////////////////////////////////////////////////////////////////
// Type library ID and version

IMPLEMENT_OLETYPELIB(CIndentityTestCtrl, _tlid, _wVerMajor, _wVerMinor)


/////////////////////////////////////////////////////////////////////////////
// Interface IDs

const IID BASED_CODE IID_DIndentityTest =
		{ 0xf59edbf5, 0xc1a1, 0x41ef, { 0xa7, 0xce, 0xaa, 0x17, 0xb4, 0x81, 0x7c, 0x1c } };
const IID BASED_CODE IID_DIndentityTestEvents =
		{ 0xd62c428, 0x98dc, 0x4d24, { 0xac, 0x88, 0x7b, 0x3d, 0x4e, 0xa2, 0x79, 0xd6 } };


/////////////////////////////////////////////////////////////////////////////
// Control type information

static const DWORD BASED_CODE _dwIndentityTestOleMisc =
	OLEMISC_ACTIVATEWHENVISIBLE |
	OLEMISC_SETCLIENTSITEFIRST |
	OLEMISC_INSIDEOUT |
	OLEMISC_CANTLINKINSIDE |
	OLEMISC_RECOMPOSEONRESIZE;

IMPLEMENT_OLECTLTYPE(CIndentityTestCtrl, IDS_INDENTITYTEST, _dwIndentityTestOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CIndentityTestCtrl::CIndentityTestCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CIndentityTestCtrl

BOOL CIndentityTestCtrl::CIndentityTestCtrlFactory::UpdateRegistry(BOOL bRegister)
{
	// TODO: Verify that your control follows apartment-model threading rules.
	// Refer to MFC TechNote 64 for more information.
	// If your control does not conform to the apartment-model rules, then
	// you must modify the code below, changing the 6th parameter from
	// afxRegApartmentThreading to 0.

	if (bRegister)
		return AfxOleRegisterControlClass(
			AfxGetInstanceHandle(),
			m_clsid,
			m_lpszProgID,
			IDS_INDENTITYTEST,
			IDB_INDENTITYTEST,
			afxRegApartmentThreading,
			_dwIndentityTestOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CIndentityTestCtrl::CIndentityTestCtrl - Constructor

CIndentityTestCtrl::CIndentityTestCtrl()
{
	InitializeIIDs(&IID_DIndentityTest, &IID_DIndentityTestEvents);

	// TODO: Initialize your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CIndentityTestCtrl::~CIndentityTestCtrl - Destructor

CIndentityTestCtrl::~CIndentityTestCtrl()
{
	// TODO: Cleanup your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CIndentityTestCtrl::OnDraw - Drawing function

void CIndentityTestCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	// TODO: Replace the following code with your own drawing code.
	//pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
	//pdc->Ellipse(rcBounds);
	pdc->TextOut(rcBounds.left+6,rcBounds.top+4, "西安网鑫U盘身份识别系统");
}


/////////////////////////////////////////////////////////////////////////////
// CIndentityTestCtrl::DoPropExchange - Persistence support

void CIndentityTestCtrl::DoPropExchange(CPropExchange* pPX)
{
	ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
	COleControl::DoPropExchange(pPX);

	// TODO: Call PX_ functions for each persistent custom property.

}


/////////////////////////////////////////////////////////////////////////////
// CIndentityTestCtrl::OnResetState - Reset control to default state

void CIndentityTestCtrl::OnResetState()
{
	COleControl::OnResetState();  // Resets defaults found in DoPropExchange

	// TODO: Reset any other control state here.
}


/////////////////////////////////////////////////////////////////////////////
// CIndentityTestCtrl::AboutBox - Display an "About" box to the user

void CIndentityTestCtrl::AboutBox()
{
	CDialog dlgAbout(IDD_ABOUTBOX_INDENTITYTEST);
	dlgAbout.DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// CIndentityTestCtrl message handlers

BOOL CIndentityTestCtrl::InitU() //  bool  true  false
{
	// TODO: Add your dispatch handler code here
	HKEY hkey;
    char sz[256];
    DWORD dwtype,sl = 256;
    USB_ID="";

	for(int i=1;i<8;i++)
	{
		if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Services\\Disk\\Enum",\
			NULL, KEY_ALL_ACCESS, &hkey)==ERROR_SUCCESS)
		{
			CString id;
			id.Format("%d",i);
			if(RegQueryValueEx(hkey,id,NULL,&dwtype,(LPBYTE)sz,&sl)==ERROR_SUCCESS)
			{
				CString str=(CString)sz;
				USB_ID=str;
			}
		}
	}
	RegCloseKey(hkey);


	if(USB_ID.GetLength()==0)
	{
		return false;
		//AfxMessageBox("没有发现移动设备!");
	}
	else
	{
        //AfxMessageBox("U盘初始化成功 ID=  "+USB_ID);
		return true;
	}
}

short CIndentityTestCtrl::IndentityJudge() 
{
	// TODO: Add your dispatch handler code here

	unsigned char MBRBuf[512];

	CString name;
	CString driver;
		
	int id;				// 选择移动设备的编号

	if(USB_ID.GetLength()==0)
	{
		AfxMessageBox("请插入U盘!");
		return 0;
	}

	//id=m_select.GetCurSel();
	//m_select.GetLBText(id,name);
	name=USB_ID;

	// 确定选择的磁盘
	driver=GetDiskNumber(name);

	// 读磁盘的MBR区
	if(ReadDisk(driver,MBRBuf,512)==0)
		return 0;
	
	char ReadBuffer[512];
	memcpy(ReadBuffer,MBRBuf,512);
	
	CString str;
    str.Format("%s",ReadBuffer);
	if(str=="西安网鑫科技")
	{
		AfxMessageBox("身份识别成功 公司:"+str);
	}
	else
	{
		AfxMessageBox("身份识别错误,请插入U盘!");
	}
	return 0;
}

BSTR CIndentityTestCtrl::GetUData() 
{
	CString strResult;
	// TODO: Add your dispatch handler code here
	unsigned char MBRBuf[512];

	CString name;
	CString driver;
		
	int id;				// 选择移动设备的编号

	if(USB_ID.GetLength()==0)
	{
		AfxMessageBox("请插入U盘!");
		return 0;
	}

	//id=m_select.GetCurSel();
	//m_select.GetLBText(id,name);
	name=USB_ID;

	// 确定选择的磁盘
	driver=GetDiskNumber(name);

	// 读磁盘的MBR区
	if(ReadDisk(driver,MBRBuf,512)==0)
		return 0;
	
	char ReadBuffer[512];
	memcpy(ReadBuffer,MBRBuf,512);
	
    strResult.Format("%s",ReadBuffer);
	if (strResult!="")
	{
		//AfxMessageBox(strResult);
		return strResult.AllocSysString();
	}
	else
	{
		return NULL;
	}
}

⌨️ 快捷键说明

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