⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shapestoolbar.cpp

📁 这是MFC经典问答书的光盘内容
💻 CPP
字号:
// ShapesToolBar.cpp : implementation file
//

#include "stdafx.h"
#include "ComboBoxInToolbar.h"
#include "ShapesToolBar.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CShapesToolBar

CShapesToolBar::CShapesToolBar()
{
}

CShapesToolBar::~CShapesToolBar()
{
}


BEGIN_MESSAGE_MAP(CShapesToolBar, CToolBar)
	//{{AFX_MSG_MAP(CShapesToolBar)
	ON_CBN_SELCHANGE(IDC_SHAPES_COMBO_BOX, OnSelChangeShapesComboBox) 
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CShapesToolBar message handlers

BOOL CShapesToolBar::Create( CWnd* pParentWnd, DWORD dwStyle, UINT nID )
{
	// 1 - Create toolbar and load related resources
	if( !CToolBar::Create( pParentWnd, dwStyle, nID ) ||
		!LoadToolBar(IDR_SHAPES) )
	{
		return FALSE;
	}

	// 2 - Enlarge placeholder
	SetButtonInfo( 0, IDC_SHAPES_COMBO_BOX, TBBS_SEPARATOR, 100 );
	
	// 3 - Retrieve destination coordinates
	CRect rect;
	GetItemRect( 0, &rect );

	// 4 - Enlarge rectangle to account for drop height
	rect.bottom = rect.top + 100;

	// 5 - Create toolbar combo-box
	m_cmbShapes.Create(	WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DROPDOWNLIST,
						rect, this, IDC_SHAPES_COMBO_BOX );

	// 6 - Add some entries to the combo-box
	m_cmbShapes.AddString( _T( "Square" ) );
	m_cmbShapes.AddString( _T( "Circle" ) );

	return TRUE;
}

void CShapesToolBar::OnSelChangeShapesComboBox() 
{
	// Transform CBN_SELCHANGE message into WM_COMMAND
	// with combo-box HWND into LPARAM
	AfxGetMainWnd()->PostMessage(	WM_COMMAND,
									MAKEWPARAM( IDC_SHAPES_COMBO_BOX, 0 ),
									reinterpret_cast<LPARAM>( m_cmbShapes.GetSafeHwnd() ) );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -