///////////////////////////////////////////////////////////////////////// //类名:CAboutDlg //功能:通讯录"关于"对话框
/////////////////////////////////////////////////////////////////////////
#include "stdafx.h" #include "Address.h" #include "AddressDlg.h" #include "PswdSet.h"//当一个类中需要另一个类中的某些函数就应将 那个类 的 头文件 加在 该类的 cpp中 #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,3000,NULL); SetTimer(1,4000,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; //m_database是在该类的 头文件中定义 UpdateData(TRUE);//读入用户输入的密码UpdateData(true); strSQL.Format("select * from password where PASSWORD='%s'",m_password); ///strsQL.Format("select * from password where PASSWORD='%s'", m_Password ); //写出完整的sql语句 m_recordset->Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);//从数据库中查找,输入的密码是否正确 //记录集对象或指针用来打开纪录, 执行 sql语句方法是open 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 if(nIDEvent == 0) { CString str; seconds--; str.Format("%d",seconds); this->SetWindowText("口令 ("+str+")秒 通讯录——马敬发");//加号表示括号 if(seconds==0) { KillTimer(0); CAddressDlg::OnCancel();//因为 CAddressDlg 是类名,而不是实体的,所以用:: } } else { CString str; seconds--; str.Format("%d",seconds);
this->SetWindowText("口令 ("+str+")秒 哈尔滨理工大学计算机03-5马敬发");//加号表示括号 if(seconds==0) { KillTimer(0); CAddressDlg::OnCancel();//因为 CAddressDlg 是类名,而不是实体的,所以用:: //关闭对话框的函数调用的类的成员函数 }
} CDialog::OnTimer(nIDEvent); }
//////////////////////////////////////////////////////////////////////// //名称:OnClosr //功能:关闭登陆界面
///////////////////////////////////////////////////////////////////////// void CAddressDlg::OnClose() ///此处是系统关闭函属于对话框的一个成员函数 { // TODO: Add your message handler code here and/or call default KillTimer(0); if ( MessageBox("尊敬的用户,\n你确认真的要退出吗 ??","马敬发提醒您" ,MB_OKCANCEL)==IDOK)
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; }///

|