📄 demodlg.cpp
字号:
/*----------------------------------------------------------------------------
* Copyright (c) 2001 by National Semiconductor Corporation
* National Semiconductor Corporation
* 2900 Semiconductor Drive
* Santa Clara, California 95051
*
* All rights reserved
*
*<<<-------------------------------------------------------------------------
* File Contents:
* DemoDlg.cpp
*
* Project: USB Demo Application
* Author : Yan Nosovitsky
* Date : Dec 2001
*----------------------------------------------------------------------->>>*/
// DemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Demo.h"
#include "DemoDlg.h"
#include "CmdTabCtrl.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()
/////////////////////////////////////////////////////////////////////////////
// CDemoDlg dialog
CDemoDlg::CDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDemoDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDemoDlg)
DDX_Control(pDX, IDC_COMMAND_TAB, m_cmdTabCtrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDemoDlg, CDialog)
//{{AFX_MSG_MAP(CDemoDlg)
ON_WM_SYSCOMMAND()
ON_WM_DESTROY()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(ID_HELP_ABOUT,OnHelpAbout)
ON_COMMAND(ID_HTML_HELP,OnHTMLHelp)
ON_COMMAND(ID_REQUESTS,OnReqTab)
ON_COMMAND(ID_BULK,OnBulkTab)
ON_COMMAND(ID_ISOCHRONOUS,OnIsoTab)
ON_COMMAND(ID_INTERRUPT,OnIntTab)
ON_COMMAND(ID_DIAGNOSTIC,OnDiagTab)
ON_NOTIFY(TCN_SELCHANGE, IDC_COMMAND_TAB, OnSelchangeCommandTab)
ON_NOTIFY(TCN_SELCHANGING, IDC_COMMAND_TAB, OnSelchangingCommandTab)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDemoDlg message handlers
BOOL CDemoDlg::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
USBDriver *curUSBDriver = USBDriver::GetUSBDriver();
if (curUSBDriver->IsUSBDriverHaveError())
MessageBox(curUSBDriver->GetErrorDescriptor(),"Error",MB_ICONERROR | MB_OK);
//Tab Control
m_cmdTabCtrl.InsertItem(CONTROL, _T("&Requests"));
m_cmdTabCtrl.InsertItem(BULK, _T("Bulk"));
m_cmdTabCtrl.InsertItem(INTERRUPT, _T("Interrupt"));
m_cmdTabCtrl.InsertItem(ISOCHRONOUS, _T("Isochronous"));
m_cmdTabCtrl.InsertItem(DIAGNOSTIC, _T("Diagnostic"));
m_cmdTabCtrl.CommandTabCtrlInit();
MenuUpdateOnCommand();
// m_cmdTabCtrl.m_ControlTab->controlFunc->SetDrvHandle(driver->GetDriverHandle());
// m_cmdTabCtrl.m_BulkTab->bulkFunc->SetDrvHandle(driver->GetDriverHandle());
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
if ((nID & 0xFFF0) == SC_CLOSE)
{
/* stop running tests */
m_cmdTabCtrl.m_BulkTab->bulkFunc->StopLastProcess();
m_cmdTabCtrl.m_IsoTab->isoFunc->StopLastProcess();
m_cmdTabCtrl.m_IntTab->intFunc->StopLastProcess();
ControlFunc::SendSetupPacketOut(STOP_REQUEST,0,0,0);
}
CDialog::OnSysCommand(nID, lParam);
}
}
void CDemoDlg::OnHelpAbout()
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
void CDemoDlg::OnDestroy()
{
WinHelp(0L, HELP_QUIT);
CDialog::OnDestroy();
}
// 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 CDemoDlg::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 CDemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDemoDlg::OnSelchangeCommandTab(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
MenuUpdateOnCommand();
*pResult = 0;
}
void CDemoDlg::OnSelchangingCommandTab(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CDemoDlg::OnReqTab()
{
m_cmdTabCtrl.TabSwitcher(CONTROL);
MenuUpdateOnCommand();
}
void CDemoDlg::OnBulkTab()
{
m_cmdTabCtrl.TabSwitcher(BULK);
MenuUpdateOnCommand();
}
void CDemoDlg::OnIsoTab()
{
m_cmdTabCtrl.TabSwitcher(ISOCHRONOUS);
MenuUpdateOnCommand();
}
void CDemoDlg::OnIntTab()
{
m_cmdTabCtrl.TabSwitcher(INTERRUPT);
MenuUpdateOnCommand();
}
void CDemoDlg::OnDiagTab()
{
m_cmdTabCtrl.TabSwitcher(DIAGNOSTIC);
MenuUpdateOnCommand();
}
void CDemoDlg::OnHTMLHelp()
{
HtmlHelp( AfxGetMainWnd()->m_hWnd,
"USBDemo.chm",
HH_DISPLAY_TOC,
NULL) ;
}
void CDemoDlg::MenuUpdateOnCommand()
{
//This function should be called after the new tab/command selection
//has been made
CWnd* pMain = AfxGetMainWnd();
if (pMain != NULL) {
CMenu* pMenu = pMain->GetMenu();
CMenu* submenu = pMenu->GetSubMenu(0); //View popup menu
for (unsigned int i=0;i<submenu->GetMenuItemCount();i++) {
UINT state = submenu->GetMenuState(i, MF_BYPOSITION);
// ASSERT(state != 0xFFFFFFFF);
if (state & MF_CHECKED) {
submenu->CheckMenuItem(i, MF_UNCHECKED | MF_BYPOSITION);
break;
}
}
int CurSel = m_cmdTabCtrl.GetCurSel();
submenu->CheckMenuItem(CurSel, MF_CHECKED | MF_BYPOSITION);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -