📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "block.h"
#include "MainFrm.h"
#include "BlockView.h"
#include "BlockDoc.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)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
//}}AFX_MSG_MAP
ON_UPDATE_COMMAND_UI(ID_LEVEL,OnLevel)
ON_UPDATE_COMMAND_UI(ID_SCORE,OnScore)
ON_CBN_SELENDOK(ID_COMBOBOX, OnCombobox)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
const UINT uIndicators[]=
{
ID_SEPARATOR,
ID_LEVEL,
ID_SCORE
};
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
}
m_wndToolBar.SetButtonInfo(10,ID_COMBOBOX,TBBS_SEPARATOR,120);
CRect rect;
m_wndToolBar.GetItemRect(10,&rect);
rect.bottom=rect.top+100;
m_wndCombo.Create(WS_CHILD|WS_VISIBLE|WS_VSCROLL|CBS_SORT|CBS_DROPDOWNLIST,
rect,&m_wndToolBar,ID_COMBOBOX);
CString strLevel=_T("难度级别?");
for(int i=0;i<9;i++)
{
strLevel.SetAt(8,_T('0')+i+1);
m_wndCombo.AddString(strLevel);
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndStatusBar.Create(this);
m_wndStatusBar.SetIndicators(uIndicators,3);
m_wndStatusBar.SetPaneInfo(1,ID_LEVEL,SBPS_NORMAL,80);
m_wndStatusBar.SetPaneInfo(2,ID_SCORE,SBPS_NORMAL,80);
rect.SetRect(0,0,400,467);
CalcWindowRect(&rect);
SetWindowPos(NULL,0,0,rect.Width(),rect.Height(),
SWP_NOZORDER|SWP_NOREDRAW|SWP_NOMOVE);
CenterWindow();
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
cs.style&=~WS_MAXIMIZEBOX;
cs.style&=~WS_THICKFRAME;
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::OnLevel(CCmdUI *pCmdUI)
{
CBlockView *pView=(CBlockView *)GetActiveView();
CBlockDoc *pDoc=pView->GetDocument();
CString str;
str.Format(_T(" 级别:%d"),pDoc->m_iLevel+1);
pCmdUI->SetText(str);
}
void CMainFrame::OnScore(CCmdUI *pCmdUI)
{
CBlockView *pView=(CBlockView *)GetActiveView();
CBlockDoc *pDoc=pView->GetDocument();
CString str;
str.Format(_T(" 得分:%d"),pDoc->m_uScore);
pCmdUI->SetText(str);
}
void CMainFrame::OnCombobox()
{
// TODO: Add your command handler code here
CBlockView *pView=(CBlockView *)GetActiveView();
CBlockDoc *pDoc=pView->GetDocument();
pDoc->m_iLevel=m_wndCombo.GetCurSel();
SetFocus();
if(pView->m_bRunning)
{
pView->SendMessage(WM_COMMAND,MAKELONG(ID_STOP,BN_CLICKED),0);
pView->SendMessage(WM_COMMAND,MAKELONG(ID_START,BN_CLICKED),0);
}
}
void CMainFrame::ChangeLevelSel(int iIndex)
{
m_wndCombo.SetCurSel(iIndex);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -