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

📄 casecombobox.cpp

📁 这是书上的代码
💻 CPP
字号:
// CaseComboBox.cpp : implementation file
//

#include "stdafx.h"
#include "changepage.h"
#include "CaseComboBox.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCaseComboBox property page

IMPLEMENT_DYNCREATE(CCaseComboBox, CPropertyPage)
//改写下面构造函数
CCaseComboBox::CCaseComboBox(UINT nIDTemplate) : CPropertyPage(nIDTemplate)
{
	//{{AFX_DATA_INIT(CCaseComboBox)
	m_CaseComboBox = 0;//初始化组合框成员变量m_CaseComboBox
	//}}AFX_DATA_INIT
}
//添加构造函数
CCaseComboBox::CCaseComboBox() : CPropertyPage( (UINT) 0 )
{
}


CCaseComboBox::~CCaseComboBox()
{
}

void CCaseComboBox::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCaseComboBox)
	DDX_CBIndex(pDX, IDC_COMBO1, m_CaseComboBox);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCaseComboBox, CPropertyPage)
	//{{AFX_MSG_MAP(CCaseComboBox)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCaseComboBox message handlers

BOOL CCaseComboBox::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// TODO: Add extra initialization here
	CPropertyPage* pPage;
	CComboBox* pComboBox;
	CString str;
	CRect rect;
	// 取主属性页中组合框的指针
	pComboBox = (CComboBox*) GetDlgItem(IDC_COMBO1);
	// 设置主属性页的窗口显示区域
	pComboBox->GetWindowRect( rect );
	ScreenToClient( &rect );//将屏幕坐标转换为设备坐标
	rect.bottom += 100;
	pComboBox->MoveWindow( rect );

	// 生成子属性页
	for ( int i = 0; i < m_arrayPages.GetSize(); i++ )
		{
		pPage = (CPropertyPage*) m_arrayPages[i];

		pPage->Create( m_arrayPageIDs[i], this );

		// 在组合框中加入选项
		pPage->GetWindowText( str );
		pComboBox->AddString( str );
		}

	// 设置组合框选项焦点
	pComboBox->SetCurSel( m_CaseComboBox );

	// 设置初始页
	OnSelchangeCombo1();

	UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CCaseComboBox::OnSelchangeCombo1() 
{
	// TODO: Add your control notification handler code here
	CRect Rect;
	CPropertyPage* pOldPage;
	CPropertyPage* pNewPage;

	// 指针指向当前子属性页
	pOldPage = (CPropertyPage*) m_arrayPages[m_CaseComboBox];
	if ( !pOldPage->OnKillActive() )
		{
		// Restore the combo box to its original setting
		UpdateData( FALSE );
		return;
		}

	// 获取当前组合框选项
	CComboBox* pComboBox = (CComboBox*) GetDlgItem(IDC_COMBO1);
	m_CaseComboBox = pComboBox->GetCurSel();

	// 获取对应的子属性页指针
	pNewPage = (CPropertyPage*) m_arrayPages[m_CaseComboBox];
	// 激活子属性页
	if ( !pNewPage->OnSetActive() )
		{
		UpdateData( FALSE );
		return;
		}

	// 隐藏当前的子属性页
	pOldPage->ShowWindow( SW_HIDE );

	// 显示新的子属性页
	pNewPage->ShowWindow( SW_SHOW );

	// 在主属性页的图片框中确定新子属性页的显示位置
	GetDlgItem( IDC_PIC )->GetWindowRect( &Rect);
	ScreenToClient( &Rect );
	pNewPage->SetWindowPos( NULL, Rect.left, Rect.top, 0, 0, 
			SWP_NOSIZE | SWP_NOACTIVATE );
	
}

void CCaseComboBox::AddPage(CPropertyPage *pPropertyPage, UINT nID)
{
	if ( pPropertyPage!=NULL)
	{
		m_arrayPages.Add( pPropertyPage );
		m_arrayPageIDs.Add( nID );
	}
}

⌨️ 快捷键说明

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