当前位置: 首页> 科技> IT业 > MFC密码对话框之间数据传送实例(源码下载)

MFC密码对话框之间数据传送实例(源码下载)

时间:2025/7/9 3:03:26来源:https://blog.csdn.net/weixin_42350092/article/details/139039275 浏览次数:0次

新建一个login工程项目对话框,主对话框IDD_LOGIN_DIALOG中一个显示按钮IDC_BUTTON1、一个密码按钮IDC_BUTTON2。添加一个密码对话框IDD_DIALOG1,添加类password,在对话框中添加一个编辑框IDC_EDIT1、一个确定按钮IDC_BUTTON1。
程序功能:运行程序显示按钮灰色不可用,点击密码按钮弹出密码对话框,在编辑框中输入WHCC点击确定按钮显示按钮可用。
在这里插入图片描述
在这里插入图片描述
主要代码如下:`
l1、oginDlg.cpp中

BOOL CLoginDlg::OnInitDialog()
{CDialog::OnInitDialog();...GetDlgItem(IDC_BUTTON1)->EnableWindow(false);return TRUE;  // return TRUE  unless you set the focus to a control
}
void CLoginDlg::OnButton1() 
{// TODO: Add your control notification handler code hereAfxMessageBox("按钮可用");
}void CLoginDlg::OnButton2() 
{// TODO: Add your control notification handler code herepassword dlg;dlg.DoModal();CString pass=dlg.LOGIN;if (pass=="WHCC") {GetDlgItem(IDC_BUTTON1)->EnableWindow(true);}else{GetDlgItem(IDC_BUTTON1)->EnableWindow(false);}}

2、password.h中添加一个公共变量

class password : public CDialog
{
// Construction
public:password(CWnd* pParent = NULL);   // standard constructorCString LOGIN;...
}

3、

void password::OnButton1() 
{// TODO: Add your control notification handler code hereGetDlgItem(IDC_EDIT1)->GetWindowText(LOGIN);if (LOGIN=="WHCC"){UpdateData(false);EndDialog(0);}else{MessageBox("输入密码有误!");GetDlgItem(IDC_EDIT1)->SetFocus();}}

运行程序

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
源码下载

关键字:MFC密码对话框之间数据传送实例(源码下载)