求VC++MFC做的登录实例程序

求VC++MFC做的登录实例程序,第1张

首先,新建对话框,拖拽几个控件,包括2个输入框,"登录"和"取消"按钮,下边是一个登陆框的例子。#if !defined(AFX_LOGINDLG_H__5FFFF6A5_8CF5_411A_9796_A597EB8FE9A4__INCLUDED_)

#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()

}

}

1、找到游戏的可执行文件,使用CreateProcess运行该程序。

2、通过进程ID或窗口标题(FindWindow)找到该程序的登录界面。

3、得到帐号和密码的控件,SetWindowText赋值帐号密码

4、点击登录。PostMessage、KeyPress、mouseEvent等


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7804020.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存