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

使用c++编写确认对话框的问题

如何添加一个确认的对话框?函数是怎样的?

哈士奇WWW
浏览 192回答 2
2回答

LEATH

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;} 

莫回无

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