📄 mainfrm.cpp
字号:
////////////////////////////////////////////////////////////////
// MSDN Magazine -- October 2001
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual C++ 6.0 for Windows 98 and probably Windows 2000 too.
// Set tabsize = 3 in your editor.
//
#include "StdAfx.h"
#include "MainFrm.h"
#include "View.h"
#include "resource.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_WM_CREATE()
ON_NOTIFY(TBN_DROPDOWN, AFX_IDW_TOOLBAR, OnToolbarDropDown)
END_MESSAGE_MAP()
static UINT indicators[] = {
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
CMainFrame::CMainFrame()
{
}
CMainFrame::~CMainFrame()
{
}
////////////////
// Override flicker-free drawing with no CS_VREDRAW and CS_HREDRAW. This has
// nothing to do with coolbars, but I it's a good thing to do.
//
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.lpszClass = AfxRegisterWndClass(
0, // no redraw
NULL, // no cursor (use default)
NULL, // no background brush
AfxGetApp()->LoadIcon(IDR_MAINFRAME)); // app icon
ASSERT(cs.lpszClass);
return CFrameWnd::PreCreateWindow(cs);
}
//////////////////
// Create handler creates control bars
//
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
VERIFY(m_wndStatusBar.Create(this));
VERIFY(m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)));
VERIFY(m_wndToolBar.Create(this));
VERIFY(m_wndToolBar.LoadToolBar(IDR_MAINFRAME));
m_wndToolBar.ModifyStyle(0, TBSTYLE_FLAT);
// TODO: 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);
#ifndef TB_SETEXTENDEDSTYLE
#define TB_SETEXTENDEDSTYLE (WM_USER + 84) // For TBSTYLE_EX_*
#define TBSTYLE_EX_DRAWDDARROWS 0x00000001
#endif
CToolBar& tb = m_wndToolBar;
tb.SendMessage(TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_DRAWDDARROWS);
// change button style to dropdown
int iButton = tb.SendMessage(TB_COMMANDTOINDEX, ID_FILE_OPEN);
DWORD dwStyle = tb.GetButtonStyle(iButton);
dwStyle |= TBSTYLE_DROPDOWN;
tb.SetButtonStyle(iButton, dwStyle);
VERIFY(CFrameWnd::OnCreate(lpCreateStruct) == 0);
return 0;
}
//////////////////
// Handle TBN_DROPDOWN
// Default is to display the specified menu at the right place.
// You can override to generate dynamic menus
//
// Args:
// - NMTOOLBAR struct from TBN_DROPDOWN
// - command id of button
// - point to display menu at
//
void CMainFrame::OnToolbarDropDown(NMHDR *pnmh, LRESULT *plr)
{
NMTOOLBAR* pnmtb = (NMTOOLBAR*)pnmh;
// load and display popup menu
CMenu menu;
menu.LoadMenu(IDR_FILEDROPDOWN);
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup);
CRect rc;
m_wndToolBar.SendMessage(TB_GETRECT, pnmtb->iItem, (LPARAM)&rc);
m_wndToolBar.ClientToScreen(&rc);
pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,
rc.left, rc.bottom, this, &rc);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -