?? mainfrm.cpp
字號:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "Painter.h"
#include "Splash.h"
#include "MdiClient.h"
#include "MainFrm.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)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_VIEW_DRAWBAR, OnViewDrawbar)
ON_UPDATE_COMMAND_UI(ID_VIEW_DRAWBAR, OnUpdateViewDrawbar)
ON_COMMAND(ID_CALC, OnCalc)
ON_UPDATE_COMMAND_UI(ID_CALC, OnUpdateCalc)
ON_UPDATE_COMMAND_UI(ID_GAME, OnUpdateGame)
ON_COMMAND(ID_GAME, OnGame)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // 提示信息輸出欄
ID_SEPARATOR, // 鼠標位置
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
m_pmdiclient=(CMdiClient *)new CMdiClient;
}
CMainFrame::~CMainFrame()
{
m_pmdiclient->Detach();
delete m_pmdiclient;
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
m_pmdiclient->SubclassWindow(m_hWndMDIClient);
//載入常用工具欄
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.GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);
m_wndToolBar.SetButtonStyle(17,TBSTYLE_BUTTON | TBSTYLE_DROPDOWN);
//使常用工具欄浮動
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
//載入狀態(tài)欄
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
}
//設(shè)置狀態(tài)欄初始顯示文本
m_wndStatusBar.SetPaneText( 1, "x=10,y=10",TRUE );
m_wndStatusBar.SetPaneInfo( 1, ID_SEPARATOR,SBPS_STRETCH, 10);
//載入繪圖工具欄
if (!m_DrawToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_LEFT
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC)||
!m_DrawToolBar.LoadToolBar(IDR_DRAW_TOOLBAR))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
//使繪圖工具欄浮動
m_DrawToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
//載入對話框工具條
if (!m_wndMyDialogBar.Create(this, IDD_DLGBAR,
CBRS_RIGHT| CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE,
IDD_DLGBAR))
{
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);
//初始化對話框中控件
CComboBox* pCBox=(CComboBox*)m_wndMyDialogBar.GetDlgItem(IDC_FILL_PATTERN);
pCBox->SetCurSel(0);
pCBox=(CComboBox*)m_wndMyDialogBar.GetDlgItem(IDC_LINE_TYPE);
pCBox->SetCurSel(0);
pCBox=(CComboBox*)m_wndMyDialogBar.GetDlgItem(IDC_LINE_WIDTH);
pCBox->SetCurSel(0);
CSplashWnd::ShowSplashScreen(this);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
| WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
if( !CMDIFrameWnd::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
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnFileOpen()
{
// TODO: Add your command handler code here
//如果在無文檔打開時,直接在主框架中打開文件
SendMessage(WM_COMMAND,ID_FILE_NEW,NULL);
CView *viewNew=GetActiveView();
SendMessage(WM_COMMAND,ID_FILE_OPEN,NULL);
}
void CMainFrame::OnViewDrawbar()
{
// TODO: Add your command handler code here
//顯示或隱藏繪圖工具欄
BOOL bVisible = ((m_DrawToolBar.GetStyle() & WS_VISIBLE) != 0);
ShowControlBar(&m_DrawToolBar, !bVisible, FALSE);
RecalcLayout();
}
void CMainFrame::OnUpdateViewDrawbar(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
//顯示或隱藏工具欄時相應(yīng)設(shè)置菜單項狀態(tài)(打勾或不打勾)
BOOL bVisible = ((m_DrawToolBar.GetStyle() & WS_VISIBLE) != 0);
pCmdUI->SetCheck(bVisible);
}
void CMainFrame::OnCalc()
{
// TODO: Add your command handler code here
int i = WinExec("Calculator.exe",SW_SHOW);
if(i==ERROR_FILE_NOT_FOUND)
AfxGetMainWnd()->MessageBox("計算器啟動失敗!\r\n請確認在當前路徑有Calculator.exe文件。" ,"Error",MB_OK|MB_ICONERROR);
}
void CMainFrame::OnUpdateCalc(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CMainFrame::OnUpdateGame(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CMainFrame::OnGame()
{
// TODO: Add your command handler code here
int i = WinExec("Point24.exe",SW_SHOW);
if(i==ERROR_FILE_NOT_FOUND)
AfxGetMainWnd()->MessageBox("游戲啟動失敗!\r\n請確認在當前路徑有Point24.exe文件。" ,"Error",MB_OK|MB_ICONERROR);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -