#define AFX_LOGINDLG_H__5FFFF6A5_8CF5_411A_9796_A597EB8FE9A4__INCLUDED_#if _MSC_VER >1000
#pragma once
#endif // _MSC_VER >1000
// LoginDlg.h : header file
//
#include "BtnST.h"
///////////////答缓//////////////////////////////////////////////////////////////
// CLoginDlg dialog
typedef struct _tagUser
{
char name[18]
int oper
char password[16]
}USERINFOclass CLoginDlg : public CDialog
{
// Construction
public:
CLoginDlg(CWnd* pParent = NULL) // standard constructor
DWORD GetUserInfo()constCButtonST m_btnButton2
CButtonST m_btnButton3// Dialog Data
//{{AFX_DATA(CLoginDlg)<br>enum { IDD = IDD_LOGIN }
// NOTE: the ClassWizard will add data members here
CComboBox m_uList
CString m_pas
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CLoginDlg)<br>protected:<br>virtual void DoDataExchange(CDataExchange* pDX) // DDX/DDV support<br>//}}AFX_VIRTUAL// Implementation
protected:
virtual BOOL OnInitDialog()
virtual void OnOK()// Generated message map functions
//{{AFX_MSG(CLoginDlg)<br> // NOTE: the ClassWizard will add member functions here<br>DWORD m_dwUser<br>DWORD m_times<br>//}}AFX_MSG
DECLARE_MESSAGE_MAP()
}//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_LOGINDLG_H__5FFFF6A5_8CF5_411A_9796_A597EB8FE9A4__INCLUDED_)
CPP文件 // LoginDlg.cpp : implementation file
//#include "stdafx.h"
#include "SuperWords.h"
#include "LoginDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__
#endif///////////////////族举配/////////////////////////////////////////////////兆指/////////
// CLoginDlg dialog
CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLoginDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLoginDlg)<br> // NOTE: the ClassWizard will add member initialization here<br> m_times = 2<br>m_dwUser = 0<br>m_pas = _T("")<br>//}}AFX_DATA_INIT
}
void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX)
//{{AFX_DATA_MAP(CLoginDlg)<br> // NOTE: the ClassWizard will add DDX and DDV calls here<br>DDX_Control(pDX, IDC_DLOG_CUSER, m_uList)<br>DDX_Text(pDX, IDC_DLOG_CPASWORD, m_pas)<br>DDV_MaxChars(pDX, m_pas, 16)<br>//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
//{{AFX_MSG_MAP(CLoginDlg)<br> // NOTE: the ClassWizard will add message map macros here<br>//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CLoginDlg message handlers
DWORD CLoginDlg::GetUserInfo() const
{
return m_dwUser
}
BOOL CLoginDlg::OnInitDialog()
{
CDialog::OnInitDialog()
USERINFO theUser
char * strOper[] = { {"信息录入员"},{"系统管理员"} }
UINT size = sizeof(USERINFO)
LPBYTE bt = new unsigned char[sizeof(theUser)]
CString strID
strID.Format("User%04u",0)
int lastID
lastID = AfxGetApp()->GetProfileInt("用户","LastID",0)
for(int i=0i<lastID &&AfxGetApp()->GetProfileBinary("用户",strID,&bt,&size)i++)
{
memcpy(&theUser,bt,sizeof(theUser))
CString strInfo
strInfo.Format("%s [%s]",theUser.name,strOper[theUser.oper])
m_uList.AddString(strInfo)
strID.Format("User%04u",i+1)
}
if(lastID >0)
m_uList.SetCurSel(0)
delete [] btm_btnButton2.SubclassDlgItem(IDOK, this)
m_btnButton2.SetIcon(IDI_ICON1)
m_btnButton3.SubclassDlgItem(IDCANCEL, this)
m_btnButton3.SetIcon(IDI_ICON2)
return TRUE
}
void CLoginDlg::OnOK()
{
UpdateData()
USERINFO theUser
UINT size = sizeof(theUser)
LPBYTE bt = new unsigned char[sizeof(theUser)]
CString strID
int id = m_uList.GetCurSel()
strID.Format("User%04u",id)
if(AfxGetApp()->GetProfileBinary("用户",strID,&bt,&size))
{
memcpy(&theUser,bt,sizeof(theUser))
delete [] bt
if(!m_pas.Compare(theUser.password))
{
m_dwUser = theUser.oper
CDialog::OnOK()
return
}
}
else
{
delete [] bt
MessageBox("没有该用户的信息,请与系统管理员联系。","读取用户数据错误",MB_OK|MB_ICONSTOP)
return
}
if(m_times)
{
m_times--
MessageBox("用户密码不正确!请再次尝试...","登陆失败...",MB_OK|MB_ICONSTOP)
GetDlgItem(IDC_DLOG_CPASWORD)->SetFocus()
}
else
{
MessageBox("用户密码不正确!\n您的登陆失败次数已达三次,程序将退出。\n请与系统管理员联系。","登陆失败...",MB_OK|MB_ICONSTOP)
CDialog::OnCancel()
}
}
第一步:建立应用程序。利用mfcappwizard创建困卖基本对话框汪雀逗的windows应用程序
工程名:dialog
步骤1
启动visualc++6.0,选择“文件(f)”菜单下的“新建(n)”菜单项,选择“工程”标签,选择“mfc
appwizard(exe)”项目类型。在“工程名称(n)”中输入项目dialog将“location”定位于“e:\c++\example”文件夹中,单击“确定”按钮。
第二步:增岁答加按钮控件。
把工具栏里的“按钮”控件拖到对话框里。
或双击工具栏里的“按钮”控件。
第三步:给按钮控件点击事件,增加代码
双击新增的按钮
messagebox(null,"在主窗口出现前,先d出一个对话框","标题",mb_ok)
或者选中按钮,
在事件中找到“bn_clicked",添加函数。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)