mfc中弹出wpf对话框_CAA二次开发-创建对话框

7312d03f1d0de173d9567a2f327d26a2.png

步骤:

1.创建对话框框架

2.实现对话框中按钮的功能

1. 对话框框架搭建

框架搭建与第一节框架搭建一样,再次不再累述。针对对话框框架的搭建,在LocalInterfaces中,有CAADialogApplicationDlg.CATDlg文件。点击此文件会弹出工具条,用此工具条对对话框进行布局。效果图如下:

CAA二次开发-创建对话框

df1a91bebfee056751127a96c9681409.png

2.实现按钮功能

2.1Combo(年龄一栏)的初始化

在void CAADialogApplicationDlg::Build(){}中,添加如下代码

///对Combo进行初始化

CATUnicodeString ComboNum[30];//声明CATUnicodeString类型的数组(Combo容量)

for (int i = 0;i<30;i++)

{

//将int类型的数转换为CATUcicodeString类型

ComboNum[i].BuildFromNum(i+20,"%d");

//对Combo中的行设置数值

_ShowAge ->SetLine(ComboNum[i],i);

}

//设置默认行

_ShowAge->SetSelect(0);

2.2获取姓名功能实现

将鼠标放到获取姓名按钮,右键选择callback wizard…,弹出对话框,选择Button activation选项,点击Add callback…按钮,在CAADialogApplicationDlg.cpp文件中会自动添加void CAADialogApplicationDlg::OnGetNameButtonPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)

{

}方法,在此方法中添加如下代码:

void CAADialogApplicationDlg::OnGetNameButtonPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)

{

//定义一的字符串

CATUnicodeString NameText;

//获取StudentName中的字符串

NameText = _StudentNameEditor->GetText();

//判断editor是否为空,如果为空,弹出“请输入姓名:”的对话框

//如果不为空,弹出"你输入的姓名是:+姓名"的对话框

if(2==NameText.Compare(""))

{

_OpenNotify = new CATDlgNotify(this," ",CATDlgNfyWarning);

_OpenNotify -> SetText("请输入姓名:");

_OpenNotify ->SetVisibility(CATDlgShow);

}

else

{

_OpenNotify = new CATDlgNotify(this," ",CATDlgNfyInformation);

_OpenNotify -> SetText("你输入的姓名是:n"+NameText);

_OpenNotify ->SetVisibility(CATDlgShow);

}

}

216d80ebcb437ca45702adcba99ec86a.png

2d3e07ca5e41707928f9084e7c98d5ec.png

2.3获取性别功能实现

将鼠标放到获取性别按钮,右键选择callback wizard…,弹出对话框,选择Button activation选项,点击Add callback…按钮,在CAADialogApplicationDlg.cpp文件中会自动添加void CAADialogApplicationDlg::OnGetGenderPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)

{ }在其中添加代码如下:

void CAADialogApplicationDlg::OnGetGenderPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)

{

//判断是否选中状态,如果都没被选中,弹出”请选择性别对话框“

if (_ManRadioButton->GetState()!=CATDlgCheck && _WomanRadioButton->GetState()!=CATDlgCheck)

{

_OpenNotify = new CATDlgNotify(this," ",CATDlgNfyWarning);

_OpenNotify -> SetText("请选择性别");

_OpenNotify ->SetVisibility(CATDlgShow);

}

运行结果:

7815a673e7ad63cf9e68451c5be5380e.png

//如果”男“被选中弹出”你选择的性别是:男“

else if(_ManRadioButton->GetState()==CATDlgCheck)

{

_OpenNotify = new CATDlgNotify(this," ",CATDlgNfyOK);

_OpenNotify -> SetText("你选择的性别是:男");

_OpenNotify ->SetVisibility(CATDlgShow);

}

运行结果:

135a2a2733d0c0062f0b3763ad8c5673.png

//如果“女”被选中,弹出你选择的性别是:女

else

{

_OpenNotify = new CATDlgNotify(this," ",CATDlgNfyOK);

_OpenNotify -> SetText("你选择的性别是:女");

_OpenNotify ->SetVisibility(CATDlgShow);

}

}

运行结果:

fbff7008af06609bfb307d615d7f6d22.png

2.4显示学科功能实现

将鼠标放到显示学科按钮,右键选择callback wizard…,弹出对话框,选择Button activation选项,点击Add callback…按钮,在CAADialogApplicationDlg.cpp文件中会自动添加

void CAADialogApplicationDlg::OnGetProjectPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data){},在其中添加代码如下:

void CAADialogApplicationDlg::OnGetProjectPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)

{

//声明一个CATUnicodeStrng类型的数组

CATUnicodeString iText[3];

//判断多选按钮是否都没选中,如果是弹出“请选择学科”的对话框,否则就显示“你选择的科目是:+所选学科”

if (_YUWEN->GetState()!=CATDlgCheck && _English->GetState()!=CATDlgCheck && _Math->GetState()!=CATDlgCheck)

{

_OpenNotify = new CATDlgNotify(this," ",CATDlgNfyError);

_OpenNotify ->SetText("请选择学科");

_OpenNotify ->SetVisibility(CATDlgShow);

}

运行结果:

f4adc80accbc342dfbf0e17fed74a93b.png

else

{

int i = 0;

if (_YUWEN->GetState()==CATDlgCheck)

{

iText[i++] = _Label059->GetTitle();

}

if (_English->GetState()==CATDlgCheck)

{

iText[i++] = _Label060->GetTitle();

}

if (_Math->GetState()==CATDlgCheck)

{

iText[i++] = _Label061->GetTitle();

}

_OpenNotify = new CATDlgNotify(this," ",CATDlgNfyWarning);

_OpenNotify ->SetText("你选择的科目是:n"+ iText[0]+","+ iText[1]+","+ iText[2]);

_OpenNotify->SetVisibility(CATDlgShow);

}

}

2.5获取年龄功能实现

将鼠标放到获取年龄按钮,右键选择callback wizard…,弹出对话框,选择Button activation选项,点击Add callback…按钮,在CAADialogApplicationDlg.cpp文件中会自动添加

void CAADialogApplicationDlg::OnGetAgePushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data){},在其中添加的代码如下:

void CAADialogApplicationDlg::OnGetAgePushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)

{

CATUnicodeString iText;//声明所选择Combo行的内容;

int LineNumber=_ShowAge->GetSelect();//获取所选行的行号

_ShowAge ->GetLine(iText,LineNumber);//获取所选行的内容

_OpenNotify = new CATDlgNotify(this," ",CATDlgNfyOK);//弹出信息对话框

_OpenNotify->SetText("年龄为:"+iText);//对话框显示的内容

_OpenNotify ->SetVisibility(CATDlgShow);//显示对话框

}

2.6满意程度功能实现

将鼠标放到满意程度按钮,右键选择callback wizard…,弹出对话框,选择Button activation选项,点击Add callback…按钮,在CAADialogApplicationDlg.cpp文件中会自动添加

void CAADialogApplicationDlg::OnGetStatificationPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data){},在其中添加代码如下:

void CAADialogApplicationDlg::OnGetStatificationPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)

{

// 获取当前值,如果值为,弹出“请选择学习年限”对话框,

//如果值小于,大于零,弹出“特别幸福”对话框

//如果值大于.弹出“不幸福”对话框

//否则弹出“一般幸福”对话框

int i = _ShowStudyAge->GetCurrentValue();

if(i==0)

{

_OpenNotify = new CATDlgNotify(this," ",CATDlgNfyOK);

_OpenNotify -> SetText("请选择学习年限");

_OpenNotify ->SetVisibility(CATDlgShow);

}

else if(i<3 && i >0)

{

_OpenNotify = new CATDlgNotify(this," ",CATDlgNfyOK);

_OpenNotify -> SetText("特别幸福");

_OpenNotify ->SetVisibility(CATDlgShow);

}

else if( i > 6)

{

_OpenNotify = new CATDlgNotify(this," ",CATDlgNfyOK);

_OpenNotify -> SetText("不幸福");

_OpenNotify ->SetVisibility(CATDlgShow);

}

else

{

_OpenNotify = new CATDlgNotify(this," ",CATDlgNfyOK);

_OpenNotify -> SetText("一般幸福");

_OpenNotify ->SetVisibility(CATDlgShow);

}

}

2.7添加信息功能实现

将鼠标放到添加信息按钮,右键选择callback wizard…,弹出对话框,选择Button activation选项,点击Add callback…按钮,在CAADialogApplicationDlg.cpp文件中会自动添加

void CAADialogApplicationDlg::OnAddInfoPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data){},在其中添加的代码如下:

void CAADialogApplicationDlg::OnAddInfoPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)

{

int CHECK = 0,CHECK2 = 0;

CATUnicodeString oCellContents[25];

//判断所有信息是否完整

if (_StudentNameEditor->GetText()=="")

{

CHECK=1;

}

if (_ManRadioButton->GetState()==CATDlgUncheck && _WomanRadioButton->GetState()==CATDlgUncheck)

{

CHECK=1;

}

if (_YUWEN->GetState()==CATDlgUncheck && _English->GetState()==CATDlgUncheck && _Math->GetState()==CATDlgUncheck)

{

CHECK=1;

}

if (_ShowStudyAge->GetCurrentValue()==0)

{

CHECK=1;

}

//判断是否重名

for(int i=0;i<_MultiList->GetLineCount();i++)

{

_MultiList->GetColumnItem(0, oCellContents[i],i);

if(oCellContents[i]==_StudentNameEditor->GetText())

CHECK2=1;

}

if(CHECK==1)

{

_OpenNotify = new CATDlgNotify(this," ",CATDlgNfyWarning);

_OpenNotify -> SetText("请完善信息");

_OpenNotify ->SetVisibility(CATDlgShow);

}

else if (CHECK2==1)

{

_OpenNotify = new CATDlgNotify(this," ",CATDlgNfyWarning);

_OpenNotify -> SetText("重名");

_OpenNotify ->SetVisibility(CATDlgShow);

}

else

{

int ColumentNum = _MultiList->GetColumnCount();

CATUnicodeString ColumentContext[4];

ColumentContext[0] = _StudentNameEditor->GetText();

if (_ManRadioButton->GetState()==CATDlgCheck)

{

ColumentContext[1] ="男";

}

else if (_WomanRadioButton->GetState()==CATDlgCheck)

{

ColumentContext[1] = "女";

}

CATUnicodeString iText;

if (_YUWEN->GetState()==CATDlgCheck)

{

iText = _Label059->GetTitle();

}

if (_English->GetState()==CATDlgCheck)

{

iText+= _Label060->GetTitle();

}

if (_Math->GetState()==CATDlgCheck)

{

iText+= _Label061->GetTitle();

}

ColumentContext[2]= iText;

CATUnicodeString AgeText;

int LineNumber=_ShowAge->GetSelect();

_ShowAge ->GetLine(AgeText,LineNumber);

ColumentContext[3] = AgeText;

_MultiList-> SetColumnItems(0,&ColumentContext[0],1,-1,CATDlgDataAdd);

_MultiList-> SetColumnItems(1,&ColumentContext[1],1,-1,CATDlgDataAdd);

_MultiList-> SetColumnItems(2,&ColumentContext[2],1,-1,CATDlgDataAdd);

_MultiList-> SetColumnItems(3,&ColumentContext[3],1,-1,CATDlgDataAdd);

_DeleteInfo->SetSensitivity(CATDlgEnable);

}

}

运行结果:

7fb5ee00845b61211844aac6591c71cc.png

2.8删除信息

将鼠标放到删除信息按钮,右键选择callback wizard…,弹出对话框,选择Button activation选项,点击Add callback…按钮,在CAADialogApplicationDlg.cpp文件中会自动添加

void CAADialogApplicationDlg::OnDeleteInfoPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data){},在其中添加代码如下:

void CAADialogApplicationDlg::OnDeleteInfoPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)

{

CATBool IsSelectBool;

int RowNumber = 0;

for (int i = 0;i<_MultiList->GetLineCount();i++)

{

IsSelectBool = _MultiList->IsSelect(i);

if (IsSelectBool==TRUE) RowNumber = i;

}

_MultiList->ClearLine(RowNumber);

if (_MultiList->GetLineCount()==0)

{

_DeleteInfo->SetSensitivity(CATDlgDisable);

}

}

2.9列表相应事件

将鼠标放到列表中,右键选择callback wizard…,弹出对话框,选择Selection in list选项,点击Add callback…按钮,在CAADialogApplicationDlg.cpp文件中会自动添加

void CAADialogApplicationDlg::OnMultiListListSelectNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data),在其中添加代码如下:

void CAADialogApplicationDlg::OnMultiListListSelectNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)

{

int selectLine[1];

int selectNum = _MultiList ->GetSelect(selectLine,1);

CATUnicodeString name,gender,age,subject;

_MultiList ->GetColumnItem(0,name,selectLine[0]);

_MultiList ->GetColumnItem(1,gender,selectLine[0]);

_MultiList ->GetColumnItem(2,subject,selectLine[0]);

_MultiList ->GetColumnItem(3,age,selectLine[0]);

_StudentNameEditor->SetText(name);

if (gender=="男")

{

_ManRadioButton->SetState(CATDlgCheck);

_WomanRadioButton->SetState(CATDlgUncheck);

}

if (gender=="女")

{

_ManRadioButton->SetState(CATDlgUncheck);

_WomanRadioButton->SetState(CATDlgCheck);

}

int ageNum;

age.ConvertToNum(&ageNum,"%d");

_ShowAge ->SetSelect(ageNum-20);

if (-1==subject.SearchSubString("语文"))

{

_YUWEN->SetState(CATDlgUncheck);

}

else

{

_YUWEN->SetState(CATDlgCheck);

}

if (-1==subject.SearchSubString("英语"))

{

_English->SetState(CATDlgUncheck);

}

else

{

_English->SetState(CATDlgCheck);

}

if (-1==subject.SearchSubString("数学"))

{

_Math->SetState(CATDlgUncheck);

}

else

{

_Math->SetState(CATDlgCheck);

}

}

当鼠标选中列表,相应信息被选中。

bb10f60122ca52dfb51340a1da2b6c27.png

7fcdcbafcbf9440abf9fd52470988890.png

2.10窗口关闭实现

将鼠标移到框架空白处,右键选择callback wizard…,弹出对话框,选择Window closing选项,点击Add callback…按钮,在CAADialogApplicationDlg.cpp文件中会自动添加

Void CAADialogApplicationDlg::OnCAADialogApplicationDlgWindCloseNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data){},在其中添加代码如下:

void CAADialogApplicationDlg::OnCAADialogApplicationDlgWindCloseNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)

{

this -> SetVisibility(CATDlgHide);

this -> RequestDelayedDestruction();

}

0c13720b889fdbeabe707d8d96f2402a.png

运行结果(点击关闭按钮,对话框消失):

7fcdcbafcbf9440abf9fd52470988890.png

后期会在微信公众号发一些有关CATIA软件开发所用到的编程教程(例如C++,MFC,VB等等)需要的小伙伴关注微信公众号:

d76f579888a4b198b5f2aa4b60f5fa76.png
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值