为了账号安全,请及时绑定邮箱和手机立即绑定

为什么点"确定"执行操作,点"取消"不执行操作?

为什么点"确定"执行操作,点"取消"不执行操作?

C++
哈士奇WWW 2023-04-23 17:13:27
使用c++编写确认对话框的问题如何添加一个确认的对话框?函数是怎样的?
查看完整描述

2 回答

?
LEATH

TA贡献1936条经验 获得超6个赞

try
{

AfxMessageBox("提交成功");
/*这里写入你确定后的程序*/
CDialog::OnOK();
}
catch(CDBException e)
{
AfxMessageBox("提交失败");
}

比方下面的SQL 添加记录的 程序按钮:
void CAddRecord::OnBtnSubmit() 
{
// TODO: Add your control notification handler code here
// 添加记录
UpdateData(true);

CDatabase db;//打开数据库
db.Open(NULL,FALSE,FALSE,"ODBC;DSN=odbcmfc;UID=root;PWD=");

CString str_no = m_no;
CString str_name = m_name;
CString str_age = m_age;
CString str_sex = m_sex;
CString str_depart = m_depart;
if (str_no == "")
{
AfxMessageBox("请填写学号");
GetDlgItem(IDC_EDIT_NO)->SetFocus();
return;
}
if (str_name == "")
{
AfxMessageBox("请填写姓名");
GetDlgItem(IDC_EDIT_NAME)->SetFocus();
return;
}

if (str_sex != "男" && str_sex != "女" && str_sex != "")
{
AfxMessageBox("性别只能填‘男’或‘女’");
GetDlgItem(IDC_EEDIT_SEX)->SetFocus();
return;
}

//插入新记录的SQL语句
CString sql="insert into student (id,name, age,sex,depart)\
values ('"+str_no+"','"+str_name+"', '"+str_age+"','"+str_sex+"','"+str_depart+"')"; 

try
{
db.ExecuteSQL(sql);
AfxMessageBox("提交成功");
CDialog::OnOK();
}
catch(CDBException e)
{
AfxMessageBox("提交失败");
}

return;
}

 


查看完整回答
反对 回复 2023-04-26
?
莫回无

TA贡献1865条经验 获得超7个赞

话说用C++编写免不了MFC光工程框架就很大了!
Win32 SDK写吧!
加上#include"windows.h"
写上主函数WinMain(.....)
至于如何写,MSDN上面很清楚,祝你好运!
if(IDOK==MessageBox("确认当前操作么?","询问...",MB_YESNO))
{
MessageBox("你确认的...");
}
else
{
MessageBox("你取消了...");
}


查看完整回答
反对 回复 2023-04-26
  • 2 回答
  • 0 关注
  • 120 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信