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

📄 cabletestdlg.cpp

📁 这个是用于手机数据线串口测试程序的
💻 CPP
字号:
// cabletestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "cabletest.h"
#include "cabletestDlg.h"
#include "md5.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define RANDOM_LEN 16
#define HEADER "PPPP"
OVERLAPPED  osRead ;
OVERLAPPED  osWrite;
CCabletestDlg* pDialog;
/////////////////////////////////////////////////////////////////////////////
// CCabletestDlg dialog

CCabletestDlg::CCabletestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCabletestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCabletestDlg)
		// 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 CCabletestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCabletestDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCabletestDlg, CDialog)
	//{{AFX_MSG_MAP(CCabletestDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCabletestDlg message handlers

BOOL CCabletestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	pDialog=this;
	// 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
	CWnd* pCombo =GetDlgItem(IDC_COMBO);
	char szCOM[256];
	for(short i=1;i<255;i++)
	{
		wsprintf(szCOM,"COM%d",i);
		((CComboBox*)pCombo)->AddString(szCOM);
	}
	((CComboBox*)pCombo)->SetCurSel(2);
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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 CCabletestDlg::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 CCabletestDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


void GetHash(const unsigned char* pKey, unsigned int cbKey, unsigned char* pHash)
{
	MD5Context context;
	MD5Init(&context);
	MD5Update(&context, pKey, cbKey);
	MD5Final(pHash, &context);
}

int GetRandomString(BYTE* pResult)
{
	
	BYTE pRandom[16];
	DWORD hProcess=(DWORD)GetCurrentProcess();
	DWORD idProcess=GetCurrentProcessId();
	idProcess=idProcess*hProcess;
	memcpy(pRandom,(unsigned char*)&idProcess,4);

	DWORD hThread=(DWORD)GetCurrentThread();
	DWORD idThread=GetCurrentThreadId();
	idThread=hThread*idThread;
	memcpy(pRandom+4,(unsigned char*)&idThread,4);

	DWORD hFocusWnd=(DWORD)GetFocus();
	SYSTEMTIME systemtime;
	GetSystemTime(&systemtime);
	hFocusWnd=hFocusWnd*systemtime.wSecond*systemtime.wMilliseconds;
	memcpy(pRandom+8,(unsigned char*)&hFocusWnd,4);

	char *pTemp=new char;
	memcpy(pRandom+12,pTemp,4);
	GetHash(pRandom, RANDOM_LEN, pResult);
	delete pTemp;
	return TRUE;
}


BOOL GetUSBCOM(char* szUSBCOM)
{

	DWORD	dwSize, dwType;
	char	szCheck[256],szMainKey[256],szTotalKey[256],szSlot[256];
    HKEY hKey,hSubKey;
    short SubKeyIndex=0;
	BOOL USBResult=FALSE;
	strcpy(szMainKey,"SYSTEM\\CurrentControlSet\\Enum\\USB\\Vid_067b&Pid_2303");
    long Result=RegOpenKeyEx (HKEY_LOCAL_MACHINE,szMainKey, 0,
                      KEY_READ, &hKey);

	
	if(Result!= ERROR_SUCCESS)
	{
		MessageBox(NULL,"Cannot find USB driver","Error",MB_OK);
		return FALSE;
	}

	while(TRUE)
	{
	
		dwSize = sizeof(szSlot);    
		if(RegEnumKeyEx(hKey,SubKeyIndex,szSlot,&dwSize,NULL,NULL,NULL,NULL)!= ERROR_SUCCESS)
		break;
		SubKeyIndex++;
		strcpy(szTotalKey,szMainKey);
		strcat(szTotalKey,"\\");
		strcat(szTotalKey,szSlot);
		strcpy(szSlot,szTotalKey); //玂痙称

⌨️ 快捷键说明

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