MFC(继续对话框,孙鑫C++第八讲笔记整理)

1.如何改变按纽的字体?在对话框的属性中改变字体的属性即可

 

2.逃跑按纽的实现

 

 1.CButton派生一个类,CWeixinBtn

 2.IDC_EDIT1关联成员变量m_btn1,类型为CWeixinBtn,注意要包含头文件。

 3.CWeixinBtn中加一个指针成员变量CWeixinBtn *pWeixinBtn,然后将其地址初始化。

 4.在新类中增加鼠标移动的消息处理。

 

3.属性表单

 1.插入属性页资源。Insert->new Resource->Dialog

 2.当选择Classwizard菜单时,系统提示是否为创建新的类,我们将其从CPropertyPage派生!这样可以为方便为其增加消息响应函数。

 3.插入新的从CPropertySheet派生的类,在类中增加3CPropertyPage的实例。

 4.view中增加菜单项,当点击时显示属性表单,出现中文乱码,修改CPropertyPage属性为中文,另外将其字体设为宋体。

 5.CPropertyPage中设置SetWizardButtons可将其属性改为上一步、完成!

 6.IDC_RADIO1关联成员变量,需要先设置Group属性才行。另外别忘记调用UpdateData().

 7.CPropertyPage增加虚函数,OnWizardNext,如果用户点击下一步时,不想让他进入下一步,刚返回-1

 8.将用户的选择输出到屏幕上,此时可以在View中增加几个成员变量,用来接收用户选择的数据。

 

4.memset函数的用法 memcopy的用法 

 

 

在CXXDlg添加ButtonDlg.h头文件

#include"ButtonDlg.h"

 

OnInitDlg添加

m_btn1.m_pbtn=&m_btn2;
m_btn2.m_pbtn=&m_btn1;


 

void CButtonDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	ShowWindow(SW_HIDE);
	m_pbtn->ShowWindow(SW_SHOW);

	CButton::OnMouseMove(nFlags, point);
}


使用SetWindowPos方法

void CDlgButton::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	static CRect crectold,crectnew;

	if(crectold.IsRectNull())
	{
		GetWindowRect(&crectold);

		crectnew.left=crectold.left-100;
		crectnew.top=crectold.top+100;
		crectnew.right=crectold.right-100;
		crectnew.bottom=crectold.bottom+100;

	}
	ScreenToClient(&crectold);
	SetWindowPos(NULL,crectold.left,crectold.top+100,crectold.right,crectold.bottom+100,SWP_SHOWWINDOW|SWP_NOSIZE );
	//ShowWindow(SW_SHOW);
	
	/*CString cstring;
	cstring.Format("x=%d",crectold.left);
	MessageBox(cstring);*/

		
	
	CButton::OnMouseMove(nFlags, point);
}


只是初步测试,由于时间关系,自己改吧。

 

下面是属性列表的代码(属性选项卡)

解决中文乱码的问题:先设置propertypage的字体为Chinese,然后修改字体为宋体或其他

1新建一个MFC单文档模式

2在资源那里添加

创建三个.

3然后拉控件

4为每个Proppage添加一个类

 

5查MSDN得知,要用CPropertySheet调用AddPage

 

6在其构造函数中添加

CPropSheet::CPropSheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
	:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
	AddPage(&m_proc1);
	AddPage(&m_proc2);
	AddPage(&m_proc3);
}

CPropSheet::CPropSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
	:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
	AddPage(&m_proc1);
	AddPage(&m_proc2);
	AddPage(&m_proc3);
}


7菜单添加一个选项:

void CProccView::OnProc() 
{
	// TODO: Add your command handler code here
	//MessageBox("hello");

	CPropSheet cpst("属性列表");
	cpst.DoModal();

}


这样就可以显示了

 

To create a wizard-type dialog box, follow the same steps you would follow to create a standard property sheet, but call SetWizardMode before you call DoModal. 


 

void CProccView::OnProc() 
{
	// TODO: Add your command handler code here
	//MessageBox("hello");

	CPropSheet cpst("属性列表");
	cpst.SetWizardMode( );
	cpst.DoModal();

}


 

向导的按钮有问题,第一页是没有上一页的:

属性页添加到属性表单,属性表单就是属性页的父窗体

 

BOOL CProc1::OnSetActive() 
{
	// TODO: Add your specialized code here and/or call the base class
	
	 ((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_NEXT);//CPropertySheet相当于CPropertyPage的父窗体

	return CPropertyPage::OnSetActive();
}


 

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


 

第一个单选按钮在GROUP打钩,则后面(直到再次遇到一个GROUP打钩的)都为同一组:

 

单选关联一个数值:

 

为CListBoX赋值,WM_INITDILOG

BOOL CProc1::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// TODO: Add extra initialization here
	
	CString cst1="北京";
	CString cst2="上海";
	CString cst3="天津";
	CString cst4="南京";
	CString cst5="广州";

	((CListBox*)GetDlgItem(IDC_LIST1))->AddString(cst1);
	((CListBox*)GetDlgItem(IDC_LIST1))->AddString(cst2);
	((CListBox*)GetDlgItem(IDC_LIST1))->AddString(cst3);
	((CListBox*)GetDlgItem(IDC_LIST1))->AddString(cst4);
	((CListBox*)GetDlgItem(IDC_LIST1))->AddString(cst5);

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


 

LRESULT CProc1::OnWizardNext() 
{
	// TODO: Add your specialized code here and/or call the base class
	
	UpdateData();//参数默认为TRUE,取值的时候,参数为TRUE,要赋值的时候,参数为FALSE
	if(m_zhiye==-1)
	{
		MessageBox("请选择你的职业");
		return -1;
	}

	if(m_gongzuodidian=="")
	{
		MessageBox("请选择你的工作地点");
		return -1;
	}
	
	return CPropertyPage::OnWizardNext();
}

 

添加关联数值:

 

LRESULT CProc2::OnWizardNext() 
{
	// TODO: Add your specialized code here and/or call the base class

	UpdateData();
	if(m_zuqiu||m_lanqiu||m_paiqiu||m_youyong)
	{
		return CPropertyPage::OnWizardNext();
	}
	else
	{
		MessageBox("请选择你的兴趣爱好");
	}

	
	
}


初始化CCombox

BOOL CProp3::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// TODO: Add extra initialization here
	
	CString str1="1000元以下";
	CString str2="1000-2000元";
	CString str3="2000-3000元";
	CString str4="3000-5000元";
	CString str5="5000元以上";

	((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString(str1);
	((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString(str2);
	((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString(str3);
	((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString(str4);
	((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString(str5);


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


把SORT的勾去掉,使得它按照我们添加进去的顺序排序

 

数值关联:

 

VIEW中添加成员变量,用以接收数据

private:
	int zhiye;
	CString gongzuodidian;
	BOOL xingqu[4];
	CString xinzishuiping;
};


 

void CProccView::OnProc() 
{
	// TODO: Add your command handler code here
	//MessageBox("hello");

	CPropSheet cpst("属性列表");
	cpst.SetWizardMode( );
	//cpst.DoModal();

	if(ID_WIZFINISH==cpst.DoModal())
	{
		zhiye=cpst.m_proc1.m_zhiye;
		gongzuodidian=cpst.m_proc1.m_gongzuodidian;

		xingqu[0]=cpst.m_proc2.m_zuqiu;
		xingqu[1]=cpst.m_proc2.m_lanqiu;
		xingqu[2]=cpst.m_proc2.m_paiqiu;
		xingqu[3]=cpst.m_proc2.m_youyong;

		xinzishuiping=cpst.m_proc3.cstrxinshui;
	         Invalidate();
           }
}


 

void CProccView::OnDraw(CDC* pDC)
{
	CProccDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here

	CFont cfont;
	cfont.CreatePointFont(300,"宋体");
	CFont *oldfont=pDC->SelectObject(&cfont);
	TEXTMETRIC tm;
	pDC->GetTextMetrics(&tm);
	CString temp="你的职业是:";
	if(zhiye==0)
	{
		temp+="程序员";
	}
	if(zhiye==1)
	{
		temp+="系统工程师";
	}
	if(zhiye==2)
	{
		temp+="项目经理";
	}
	pDC->TextOut(0,0,temp);


	temp="你的工作地点是:";
	temp+=gongzuodidian;
	pDC->TextOut(0,tm.tmHeight,temp);

	temp="你的兴趣爱好是:";
	if(xingqu[0])
	{
		temp+="足球 ";
	}
	if(xingqu[1])
	{
		temp+="篮球 ";
	}
	if(xingqu[2])
	{
		temp+="排球 ";
	}
	if(xingqu[3])
	{
		temp+="游泳 ";
	}
	pDC->TextOut(0,tm.tmHeight*2,temp);

	temp="你的薪资水平是";
	temp+=xinzishuiping;
	pDC->TextOut(0,tm.tmHeight*3,temp);

	pDC->SelectObject(oldfont);

}


自此,这个程序完成了

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值