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

📄 dialogusbdlg.cpp

📁 开发usb固件时
💻 CPP
字号:
// DialogUSBDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DialogUSB.h"
#include "DialogUSBDlg.h"

#include "Search_USB.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()

/////////////////////////////////////////////////////////////////////////////
// CDialogUSBDlg dialog

CDialogUSBDlg::CDialogUSBDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogUSBDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialogUSBDlg)
		// 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 CDialogUSBDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialogUSBDlg)
	DDX_Control(pDX, IDC_LIST_USB, m_List_USB);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDialogUSBDlg, CDialog)
	//{{AFX_MSG_MAP(CDialogUSBDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_LOOKUP_USB, On_Lookup_USB)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogUSBDlg message handlers

BOOL CDialogUSBDlg::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
	SetDlgItemText(IDC_USB_Information, _T("请扫描本机的设备"));
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CDialogUSBDlg::On_Lookup_USB() 
{
	// TODO: Add your control notification handler code here
	int i, length;
	BOOL result= FALSE;
	CStringArray ArrayUSB;
	CStringArray FindUSB;
	CString sTemp;
	CString sBuf= _T("Flash Disk");

//	GetDlgItem(IDC_USB_Information)->SetWindowText
	SetDlgItemText(IDC_USB_Information, _T("正在扫描本机的设备..."));
	UpdateData();
	ArrayUSB.RemoveAll();
	Search_USB usb;
	usb.Search(&ArrayUSB);
	ArrayUSB.FreeExtra();
	m_List_USB.ResetContent();
	SetDlgItemText(IDC_USB_Information, _T("USB 设备信息"));
	length= ArrayUSB.GetSize();
	for(i= 0; i< length; i++)
	{
		m_List_USB.AddString(ArrayUSB.GetAt(i));
	}
	//////////////////////////////////
	//
	for(i= 0; i< length; i++)
	{
		sTemp= ArrayUSB.GetAt(i);
		int len= sTemp.Find(sBuf);
		if(len > 0)
		{
			result= TRUE;
			break;
		}
	}
	if(result)
	{
		length= i;
		FindUSB.Add(sTemp);
		sBuf= _T("connected");
		for(i; i> 0; i--)
		{
			sTemp= ArrayUSB.GetAt(i);
			int len= sTemp.Find(sBuf);
			if(len > 0)
			{
				break;
			}
		
		}
		length= sTemp.Find(_T("["));
		sTemp= sTemp.Right(sTemp.GetLength()- length- 1);
		length= atoi(sTemp.GetBuffer(2));
		sTemp.Format("%d Port", length);
		FindUSB.Add(sTemp);
		sBuf= _T("HUB");
		for(i; i> 0; i--)
		{
			sTemp= ArrayUSB.GetAt(i);
			int len= sTemp.Find(sBuf);
			if(len > 0)
			{
				//主HUB 名
				sTemp= ArrayUSB.GetAt(i);
				length= sTemp.Find(_T("USB"));
				sTemp= sTemp.Right(sTemp.GetLength()- length);
				FindUSB.Add(sTemp);
				//主控器名:
				sTemp= ArrayUSB.GetAt(i- 1);
				length= sTemp.Find(_T("{"));
				sTemp= sTemp.Right(sTemp.GetLength()- length);
				FindUSB.Add(sTemp);
			}
		
		}

	}
	length= FindUSB.GetSize();
	for(i= 0; i< length; i++)
	{
		sTemp= FindUSB.GetAt(i);
	}
}

⌨️ 快捷键说明

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