c语言程序设计实例
的有关信息介绍如下:// 电话本Dlg.cpp : 实现文件//#include stdafx.h#include 电话本.h#include 电话本Dlg.h#ifdef _DEBUG#define new DEBUG_NEW#endif// C电话本Dlg 对话框C电话本Dlg::C电话本Dlg(CWnd* pParent /*=NULL*/) : CDialog(C电话本Dlg::IDD, pParent){ m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);}void C电话本Dlg::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX);}BEGIN_MESSAGE_MAP(C电话本Dlg, CDialog) ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_EN_CHANGE(IDC_EDIT1, C电话本Dlg::OnName) ON_EN_CHANGE(IDC_EDIT2, C电话本Dlg::OnPhoto) ON_EN_CHANGE(IDC_EDIT3, C电话本Dlg::OnAddress) ON_EN_CHANGE(IDC_EDIT4, C电话本Dlg::OnShow) ON_BN_CLICKED(IDC_BUTTON1, C电话本Dlg::OnFill) ON_BN_CLICKED(IDC_BUTTON2, C电话本Dlg::OnInsert) ON_BN_CLICKED(IDC_BUTTON3, C电话本Dlg::OnFind) ON_BN_CLICKED(IDC_BUTTON4, C电话本Dlg::OnDelete) ON_BN_CLICKED(IDC_BUTTON5, C电话本Dlg::OnEdit) ON_BN_CLICKED(IDC_BUTTON7, C电话本Dlg::OnSave)END_MESSAGE_MAP()// C电话本Dlg 消息处理程序BOOL C电话本Dlg::OnInitDialog(){ CDialog::OnInitDialog(); // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 // TODO: 在此添加额外的初始化代码 ifstream InFile(Wab.fsd,ios::in); listWabList::iterator ItWab; char Tmp1[8],Tmp2[16],Tmp3[32]; Wab.clear(); while(InFile Tmp1 Tmp2 Tmp3) { OutWab.Name=Tmp1; OutWab.Photo=Tmp2; OutWab.Address=Tmp3; Wab.push_front(OutWab); } C电话本Dlg::OnFill(); return TRUE; // 除非将焦点设置到控件,否则返回 TRUE}// 如果向对话框添加最小化按钮,则需要下面的代码// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,// 这将由框架自动完成。void C电话本Dlg::OnPaint(){ if (IsIconic()) { CPaintDC dc(this); // 用于绘制的设备上下文 SendMessage(WM_ICONERASEBKGND, reinterpret_castWPARAM(dc.GetSafeHdc()), 0); // 使图标在工作矩形中居中 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; // 绘制图标 dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); }}//当用户拖动最小化窗口时系统调用此函数取得光标显示。//HCURSOR C电话本Dlg::OnQueryDragIcon(){ return static_castHCURSOR(m_hIcon);}void C电话本Dlg::OnName(){ CEdit *pMaxLen=(CEdit*)GetDlgItem(IDC_EDIT1); pMaxLen-SetLimitText(6); GetDlgItemText(IDC_EDIT1,InWab.Name);}void C电话本Dlg::OnPhoto(){ CEdit *pMaxLen=(CEdit*)GetDlgItem(IDC_EDIT2); pMaxLen-SetLimitText(11); GetDlgItemText(IDC_EDIT2,InWab.Photo);}void C电话本Dlg::OnAddress(){ CEdit *pMaxLen=(CEdit*)GetDlgItem(IDC_EDIT3); pMaxLen-SetLimitText(30); GetDlgItemText(IDC_EDIT3,InWab.Address);}void C电话本Dlg::OnShow(){ // TODO: 如果该控件是 RICHEDIT 控件,则它将不会 // 发送该通知,除非重写 CDialog::OnInitDialog() // 函数并调用 CRichEditCtrl().SetEventMask(), // 同时将 ENM_CHANGE 标志“或”运算到掩码中。 // TODO: 在此添加控件通知处理程序代码}void C电话本Dlg::OnFill(){ CString OutAll,OutTemp,Space,Enter; Space=_T( ); Enter=_T(\r\n); listWabList::iterator ItWab; for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab ) { OutWab=*ItWab; OutTemp=OutWab.Name Space OutWab.Photo Space OutWab.Address; OutAll=OutAll OutTemp Enter; } SetDlgItemText(IDC_EDIT4,OutAll);}void C电话本Dlg::OnInsert(){ Wab.push_front(InWab); C电话本Dlg::OnFill();}void C电话本Dlg::OnFind(){ CString OutAll,OutTemp,Space,Enter; Space=_T( ); Enter=_T(\r\n); listWabList::iterator ItWab; for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab ) { if(ItWab-Name==InWab.Name) { OutTemp=ItWab-Name Space ItWab-Photo Space ItWab-Address; OutAll=OutAll OutTemp Enter; } } SetDlgItemText(IDC_EDIT4,OutAll);}void C电话本Dlg::OnDelete(){ CString OutAll,OutTemp,Space,Enter; Space=_T( ); Enter=_T(\r\n); listWabList::iterator ItWab; for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab ) { if(ItWab-Name==InWab.Name) { OutTemp=ItWab-Name Space ItWab-Photo Space ItWab-Address; OutAll=OutAll OutTemp Enter; break; } } SetDlgItemText(IDC_EDIT4,OutAll); if(ItWab!=Wab.end()) Wab.erase(ItWab);}void C电话本Dlg::OnEdit(){ CString OutAll,OutTemp,Space,Enter; Space=_T( ); Enter=_T(\r\n); listWabList::iterator ItWab; for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab ) { if(ItWab-Name==InWab.Name) { OutTemp=ItWab-Name Space ItWab-Photo Space ItWab-Address; OutAll=OutAll OutTemp Enter; break; } } SetDlgItemText(IDC_EDIT4,OutAll); if(ItWab!=Wab.end()) { Wab.erase(ItWab); Wab.push_front(InWab); }}void C电话本Dlg::OnSave(){ CString Tmp1,Tmp2,Tmp3; ofstream OutFile(Wab.fsd,ios::out); listWabList::iterator ItWab; for(ItWab=Wab.begin();ItWab!=Wab.end();ItWab ) { Tmp1=ItWab-Name; Tmp2=ItWab-Photo; Tmp3=ItWab-Address; OutFile Tmp1 ' ' Tmp2 ' ' Tmp3 endl; }}只是个用C语言编写的电话本程序 很有实用意义