📄 通信录dlg.cpp
字号:
// 通信录Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "通信录.h"
#include "通信录Dlg.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()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Control(pDX, IDC_TAB1, m_Tab);
DDX_Control(pDX, IDC_LIST1, m_List);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnSelchangeTab1)
ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// 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
// TODO: Add extra initialization here
m_Tab.InsertItem(0,"基本情况",0);
m_Tab.InsertItem(1,"私人资料",1);
m_Tab.InsertItem(2,"单位信息",2);
m_pBaseInfoDlg=new CBaseInfoDlg;
m_pBaseInfoDlg->Create(IDD_DIALOG_BASEINFO,GetDlgItem(IDC_STATIC_DLG));
m_pWorkDlg=new CWorkDlg;
m_pWorkDlg->Create(IDD_DIALOG_WROK,GetDlgItem(IDC_STATIC_DLG));
m_pPrivateDlg=new CPrivateDlg;
m_pPrivateDlg->Create(IDD_DIALOG_PRIVATE,GetDlgItem(IDC_STATIC_DLG));
DoTab(0);
ADDRESS data,data1;
data.strName="LiMing";
data.strNick="Peter";
data.chSex='G';
data.tBirth=CTime(1984,5,6,0,0,0);
data.strHomeAdd="Jiangsu,NanJing";
data.strWorkAdd="NanJing COllege";
data1=data;
data1.strName="WangFang";
data1.strNick="Mary";
data1.chSex='M';
data1.tBirth=CTime(1986,12,3,0,0,0);
int nIndex=m_List.AddString(data.strName);
m_List.SetItemDataPtr(nIndex,new ADDRESS(data));
nIndex=m_List.AddString(data1.strName);
m_List.SetItemDataPtr(nIndex,new ADDRESS(data1));
return TRUE; // return TRUE unless you set the focus to a control
}
void CMyDlg::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 CMyDlg::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 CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyDlg::SetDlgState(CWnd *pWnd, BOOL bShow)
{
pWnd->EnableWindow(bShow);
if(bShow)
{
pWnd->ShowWindow(SW_SHOW);
pWnd->CenterWindow();//居中显示
}
else
pWnd->ShowWindow(SW_HIDE);
}
void CMyDlg::DoTab(int nSel)
{
if(nSel>2)
nSel=2;//确定nSel不能超出范围
if(nSel<0)
nSel=0;
BOOL bTab[3];
bTab[0]=bTab[1]=bTab[2]=FALSE;
bTab[nSel]=TRUE;
SetDlgState(m_pBaseInfoDlg,bTab[0]);
SetDlgState(m_pPrivateDlg,bTab[1]);
SetDlgState(m_pWorkDlg,bTab[2]);
}
void CMyDlg::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int nSelect=m_Tab.GetCurSel();
if(nSelect>=0)
DoTab(nSelect);
*pResult = 0;
}
void CMyDlg::OnSelchangeList1()
{
// TODO: Add your control notification handler code here
int nIndex=m_List.GetCurSel();
if(nIndex!=LB_ERR)
{
ADDRESS *data=(ADDRESS *)m_List.GetItemDataPtr(nIndex);
m_pBaseInfoDlg->m_strName=data->strName;
m_pBaseInfoDlg->m_strNick=data->strNick;
m_pBaseInfoDlg->m_chSex=data->chSex;
m_pBaseInfoDlg->m_timebrith=data->tBirth;
m_pPrivateDlg->m_strHome=data->strHomeAdd;
m_pPrivateDlg->m_strEmail=data->strEmail;;
m_pPrivateDlg->m_strGSM=data->strGSM;
m_pPrivateDlg->m_strTel=data->strHomeTel;
m_pWorkDlg->m_strFax=data->strWorkFax;
m_pWorkDlg->m_strWorkaddress=data->strWorkAdd;
m_pWorkDlg->m_strWorkname=data->strWorkName;
m_pWorkDlg->m_strTel=data->strWorkTel;
//m_pWorkDlg->m_str
m_pBaseInfoDlg->UpdateData(FALSE);
m_pBaseInfoDlg->UpdateSexField();
m_pPrivateDlg->UpdateData(FALSE);
m_pWorkDlg->UpdateData(FALSE);
}
}
void CMyDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
for(int nIndex=m_List.GetCount()-1;nIndex>=0;nIndex--)
{
delete (ADDRESS *)m_List.GetItemDataPtr(nIndex);
}
if(m_pBaseInfoDlg) delete m_pBaseInfoDlg;
if(m_pPrivateDlg) delete m_pPrivateDlg;
if(m_pWorkDlg) delete m_pWorkDlg;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -