📄 phonebookdlg.cpp
字号:
// phonebookDlg.cpp : implementation file
//
#include "stdafx.h"
#include "phonebook.h"
#include "phonebookDlg.h"
#include "search.h"
#include "increat.h"
#include "sure.h"
#include "Sec.h"
#include "Secchange.h"
#ifndef USER
#define USER
#include "user.h"
#include ".\phonebookdlg.h"
#endif
#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()
/////////////////////////////////////////////////////////////////////////////
// CPhonebookDlg dialog
CPhonebookDlg::CPhonebookDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPhonebookDlg::IDD, pParent)
, m_called(_T(""))
, m_sec(_T(""))
{
//{{AFX_DATA_INIT(CPhonebookDlg)
m_showname = _T("");
m_shownumber = _T("");
m_showemail = _T("");
m_showqq = _T("");
m_showinformation = _T("");
m_showadd = _T("");
m_selectname = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPhonebookDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPhonebookDlg)
DDX_Control(pDX, IDC_EDIT_QQ, m_editqq);
DDX_Control(pDX, IDC_EDIT_MOBIL, m_editnumber);
DDX_Control(pDX, IDC_EDIT_EMAIL, m_editemail);
DDX_Control(pDX, IDC_EDIT_COMMENT, m_editinformation);
DDX_Control(pDX, IDC_EDIT_ADD, m_editadd);
DDX_Control(pDX, IDC_EDIT_NAME, m_editname);
DDX_Control(pDX, IDC_NAMELIST, m_namelist);
DDX_Text(pDX, IDC_EDIT_NAME, m_showname);
DDX_Text(pDX, IDC_EDIT_MOBIL, m_shownumber);
DDX_Text(pDX, IDC_EDIT_EMAIL, m_showemail);
DDX_Text(pDX, IDC_EDIT_QQ, m_showqq);
DDX_Text(pDX, IDC_EDIT_COMMENT, m_showinformation);
DDX_Text(pDX, IDC_EDIT_ADD, m_showadd);
DDX_LBString(pDX, IDC_NAMELIST, m_selectname);
//}}AFX_DATA_MAP
DDX_Text(pDX, IDC_CALLED, m_called);
DDX_Control(pDX, IDC_CALLED, m_calledctrl);
}
BEGIN_MESSAGE_MAP(CPhonebookDlg, CDialog)
//{{AFX_MSG_MAP(CPhonebookDlg)
ON_WM_SYSCOMMAND()
ON_WM_DESTROY()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_EXIT, OnExit)
ON_BN_CLICKED(IDB_EXCHANGE, OnExchange)
ON_BN_CLICKED(IDB_SEARCH, OnSearch)
ON_BN_CLICKED(IDB_CREATE, OnCreate)
ON_BN_CLICKED(IDB_DELETE, OnDelete)
ON_LBN_SELCHANGE(IDC_NAMELIST, OnSelchangeNamelist)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_SECCHANGE, OnBnClickedSecchange)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPhonebookDlg message handlers
WNDPROC oldproc;
LRESULT CALLBACK enteredit(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
if(uMsg==WM_CHAR&&wParam==0x0d)
{
::SetFocus(::GetNextWindow(hwnd,GW_HWNDNEXT));
return 1;
}
else
{
return oldproc(hwnd,uMsg,wParam, lParam);
}
}
BOOL CPhonebookDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
//初始化对话框
CFileFind ffind;
if(ffind.FindFile("pb.dat")) {//存在旧数据文件,则转换为新数据文件 olduser
CFile oldf("pb.dat",CFile::modeRead);
CArchive ar(&oldf,CArchive::load);
int nuser;
ar>>nuser;
if(nuser!=0)
{
user* usertemp;
newuser* usernew;
for(int i=0;i<nuser;i++)
{
usernew=new newuser;
usertemp=new user;
ar>>usertemp;
//取出数据
if (usertemp->m_showname=="") {
i--,nuser--;
continue;
}
m_userarr.Add(usertemp);
usertemp=(user*)m_userarr.GetAt(i);//取出数据
///转换为新的数据结构
usernew->m_called="无";
usernew->m_showadd=usertemp->m_showadd;
usernew->m_showemail=usertemp->m_showemail;
usernew->m_showinformation=usertemp->m_showinformation;
usernew->m_showname=usertemp->m_showname;
usernew->m_shownumber=usertemp->m_shownumber;
usernew->m_showqq=usertemp->m_showqq;
delete usertemp;
m_userarr.RemoveAt(i);//重写联系人链表
m_userarr.Add(usernew);//新数据结构加到联系人链表
m_namelist.AddString(usernew->m_showname);//在列表中显示新增加的联系人
}
}
ar.Close();
oldf.Close();
//删除旧文件,创建新文件并写入数据
save();
DeleteFile("pb.dat");//删除旧文件
}
else{//读新格式的数据文件
CFile pfile("pb.new",CFile::modeRead|CFile::modeCreate|CFile::modeNoTruncate);
CArchive ar(&pfile,CArchive::load);
int nuser;
ar>>m_sec;
CSec sec;
if (sec.DoModal()==IDOK) {////选择进入
if (m_sec!=sec.m_sec) {
MessageBox("密码错误!!");
exit(0);
}
}
else exit(0);
ar>>nuser;
if(nuser!=0)
{
newuser* usertemp;
for(int i=0;i<nuser;i++)
{
ar>>usertemp;
m_userarr.Add(usertemp);
m_namelist.AddString(usertemp->m_showname);//在列表中显示新增加的联系人
}
}
ar.Close();
pfile.Close();
}
ffind.Close();
oldproc=(WNDPROC)SetWindowLong(GetDlgItem(IDC_EDIT_NAME)->m_hWnd,GWL_WNDPROC,(LONG)enteredit);
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
DWORD style=GetStyle();
ModifyStyle(0,WS_MINIMIZEBOX);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CPhonebookDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CPhonebookDlg::OnDestroy()
{
WinHelp(0L, HELP_QUIT);
CDialog::OnDestroy();
}
// 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 CPhonebookDlg::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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -