📄 mainfrm.cpp
字号:
////////////////////////////////////////////////////////////////////////////////
// MainFrm.cpp : implementation of the CMainFrame class
// $Header: /USB/Util/EzMr/MainFrm.cpp 9 3/07/02 4:51p Tpm $
// Copyright (c) 2000 Cypress Semiconductor. May not be reproduced without permission.
// See the EzUsb Developer's Kit license agreement for more details.
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "EzMr.h"
#include "MainFrm.h"
#include "EzMrProp.h"
#include "EzMrFrm.h"
#include "EzMrDoc.h"
#include "EzMrView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
ON_COMMAND_EX(CG_ID_VIEW_DEVS, OnBarCheck)
ON_UPDATE_COMMAND_UI(CG_ID_VIEW_DEVS, OnUpdateControlBarMenu)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_OPTIONS_PROPERTIES, OnProperties)
//}}AFX_MSG_MAP
// Global help commands
ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
ON_COMMAND_EX_RANGE(ID_PLUGIN_TOOL1, ID_PLUGIN_TOOL25, OnPluginTools)
ON_UPDATE_COMMAND_UI(ID_PLUGIN_TOOL1, OnUpdatePluginTools)
ON_CBN_SELCHANGE(IDC_SEL_TARG, OnSelTarget)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
m_pTxt_idx = 0;
}
CMainFrame::~CMainFrame()
{
for(int idx=0; idx<m_pTxt_idx; idx++)
{
delete m_pTxt[idx];
}
}
void CMainFrame::DockControlBarLeftOf(CToolBar* Bar,CToolBar* LeftOf)
{
CRect rect;
DWORD dw;
UINT n;
RecalcLayout(); // get MFC to adj dimensions of all docked ToolBars
LeftOf->GetWindowRect(&rect);
rect.OffsetRect(1,0);
dw=LeftOf->GetBarStyle();
n = 0;
n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;
DockControlBar(Bar,n,&rect); //simulate Toolbar dragged to location and docked
}
void CMainFrame::NewTBarText(CToolBar* pTB, int idx, UINT nID, int nPw, char* pLbl)
{
CRect rect;
CFont* pFont = m_wndTBarTarg.GetFont(); // used hereafter
m_pTxt[m_pTxt_idx] = new CStatic();
pTB->SetButtonInfo(idx, nID, TBBS_SEPARATOR, nPw);
pTB->GetItemRect(idx, &rect);
rect.top += 4;
m_pTxt[m_pTxt_idx]->Create(pLbl, WS_CHILD | WS_VISIBLE, rect, pTB, nID);
m_pTxt[m_pTxt_idx]->SetFont(pFont, TRUE);
m_pTxt_idx++;
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.Create(this) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
theApp.pm_wndToolBar = &m_wndToolBar;
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// Remove this if you don't want tool tips or a resizeable toolbar
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
// Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
{
// Initialize dialog bar m_wndDlgBarUsbDevs
if (!m_wndDlgBarUsbDevs.Create(this, CG_IDD_DEVS,
CBRS_LEFT | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE,
CG_ID_VIEW_DEVS))
{
TRACE0("Failed to create dialog bar m_wndDlgBarUsbDevs\n");
return -1; // fail to create
}
// m_wndDlgBarUsbDevs.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
// EnableDocking(CBRS_ALIGN_ANY);
m_wndDlgBarUsbDevs.EnableDocking(0);
EnableDocking(0);
DockControlBar(&m_wndDlgBarUsbDevs);
ShowControlBar(&m_wndDlgBarUsbDevs, FALSE, FALSE); // arange a little
m_wndDlgBarUsbDevs.SetWindowText("USB Device Selection");
FloatControlBar(&m_wndDlgBarUsbDevs, CPoint(50,300));
}
CRect rect;
{ //TPMDo: Add m_wndTBarTarg manually
if (!m_wndTBarTarg.Create(this,
WS_CHILD | CBRS_TOP | WS_VISIBLE |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
NULL /*ID_VIEW_TBAR_RES*/) ||
!m_wndTBarTarg.LoadToolBar(IDR_TBAR_TARG))
{
TRACE0("Failed to create dialog bar m_wndTBarTarg\n");
return -1; // fail to create
}
m_wndTBarTarg.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndTBarTarg);
DockControlBarLeftOf(&m_wndTBarTarg,&m_wndToolBar);
NewTBarText(&m_wndTBarTarg, 2, IDC_STR_TARG, 40, "Target");
m_wndTBarTarg.SetButtonInfo(3, IDC_SEL_TARG, TBBS_SEPARATOR, 120); // bogart
m_wndTBarTarg.GetItemRect(3, &rect);
rect.top = 0;
rect.bottom = rect.top + 200;
if (!m_CBoxSelTarg.Create(
CBS_DROPDOWNLIST|WS_VISIBLE|WS_TABSTOP|WS_VSCROLL|WS_CHILD,
rect, &m_wndTBarTarg, IDC_SEL_TARG))
{
TRACE0("Failed to create combo-box IDC_SEL_TARG\n");
return FALSE;
}
m_CBoxSelTarg.AddString("EZ-USB & FX");
m_CBoxSelTarg.AddString("FX2");
m_CBoxSelTarg.AddString("SX2");
if(theApp.m_nTarg == 2)
m_CBoxSelTarg.SetCurSel(2);
else if(theApp.m_nTarg == 1)
m_CBoxSelTarg.SetCurSel(1);
else
m_CBoxSelTarg.SetCurSel(0);
}
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CMDIFrameWnd::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnProperties()
{
// TODO: The property sheet attached to your project
// via this function is not hooked up to any message
// handler. In order to actually use the property sheet,
// you will need to associate this function with a control
// in your project such as a menu item or tool bar button.
CMyPropertySheet propSheet;
int bUpdateBars = 0;
propSheet.m_Page1.m_nVerbose = theApp.m_nVerbose;
propSheet.m_Page1.m_nPopUpOps = theApp.m_nPopUpOps;
propSheet.m_Page1.m_nAutoHoldRun = theApp.m_nAutoHoldRun;
propSheet.m_Page1.m_bThreaded = theApp.m_bThreaded;
propSheet.m_Page1.m_nTarg = theApp.m_nTarg;
propSheet.m_Page1.m_nMaxOpsPending = theApp.m_nMaxOpsPending;
propSheet.m_Page1.m_psp.dwFlags &= ~PSP_HASHELP;
propSheet.m_Page2.m_psp.dwFlags &= ~PSP_HASHELP;
if(propSheet.DoModal() == IDOK)
{
theApp.m_nVerbose = propSheet.m_Page1.m_nVerbose;
if(theApp.m_nPopUpOps != propSheet.m_Page1.m_nPopUpOps)
{
theApp.m_nPopUpOps = propSheet.m_Page1.m_nPopUpOps;
bUpdateBars = 1;
}
theApp.m_nAutoHoldRun = propSheet.m_Page1.m_nAutoHoldRun;
theApp.m_bThreaded = propSheet.m_Page1.m_bThreaded;
theApp.m_nMaxOpsPending = propSheet.m_Page1.m_nMaxOpsPending;
theApp.m_nTarg = propSheet.m_Page1.m_nTarg;
if(theApp.m_nMaxOpsPending > MAX_OPS_PENDING) theApp.m_nMaxOpsPending = MAX_OPS_PENDING;
}
CFrameWnd* pFrameWnd = GetActiveFrame( );
// ((CEzMrFrame*)pFrameWnd)->InitEzMrCtrlBars(); //TPMTPMTPM Should set all frames
POSITION dpos = theApp.m_pUSBDocTemplate->GetFirstDocPosition();
while (dpos != 0)
{
CDocument* pDoc = theApp.m_pUSBDocTemplate->GetNextDoc(dpos);
ASSERT(pDoc != 0);
POSITION vpos = pDoc->GetFirstViewPosition();
CEzMrView* pView = (CEzMrView*)(pDoc->GetNextView(vpos));
// pView->((CEzMrFrame*)GetParentFrame())->InitEzMrCtrlBars();
CEzMrFrame* pFrame = (CEzMrFrame*)pView->GetParentFrame();
if(bUpdateBars)
{
pFrame->InitEzMrCtrlBars();
}
}
}
//...........................................................................................
//
// DESCRIPTION:
// This function updates the tools menu.
//
// RETURN:
// void
//
//...........................................................................................
void CMainFrame::OnUpdatePluginTools(CCmdUI* pCmdUI)
{
m_plugInList.UpdateMenu( pCmdUI );
}
//...........................................................................................
//
// DESCRIPTION:
// This function will launch the plug-in tool with the appropriate arguments
// in the directory specified.
//
// RETURN:
// BOOL - TRUE if successful; otherwise FALSE
//
//...........................................................................................
BOOL CMainFrame::OnPluginTools( UINT nID )
{
BOOL bRet = ((const CPlugInTool*)(m_plugInList[ nID - ID_PLUGIN_TOOL1 ]))->Run();
return bRet;
}
void CMainFrame::OnSelTarget()
{
TRACE("TPM:CEzMrFrame::OnSelTarget()\n");
theApp.m_nTarg = m_CBoxSelTarg.GetCurSel();
theApp.OnOptionsFx2();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -