步骤:
1.创建对话框框架
2.实现对话框中按钮的功能
1. 对话框框架搭建
框架搭建与第一节框架搭建一样,再次不再累述。针对对话框框架的搭建,在LocalInterfaces中,有CAADialogApplicationDlg.CATDlg文件。点击此文件会弹出工具条,用此工具条对对话框进行布局。效果图如下:
CAA二次开发-创建对话框
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);
}
}
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);
}
运行结果:
//如果”男“被选中弹出”你选择的性别是:男“
else if(_ManRadioButton->GetState()==CATDlgCheck)
{
_OpenNotify = new CATDlgNotify(this," ",CATDlgNfyOK);
_OpenNotify -> SetText("你选择的性别是:男");
_OpenNotify ->SetVisibility(CATDlgShow);
}
运行结果:
//如果“女”被选中,弹出你选择的性别是:女
else
{
_OpenNotify = new CATDlgNotify(this," ",CATDlgNfyOK);
_OpenNotify -> SetText("你选择的性别是:女");
_OpenNotify ->SetVisibility(CATDlgShow);
}
}
运行结果:
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);
}
运行结果:
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);
}
}
运行结果:
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);
}
}
当鼠标选中列表,相应信息被选中。
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();
}
运行结果(点击关闭按钮,对话框消失):