?? phonebookdlg.cpp
字號:
// PhonebookDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SMS_duanxin.h"
#include "PhonebookDlg.h"
#include "AddphoneDlg.h"
#include "SendDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static int m_sum;
/////////////////////////////////////////////////////////////////////////////
// CPhonebookDlg dialog
CPhonebookDlg::CPhonebookDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPhonebookDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPhonebookDlg)
// NOTE: the ClassWizard will add member initialization here
m_hIcon = AfxGetApp()->LoadIcon(IDR_PHONENUM); ////載入對話框窗口圖標
//}}AFX_DATA_INIT
}
void CPhonebookDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPhonebookDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
DDX_Control(pDX, IDC_LIST1, m_phonelist);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPhonebookDlg, CDialog)
//{{AFX_MSG_MAP(CPhonebookDlg)
ON_BN_CLICKED(IDC_BUTTONUP, OnButtonup)
ON_BN_CLICKED(IDC_BUTTONDOWN, OnButtondown)
ON_BN_CLICKED(IDC_BUTTONDEL, OnButtondel)
ON_BN_CLICKED(IDC_SAVE, OnSave)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_EDIT, OnEdit)
ON_BN_CLICKED(IDC_SELECT, OnSelect)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPhonebookDlg message handlers
BOOL CPhonebookDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//將About菜單項添加到系統菜單
//設置對話框圖標
//在此處添加初始化代碼
SetIcon(m_hIcon,TRUE); //set big icon
SetIcon(m_hIcon,FALSE); //set small icon
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);
}
}
//字體設置
m_font.CreateFont(16, 0,0,0,FW_NORMAL, 0,0,0,
DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial");
m_phonelist.SetFont(&m_font);
//為列表設置擴展方式
m_phonelist.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
m_phonelist.SetBkColor(RGB(247,247,255));
m_phonelist.SetTextColor(RGB(0,0,255));
m_phonelist.SetTextBkColor(RGB(247,247,255));
//為列表添加標題
CString strname[3];
strname[0] = "序號";
strname[1] = "名字";
strname[2] = "號碼";
for(int i=0;i<3;i++)
{
m_phonelist.InsertColumn(i,strname[i],LVCFMT_LEFT,125);
}
/*FILE *fp;
//打開方式
if((fp = fopen("電話本.txt","r")==NULL))
{
AfxMessageBox("no open!");
return;
}
ch;
char sh;
while((BOOL ch=fgets(sh,500,fp))!=EOF)
{
int n=0;
m_phonelist.GetItemText(n,0)+"\t\t"+m_phonelist.GetItemText(n,1)+"\t\t"+m_phonelist.GetItemText(n,2)+"\r\t"=ch;
}
fclose(fp);*/
CFile file("電話本.txt",CFile::modeRead);
CArchive ar(&file,CArchive::load);
int nsum;
int n=0;
CString no,name,phone;
ar>>no>>nsum>>phone;
ar>>no>>name>>phone;
while(nsum--)
{
ar>>no>>name>>phone;
no.TrimRight("\t\t");
name.TrimRight("\t\t");
phone.TrimRight("\r\n");
m_phonelist.InsertItem(n,no);
m_phonelist.SetItemText(n,1,name);
m_phonelist.SetItemText(n,2,phone);
n++;
}
ar.Flush();
ar.Close();
file.Close();
/* CStdioFile df;
if(df.Open("電話本.txt",CFile::modeRead))
{
CString strvalue;
while(df.ReadString(strvalue))
{
int k =strlen(strvalue);
while()
}
}
m_phonelist.InsertItem(0,"000001");
m_phonelist.SetItemText(0,1,"笨笨");
m_phonelist.SetItemText(0,2,"13401163848");
m_phonelist.InsertItem(1,"000002");
m_phonelist.SetItemText(1,1,"豆豆");
m_phonelist.SetItemText(1,2,"15926641031");*/
//CPhonebookDlg::OnAdd();
UpdateData(TRUE);
return TRUE;
}
void CPhonebookDlg::OnButtonup()
{
// TODO: Add your control notification handler code here
m_phonelist.SetFocus();
POSITION pos = m_phonelist.GetFirstSelectedItemPosition();
//得到項目索引
m_index = m_phonelist.GetNextSelectedItem(pos);
if(m_index == -1)
{
AfxMessageBox("請選擇一項!");
return;
}
//判斷所選項是否位于首行
if(m_index == 0)
{
AfxMessageBox("已經位于第一行!");
return;
}
//提取所選列表項各列內容
CString tempField1[30],tempField2[30];
for(int i=0;i<3;i++)
{
tempField1[i] = m_phonelist.GetItemText(m_index,i);
tempField2[i] = m_phonelist.GetItemText(m_index-1,i);
}
//刪除所選列表項
//m_phonelist.DeleteItem(m_index);
//在m_index位置處插入上面所刪除列表項的各列內容
//int tempItem;
for(int j=0;j<3;j++)
{
m_phonelist.SetItemText(m_index-1,j,tempField1[j]);
m_phonelist.SetItemText(m_index,j,tempField2[j]);
}
//m_index--;
//使得m_index位置處項目點亮并獲得焦點
UINT flag = LVIS_SELECTED|LVIS_FOCUSED;
m_phonelist.SetItemState(m_index+1,flag,flag);
}
void CPhonebookDlg::OnButtondown()
{
// TODO: Add your control notification handler code here
m_phonelist.SetFocus();
POSITION pos = m_phonelist.GetFirstSelectedItemPosition();
//得到項目索引
m_index = m_phonelist.GetNextSelectedItem(pos);
if(m_index == -1)
{
AfxMessageBox("請選擇一項!");
return;
}
//判斷所選項是否位于首行
if(m_index == m_phonelist.GetItemCount()-1)
{
AfxMessageBox("已經位于最后一行!");
return;
}
//提取所選列表項各列內容
CString tempField1[30],tempField2[30];
for(int i=0;i<3;i++)
{
tempField1[i] = m_phonelist.GetItemText(m_index+1,i);
tempField2[i] = m_phonelist.GetItemText(m_index,i);
}
//刪除所選列表項
//m_phonelist.DeleteItem(m_index);
//在m_index位置處插入上面所刪除列表項的各列內容
//int tempItem;
for(int j=0;j<3;j++)
{
m_phonelist.SetItemText(m_index,j,tempField1[j]);
m_phonelist.SetItemText(m_index+1,j,tempField2[j]);
}
//m_index--;
//使得m_index位置處項目點亮并獲得焦點
UINT flag = LVIS_SELECTED|LVIS_FOCUSED;
m_phonelist.SetItemState(m_index,flag,flag);
}
void CPhonebookDlg::OnButtondel()
{
// TODO: Add your control notification handler code here
POSITION pos = m_phonelist.GetFirstSelectedItemPosition();
//得到項目索引
m_index = m_phonelist.GetNextSelectedItem(pos);
if(m_index == -1)
{
AfxMessageBox("請選擇一項!");
return;
}
m_phonelist.DeleteItem(m_index);
UINT flag = LVIS_SELECTED|LVIS_FOCUSED;
m_phonelist.SetItemState(m_index,flag,flag);
}
void CPhonebookDlg::OnSave()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CFile sf("電話本.txt",CFile::modeCreate | CFile::modeWrite);
CArchive ar(&sf,CArchive::store);
CString strout1,strout2,strout3,strout4,strout5;
m_sum = m_phonelist.GetItemCount();
strout1 = "序號\t\t";
strout2 = "姓名\t\t";
strout3 = "號碼\r\n";
strout4 = "行數\t\t";
strout5 = "\t\t\r\n";
ar<<strout4<<m_sum<<strout5;
ar<<strout1<<strout2<<strout3;
for(int i=0;i<m_sum;i++)
{
ar<<m_phonelist.GetItemText(i,0)+"\t\t"<<m_phonelist.GetItemText(i,1)+"\t\t"<<m_phonelist.GetItemText(i,2)+"\r\n";
}
ar.Flush();
ar.Close();
sf.Close();
}
/* CStdioFile sf;
if(sf.Open("電話本.txt",CFile::modeCreate | CFile::modeWrite))
{
CString strout;
strout = "序號\t\t姓名\t\t號碼\r\n";
sf.WriteString(strout);
m_sum = m_phonelist.GetItemCount();
for(int i=0;i<m_sum;i++)
{
strout = m_phonelist.GetItemText(i,0)+"\t\t"+m_phonelist.GetItemText(i,1)+"\t\t"+m_phonelist.GetItemText(i,2)+"\0\r\n";
sf.WriteString(strout);
}
sf.Close();
AfxMessageBox("保存成功!");
}
else
AfxMessageBox("保存失敗!");
}*/
void CPhonebookDlg::OnAdd()
{
// TODO: Add your control notification handler code here
CAddphoneDlg ed;
if(ed.DoModal()==IDOK)
{
int nn=m_phonelist.InsertItem(m_phonelist.GetItemCount(),ed.m_strno);
m_phonelist.SetItemText(nn,1,ed.m_strname);
m_phonelist.SetItemText(nn,2,ed.m_strphone);
}
}
void CPhonebookDlg::OnEdit()
{
// TODO: Add your control notification handler code here
POSITION pos = m_phonelist.GetFirstSelectedItemPosition();
//得到項目索引
m_index = m_phonelist.GetNextSelectedItem(pos);
if(m_index == -1)
{
AfxMessageBox("請選擇一項!");
return;
}
CAddphoneDlg ed;
ed.m_strno=m_phonelist.GetItemText(m_index,0);
ed.m_strname=m_phonelist.GetItemText(m_index,1);
ed.m_strphone=m_phonelist.GetItemText(m_index,2);
if(ed.DoModal()==IDOK)
{
m_phonelist.SetItemText(m_index,0,ed.m_strno);
m_phonelist.SetItemText(m_index,1,ed.m_strname);
m_phonelist.SetItemText(m_index,2,ed.m_strphone);
}
}
void CPhonebookDlg::OnSelect()
{
// TODO: Add your control notification handler code here
POSITION pos = m_phonelist.GetFirstSelectedItemPosition();
//得到項目索引
m_index = m_phonelist.GetNextSelectedItem(pos);
if(m_index == -1)
{
AfxMessageBox("請選擇一聯系人!");
return;
}
//CSendDlg teleadd1;
//teleadd1.m_addnum=m_phonelist.GetItemText(m_index,2);
//teleadd1.m_selephone.AddString(teleadd1.m_addnum);
AfxMessageBox("選擇成功!");
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -