⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addressdlg.cpp

📁 我自己写的一个通讯录的程序,用ODBC来连接数据库. 可以查找,添加,删除,和修改记录,并显示数据库中人所有记录. 登录程序的默认密码为空,可以在程序中修改.
💻 CPP
字号:
/////////////////////////////////////////////////////////////////////////
//类名:CAboutDlg
//功能:通讯录"关于"对话框
/////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Address.h"
#include "AddressDlg.h"
#include "PswdSet.h"
#include "MainDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAddressDlg dialog

CAddressDlg::CAddressDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAddressDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAddressDlg)
	m_password = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	count=0;
	seconds=20;
}

void CAddressDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAddressDlg)
	DDX_Control(pDX, IDC_EDIT1, m_ctrlpassword);
	DDX_Text(pDX, IDC_EDIT1, m_password);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAddressDlg, CDialog)
	//{{AFX_MSG_MAP(CAddressDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_WM_CLOSE()
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAddressDlg message handlers

BOOL CAddressDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	// TODO: Add extra initialization here
	m_ctrlpassword.SetFocus();
	SetTimer(0,1000,NULL);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CAddressDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CAddressDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CAddressDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

///////////////////////////////////////////////////////////////////////////////
//名称:OnOk
//功能:要求输入密码
//////////////////////////////////////////////////////////////////////////////
void CAddressDlg::OnOK() 
{
	// TODO: Add extra validation here
	CPswdSet* m_recordset=new CPswdSet(&m_database);
	CString strSQL;
	UpdateData(TRUE);//读入用户输入的密码
	strSQL.Format("select * from password where PASSWORD='%s'",m_password);
	m_recordset->Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);//从数据库中查找,输入的密码是否正确
	if(m_recordset->GetRecordCount()==0)
	{
		if(count<3)
		{
			MessageBox("口令错误!","提示",MB_OK|MB_ICONINFORMATION);
			count++;//登录次数加1
			m_password.Empty();
			m_ctrlpassword.SetFocus();
			UpdateData(FALSE);
		}
		else
		{
			MessageBox("你无权使用此系统!","警告",MB_OK|MB_ICONHAND);
			m_database.Close();//关闭数据库
			CDialog::OnOK();//关闭对话框
		}
	}
	//如果登录成功,则打开通讯录的主界面
	else
	{
		m_database.Close();
		CMainDlg m_dlg;
		m_dlg.m_database.Open(_T("addresslist"));
		KillTimer(0);//关闭定时器
		CDialog::OnOK();
		m_dlg.DoModal();
	}
}

/////////////////////////////////////////////////////////////////////////
//名称:Ontimer
//功能:实现登陆界面上的倒计时功能
/////////////////////////////////////////////////////////////////////////
void CAddressDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	CString str;
	seconds--;
	str.Format("%d",seconds);
	this->SetWindowText("口令 ("+str+")秒				通讯录");
	if(seconds==0)
	{
		KillTimer(0);
		CAddressDlg::OnCancel();
	}
	CDialog::OnTimer(nIDEvent);
}

////////////////////////////////////////////////////////////////////////
//名称:OnClosr
//功能:关闭登陆界面
/////////////////////////////////////////////////////////////////////////
void CAddressDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	KillTimer(0);
	CDialog::OnClose();
}

/////////////////////////////////////////////////////////////////////////
//名称:OnCtrlColor
//功能:设置登陆界面文字的颜色
////////////////////////////////////////////////////////////////////////
HBRUSH CAddressDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	pDC->SetTextColor(RGB(0,0,255));
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -