MFC列表属性CPropSheet的创建

1.  插入PropPage的Dailog三个资源:

Page1中加入一个Group Box,在里面加入三个单选框Radio Button,将第一个Radio Button(m_jop)选为Group;继续添加一个List Box(m_space)资源

创建与Page1相关的class,添加Radio Button1的int变量m_jop,添加List Box的CString的变量m_space。

添加WM_INITDAILOG的响应函数,初始化List Box;

BOOL CProp1::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// TODO: Add extra initialization here
	((CListBox*)GetDlgItem(IDC_LIST1))->AddString("北京");
	((CListBox*)GetDlgItem(IDC_LIST1))->AddString("上海");
	((CListBox*)GetDlgItem(IDC_LIST1))->AddString("深圳");
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

Page2中加入一个Group Box在里面加入选框Check Button

创建与Page2相关的class,添加四选框Check ButtonBOOL变量m_football,m_basketball,m_volllyball,m_baseball


Page3中加入一个Como Box,创建与Page3相关的class。添加WM_INITDAILOG的响应函数,初始化Como Box

BOOL CProp3::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// TODO: Add extra initialization here
	((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("1000元~2000元");
	((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("2000元~3000元");
	((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("3000元~4000元");
	((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("4000元以上");
	((CComboBox*)GetDlgItem(IDC_COMBO1))->SetCurSel(0);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

`

2. 创建基于CPropertySheet的Class,定义CProp1 m_prop1;CProp2 m_prop2;CProp3 m_prop3;三个变量。

在其构造函数中把三个PropPage添加到Sheet中

CPropSheet::CPropSheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
	:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
	AddPage(&m_prop1);
	AddPage(&m_prop2);
	AddPage(&m_prop3);
}

CPropSheet::CPropSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
	:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
	AddPage(&m_prop1);
	AddPage(&m_prop2);
	AddPage(&m_prop3);
}
重写OnSetActive() 的虚函数,用于设置窗口右下方的按键

page1:

BOOL CProp1::OnSetActive() 
{
	// TODO: Add your specialized code here and/or call the base class
	((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_NEXT);

	return CPropertyPage::OnSetActive();
}
page 2:

BOOL CProp2::OnSetActive() 
{
	// TODO: Add your specialized code here and/or call the base class
	((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_NEXT | PSWIZB_BACK);	
	return CPropertyPage::OnSetActive();
}

page3:

BOOL CProp3::OnSetActive() 
{
	// TODO: Add your specialized code here and/or call the base class
	((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_BACK | 
									PSWIZB_FINISH |PSWIZB_DISABLEDFINISH);
	return CPropertyPage::OnSetActive();
}

重写OnWizardNext() 的虚函数,用于判断信息是否填写正确。

page1:

LRESULT CProp1::OnWizardNext() 
{
	// TODO: Add your specialized code here and/or call the base class
	UpdateData();
	if (-1 == m_opation)
	{
		MessageBox("请选择你的职业。");
		return -1;
	}
	if ("" == m_space)
	{
		MessageBox("请选择你的职业地点。");
		return -1;
	}
	return CPropertyPage::OnWizardNext();
}
page2:

LRESULT CProp2::OnWizardNext() 
{
	// TODO: Add your specialized code here and/or call the base class
	UpdateData();
	if (m_baseball || m_basketball || m_football || m_vollyball)
	{
		return CPropertyPage::OnWizardNext();
	}
	else
	{
		MessageBox("请选择你的兴趣爱好");
		return -1;
	}
}
page3:

BOOL CProp3::OnWizardFinish() 
{
	// TODO: Add your specialized code here and/or call the base class
	int index = ((CComboBox*)GetDlgItem(IDC_COMBO1))->GetCurSel();
	((CComboBox*)GetDlgItem(IDC_COMBO1))->GetLBText(index, m_Salary);

	return CPropertyPage::OnWizardFinish();
}


3. 新建一个menu用来响应产生CPropertySheet(属性列表),添加相应的变量用于保存CPropertySheet里的数据。

在View中添加menu的command响应函数,用来创建CPropertySheet;

void CPropView::OnPropsheet() 
{
	// TODO: Add your command handler code here
	CPropSheet propSheet("属性表单");
	propSheet.SetWizardMode();
	if (ID_WIZFINISH == propSheet.DoModal())
	{
		switch(propSheet.m_prop1.m_opation)
		{
		case 0:
			m_jop = "程序员";
			break;
		case 1:
			m_jop = "系统工程师";
			break;
		case 2:
			m_jop = "项目经理";
			break;
		default:
			break;
		}		
		m_space = propSheet.m_prop1.m_space;

		if (propSheet.m_prop2.m_baseball)
		{
			m_Interest += "棒球 ";
		}
		if (propSheet.m_prop2.m_basketball)
		{
			m_Interest += "篮球 ";
		}
		if (propSheet.m_prop2.m_football)
		{
			m_Interest += "足球 ";
		}
		if (propSheet.m_prop2.m_vollyball)
		{
			m_Interest += "排球 ";
		}

		m_salary = propSheet.m_prop3.m_Salary;

		m_isShow = TRUE;
		Invalidate();
	}	

}


在View中显示属性列表的信息。

void CPropView::OnDraw(CDC* pDC)
{
	CPropDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (m_isShow)
	{
		CFont myFont;
		myFont.CreatePointFont(200, "鸟人字体");
		CFont *pFont = pDC->SelectObject(&myFont);	
		pDC->SetBkMode(TRANSPARENT);
		
		CString strTap = "你的职业是:";
		strTap += m_jop;
		pDC->TextOut(0, 0, strTap);
		
		strTap = "你的工作地点是:";
		strTap += m_space;
		//获取已经输入textout的高度
		TEXTMETRIC tm;
		pDC->GetTextMetrics(&tm);
		pDC->TextOut(0, tm.tmHeight, strTap);
		
		strTap = "你的兴趣爱好是:";
		strTap += m_Interest;
		pDC->TextOut(0, tm.tmHeight*2, strTap);
		
		strTap = "你的薪资水平是:";
		strTap += m_salary;
		pDC->TextOut(0, tm.tmHeight*3, strTap);
		
		pDC->SelectObject(pFont);
	}
	// TODO: add draw code for native data here
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值