📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "test2.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_COMMAND_EX(CG_ID_VIEW_MYDIALOGBAR, OnBarCheck)
ON_UPDATE_COMMAND_UI(CG_ID_VIEW_MYDIALOGBAR, OnUpdateControlBarMenu)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_UPDATE_COMMAND_UI(IDR_TEST, OnUpdateTest)
ON_COMMAND(IDR_CIRCLE, OnCircle)
ON_UPDATE_COMMAND_UI(IDR_CIRCLE, OnUpdateCircle)
ON_WM_TIMER()
ON_COMMAND(IDR_SPLITTERWND, OnSplitterwnd)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_SEPARATOR,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
m_bCircle = false;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
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
}
m_wndStatusBar.SetPaneInfo(1,ID_SEPARATOR,0,65);
/* m_progress.Create(WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,ID_VIEW_STATUS_BAR);
m_progress.SetRange(0,10);
m_progress.SetPos(0);
m_progress.SetStep(1);
CRect rect ;
m_wndStatusBar.GetItemRect(1,rect);
rect.right = rect.left+1800;
m_progress.MoveWindow(rect);
m_wndStatusBar.SetTimer(1,500,NULL);*/
if (!m_wndMyDialogBar.Create(this, CG_IDD_MYDIALOGBAR, CBRS_LEFT |CBRS_TOOLTIPS |CBRS_FLYBY | CBRS_HIDE_INPLACE,CG_ID_VIEW_MYDIALOGBAR) )
{
TRACE0("Failed to create MyDialogBar\n");
return -1; // fail to create
}
if(!CreatePropertyBar())
{
TRACE0("Failed to create property bar\n");
return -1;
}
// TODO: 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);
m_wndPropertyBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndPropertyBar);
m_wndPropertyBar.SetWindowText(_T("Property"));
// TODO: Add a menu item that will toggle the visibility of the // dialog bar named "My Dialog Bar": // 1. In ResourceView, open the menu resource that is used by // the CMainFrame class // 2. Select the View submenu // 3. Double-click on the blank item at the bottom of the submenu // 4. Assign the new item an ID: CG_ID_VIEW_MYDIALOGBAR // 5. Assign the item a Caption: My Dialog Bar // TODO: Change the value of CG_ID_VIEW_MYDIALOGBAR to an appropriate value: // 1. Open the file resource.h // CG: The following block was inserted by the 'Dialog Bar' component // Initialize dialog bar m_wndMyDialogBar/* if (!m_wndMyDialogBar.Create(this, CG_IDD_MYDIALOGBAR, CBRS_LEFT | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE, CG_ID_VIEW_MYDIALOGBAR)) { TRACE0("Failed to create dialog bar m_wndMyDialogBar\n"); return -1; // fail to create }*/ m_wndMyDialogBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndMyDialogBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnUpdateTest(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(1);
}
void CMainFrame::OnCircle()
{
// TODO: Add your command handler code here
m_bCircle = true ;
//AfxMessageBox("Circle will be maked!");
}
void CMainFrame::OnUpdateCircle(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bCircle);
}
BOOL CMainFrame::CreatePropertyBar()
{
const int nDropHeight = 100 ;
if (!m_wndPropertyBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndPropertyBar.LoadToolBar(IDR_TOOLBAR1))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
m_wndPropertyBar.SetButtonInfo(4,ID_SEPARATOR ,TBBS_SEPARATOR , 12);
m_wndPropertyBar.SetButtonInfo(5,IDW_LINETYPE ,TBBS_SEPARATOR , 200);
CRect rect ;
m_wndPropertyBar.GetItemRect(5,&rect);
rect.bottom = rect.top + nDropHeight;
if (!m_wndPropertyBar.m_wndLineTypeCmb.Create(CBS_DROPDOWNLIST|WS_VISIBLE|WS_TABSTOP|
WS_VSCROLL|CBS_OWNERDRAWVARIABLE,rect,&m_wndPropertyBar,IDW_LINETYPE))
{
TRACE0("Failed to create combobox\n");
return -1; // fail to create
}
m_wndPropertyBar.m_wndLineTypeCmb.AddItem(PS_SOLID,"Solid");
m_wndPropertyBar.m_wndLineTypeCmb.AddItem(PS_DASH,"Dash");
m_wndPropertyBar.m_wndLineTypeCmb.AddItem(PS_DOT,"Dot");
m_wndPropertyBar.m_wndLineTypeCmb.AddItem(PS_DASHDOT,"Dash Dot");
m_wndPropertyBar.m_wndLineTypeCmb.SetCurSel(0);
return true ;
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
static int nCount = 0 ;
m_progress.StepIt();
if(++nCount ==10)
{
nCount = 0 ;
m_progress.SetPos(0);
KillTimer(1);
m_progress.MoveWindow(CRect(0,0,0,0));
}
//CFrameWnd::OnTimer(nIDEvent);
}
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// CG: The following block was added by the Splitter Bar component. { if (!m_wndSplitter.Create(this, 2, 2, // TODO: adjust the number of rows, columns CSize(10, 10), // TODO: adjust the minimum pane size pContext)) { TRACE0("Failed to create splitter bar "); return FALSE; // failed to create } return TRUE; }
}
void CMainFrame::OnSplitterwnd()
{
// TODO: Add your command handler code here
//CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -