// mainfrm.cpp : implementation of the CMainFrame class
//
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.
#include "stdafx.h"
#include "ctrlbars.h"
#include "mainfrm.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_VIEW_DLGBARTOP, OnViewDlgbarTop)
ON_UPDATE_COMMAND_UI(ID_VIEW_DLGBARTOP, OnUpdateViewDlgbartop)
ON_COMMAND(ID_VIEW_SHORT, OnViewShort)
ON_COMMAND(ID_VIEW_LONG, OnViewLong)
ON_COMMAND(ID_TOGGLE_INSERT, OnToggleInsert)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_OVR, OnUpdateInsert)
ON_COMMAND_EX(IDW_STYLES, OnViewBar)
ON_UPDATE_COMMAND_UI(IDW_STYLES, OnUpdateBarMenu)
ON_COMMAND(IDM_VIEWPALETTE, OnViewPalette)
ON_UPDATE_COMMAND_UI(IDM_VIEWPALETTE, OnUpdatePaletteMenu)
ON_COMMAND(IDM_PALETTE_2COLUMN, OnPalette2column)
ON_COMMAND(IDM_PALETTE_3COLUMN, OnPalette3column)
ON_UPDATE_COMMAND_UI(IDM_PALETTE_3COLUMN, OnUpdatePalette3column)
ON_UPDATE_COMMAND_UI(IDM_PALETTE_2COLUMN, OnUpdatePalette2column)
ON_CBN_SELCHANGE(IDC_PALETTE, OnSelChangePalette)
//}}AFX_MSG_MAP
ON_COMMAND_RANGE(ID_STYLE_LEFT, ID_STYLE_JUSTIFIED, OnChangeStyle)
ON_UPDATE_COMMAND_UI_RANGE(ID_STYLE_LEFT, ID_STYLE_JUSTIFIED, OnUpdateStyle)
ON_COMMAND_RANGE(ID_PALETTEERASE, ID_PALETTEOVAL, OnPalette)
ON_UPDATE_COMMAND_UI_RANGE(ID_PALETTEERASE, ID_PALETTEOVAL, OnUpdatePalette)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// arrays of IDs used to initialize control bars
static UINT BASED_CODE styles[] =
{
// same order as in the bitmap 'styles.bmp'
ID_SEPARATOR, // for combo box (placeholder)
ID_SEPARATOR,
ID_STYLE_LEFT,
ID_STYLE_CENTERED,
ID_STYLE_RIGHT,
ID_STYLE_JUSTIFIED,
};
static UINT BASED_CODE palette[] =
{
// same order as in the bitmap 'palette.bmp'
ID_PALETTEERASE,
ID_PALETTEPEN,
ID_PALETTESELECT,
ID_PALETTEBRUSH,
ID_PALETTESPRAY,
ID_PALETTEPAINT,
ID_PALETTELINE,
ID_PALETTEEYEDROP,
ID_PALETTEMAG,
ID_PALETTERECT,
ID_PALETTEROUND,
ID_PALETTEOVAL
};
static UINT BASED_CODE indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_OVR,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
m_bInsert = FALSE; // default to over-strke mode
m_bDialogTop = FALSE;
m_nPaletteCol = 3;
}
CMainFrame::~CMainFrame()
{
}
// We override PreCreateWindow to specify a different window class (WNDCLASS),
// one with a different background and without the CS_VREDRAW/CS_HREDRAW
// style so all the frame window's control bars will not be repainted
// when the window is resized.
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.lpszClass = AfxRegisterWndClass(CS_DBLCLKS,
AfxGetApp()->LoadStandardCursor(IDC_ARROW), (HBRUSH)(COLOR_WINDOW+1),
AfxGetApp()->LoadIcon(IDR_MAINFRAME));
return TRUE;
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
EnableDocking(CBRS_ALIGN_ANY);
if (!CreateToolBar())
return -1;
if (!CreateStyleBar())
return -1;
if (!CreatePaletteBar())
return -1;
if (!CreateStatusBar())
return -1;
if (!m_wndDlgBar.Create(this, IDD_VIEWSELECT,
CBRS_LEFT|CBRS_TOOLTIPS|CBRS_FLYBY, IDD_VIEWSELECT))
{
TRACE0("Failed to create DlgBar\n");
return -1; // fail to create
}
return 0;
}
BOOL CMainFrame::CreateToolBar()
{
if (!m_wndToolBar.Create(this,
CBRS_TOP|CBRS_TOOLTIPS|CBRS_FLYBY|WS_VISIBLE) ||
!m_wndToolBar.LoadBitmap(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return FALSE; // fail to create
}
OnViewShort();
return TRUE;
}
BOOL CMainFrame::CreatePaletteBar()
{
if (!m_wndPaletteBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_FIXED |
CBRS_TOP | CBRS_TOOLTIPS, ID_PALETTEBAR) ||
!m_wndPaletteBar.LoadBitmap(IDB_PALETTE) ||
!m_wndPaletteBar.SetButtons(palette,
sizeof(palette)/sizeof(UINT)))
{
TRACE0("Failed to create toolbar\n");
return FALSE; // fail to create
}
m_wndPaletteBar.SetWindowText(_T("Palette"));
m_wndPaletteBar.EnableDocking(0);
// Create the Palette. We are using hardcoded numbers for ease here
// normally the location would be read in from an ini file.
CPoint pt(GetSystemMetrics(SM_CXSCREEN) - 100,
GetSystemMetrics(SM_CYSCREEN) / 3);
m_wndPaletteBar.SetColumns(3);
FloatControlBar(&m_wndPaletteBar, pt);
return TRUE;
}
BOOL CMainFrame::CreateStyleBar()
{
const int nDropHeight = 100;
if (!m_wndStyleBar.Create(this, WS_CHILD|WS_VISIBLE|CBRS_TOP|
CBRS_TOOLTIPS|CBRS_FLYBY, IDW_STYLES) ||
!m_wndStyleBar.LoadBitmap(IDB_STYLES) ||
!m_wndStyleBar.SetButtons(styles, sizeof(styles)/sizeof(UINT)))
{
TRACE0("Failed to create stylebar\n");
return FALSE; // fail to create
}
// Create the combo box
m_wndStyleBar.SetButtonInfo(0, IDW_COMBO, TBBS_SEPARATOR, 100);
// Design guide advises 12 pixel gap between combos and buttons
m_wndStyleBar.SetButtonInfo(1, ID_SEPARATOR, TBBS_SEPARATOR, 12);
CRect rect;
m_wndStyleBar.GetItemRect(0, &rect);
rect.top = 3;
rect.bottom = rect.top + nDropHeight;
if (!m_wndStyleBar.m_comboBox.Create(
CBS_DROPDOWNLIST|WS_VISIBLE|WS_TABSTOP,
rect, &m_wndStyleBar, IDW_COMBO))
{
TRACE0("Failed to create combo-box\n");
return FALSE;
}
// Fill the combo box
CString szStyle;
if (szStyle.LoadString(IDS_LEFT))
m_wndStyleBar.m_comboBox.AddString((LPCTSTR)szStyle);
if (szStyle.LoadString(IDS_CENTERED))
m_wndStyleBar.m_comboBox.AddString((LPCTSTR)szStyle);
if (szStyle.LoadString(IDS_RIGHT))
m_wndStyleBar.m_comboBox.AddString((LPCTSTR)szStyle);
if (szStyle.LoadString(IDS_JUSTIFIED))
m_wndStyleBar.m_comboBox.AddString((LPCTSTR)szStyle);
// Create a font for the combobox
LOGFONT logFont;
memset(&logFont, 0, sizeof(logFont));
if (!::GetSystemMetrics(SM_DBCSENABLED))
{
// Since design guide says toolbars are fixed height so is the font.
logFont.lfHeight = -12;
logFont.lfWeight = FW_BOLD;
logFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS;
CString strDefaultFont;
strDefaultFont.LoadString(IDS_DEFAULT_FONT);
_tcscpy_s(logFont.lfFaceName, LF_FACESIZE, strDefaultFont);
if (!m_wndStyleBar.m_font.CreateFontIndirect(&logFont))
TRACE0("Could Not create font for combo\n");
else
m_wndStyleBar.m_comboBox.SetFont(&m_wndStyleBar.m_font);
}
else
{
m_wndStyleBar.m_font.Attach(::GetStockObject(SYSTEM_FONT));
m_wndStyleBar.m_comboBox.SetFont(&m_wndStyleBar.m_font);
}
return TRUE;
}
BOOL CMainFrame::CreateStatusBar()
{
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return FALSE; // fail to create
}
UINT nID, nStyle;
int cxWidth;
m_wndStatusBar.GetPaneInfo( 0, nID, nStyle, cxWidth);
m_wndStatusBar.SetPaneInfo( 0, nID, SBPS_STRETCH|SBPS_NORMAL, cxWidth);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CD
- 1
- 2
前往页