⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cfxtxdlg.cpp

📁 这个还可以
💻 CPP
字号:
// CFxTxDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CFxTx.h"
#include "CFxTxDlg.h"
#include  "MyTextButton.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 };
	CMyTextButton	m_3dbtn;
	//}}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)
	virtual BOOL OnInitDialog();
	//}}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)
	DDX_Control(pDX, IDC_BUTTON1, m_3dbtn);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCFxTxDlg dialog

CCFxTxDlg::CCFxTxDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCFxTxDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCFxTxDlg)
	m_addr = _T("");
	m_birday = _T("");
	m_famtel = _T("");
	m_icq = _T("");
	m_movetel = _T("");
	m_name = _T("");
	m_offtel = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	memset(&record,0,sizeof(record));
	recordsize=sizeof(record);
    Status=FALSE;
}

void CCFxTxDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCFxTxDlg)
	DDX_Control(pDX, IDC_BUTTON1, m_btn);
	DDX_Control(pDX, IDC_OFFTEL, m_offtel_ctrl);
	DDX_Control(pDX, IDC_MOVETEL, m_movetel_ctrl);
	DDX_Control(pDX, IDC_ICQ, m_icq_ctrl);
	DDX_Control(pDX, IDC_FAMTEL, m_famtel_ctrl);
	DDX_Control(pDX, IDC_BIRDAY, m_birday_ctrl);
	DDX_Control(pDX, IDC_ADDR, m_addr_ctrl);
	DDX_Control(pDX, IDC_NAME, m_name_ctrl);
	DDX_Control(pDX, IDC_LISTCTRL, m_listctrl);
	DDX_Text(pDX, IDC_ADDR, m_addr);
	DDX_Text(pDX, IDC_BIRDAY, m_birday);
	DDX_Text(pDX, IDC_FAMTEL, m_famtel);
	DDX_Text(pDX, IDC_ICQ, m_icq);
	DDX_Text(pDX, IDC_MOVETEL, m_movetel);
	DDX_Text(pDX, IDC_NAME, m_name);
	DDX_Text(pDX, IDC_OFFTEL, m_offtel);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCFxTxDlg, CDialog)
	//{{AFX_MSG_MAP(CCFxTxDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_QUERY, OnQuery)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCFxTxDlg message handlers

BOOL CCFxTxDlg::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
	m_btn.SetFontStyle("隶书");
	//**********************************************************************
	//初始化列表框属性:
	 m_listctrl.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_UNDERLINEHOT|
		 LVS_EX_FULLROWSELECT|LVS_EX_ONECLICKACTIVATE);
     m_listctrl.SetBkColor(RGB(220,220,10));
	 m_listctrl.SetTextColor(RGB(220,10,10));
	 m_listctrl.SetTextBkColor(RGB(220,220,10));
     m_listctrl.InsertColumn(0,"姓名",LVCFMT_LEFT,50);
	 m_listctrl.InsertColumn(1,"家庭电话",LVCFMT_CENTER,60);
	 m_listctrl.InsertColumn(2,"办公电话",LVCFMT_CENTER,60);
	 m_listctrl.InsertColumn(3,"移动电话",LVCFMT_CENTER,60);
     m_listctrl.InsertColumn(4,"出生日期",LVCFMT_CENTER,60);
	 m_listctrl.InsertColumn(5,"(O)ICQ",LVCFMT_CENTER,60);
	 m_listctrl.InsertColumn(6,"地址",LVCFMT_CENTER,60);
	//对文件进行操纵
    Status=file.Open("c:\\tongxun.txt",CFile::modeReadWrite,NULL);
    if(!Status)
	{
		if(!file.Open("c:\\tongxun.txt",CFile::modeReadWrite|CFile::modeCreate,NULL))
		{
			MessageBox("创建文件失败!"); 
		}
		else
		{
			Status=TRUE;
		}
	}
	else
	{
		int lenght=file.GetLength()/recordsize;
        if(lenght>=0)
		{   
          for(int i=0;i<lenght;i++)
		  {

			file.Seek(recordsize*i,CFile::begin);
			file.Read(&record,sizeof(record));
		//	file.Seek(-recordsize,CFile::current);
            CString str;
	        str.Format("%s",record.name);
	        m_listctrl.InsertItem(i,str);
	        m_listctrl.SetItemText(i,0,(char *)record.name);
	        m_listctrl.SetItemText(i,1,(char *)record.famtel);
	        m_listctrl.SetItemText(i,2,(char *)record.offtel);
            m_listctrl.SetItemText(i,3,(char *)record.movetel);
	        m_listctrl.SetItemText(i,4,(char *)record.birday);
	        m_listctrl.SetItemText(i,5,(char *)record.icq);
        	m_listctrl.SetItemText(i,6,(char *)record.addr);
		  }
             
		}
	}
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CCFxTxDlg::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 CCFxTxDlg::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 CCFxTxDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CCFxTxDlg::OnAdd() 
{
	// Set Dialog  Vriablers to  struct DFeiXaing;
	UpdateData();
	if(m_name.IsEmpty())
	{
	    MessageBox("姓名不能为空,请重新输入!");
		m_name_ctrl.SetFocus();
	}/*
	strcpy((char *)record.name,(LPCTSTR)m_name);
	strcpy((char *)record.famtel,(LPCTSTR)m_famtel);
	strcpy((char *)record.offtel,(LPCTSTR)m_offtel);
	strcpy((char *)record.movetel,(LPCTSTR)m_movetel);
	strcpy((char *)record.birday,(LPCTSTR)m_birday);
	strcpy((char *)record.addr,(LPCTSTR)m_addr);
    strcpy((char *)record.icq,(LPCTSTR)m_icq);
	//Set CEditCtrl ro Empty;
	m_name_ctrl.SetWindowText("");
	m_famtel_ctrl.SetWindowText("");
	m_offtel_ctrl.SetWindowText("");
	m_movetel_ctrl.SetWindowText("");
	m_icq_ctrl.SetWindowText("");
	m_birday_ctrl.SetWindowText("");
	m_addr_ctrl.SetWindowText("");
    //Set these Vriablers to CtrlList; 
	int i=m_listctrl.GetItemCount();
	CString str;
	str.Format("%s",record.name);
	m_listctrl.InsertItem(i,str);
	m_listctrl.SetItemText(i,0,(char *)record.name);
	m_listctrl.SetItemText(i,1,(char *)record.famtel);
	m_listctrl.SetItemText(i,2,(char *)record.offtel);
	m_listctrl.SetItemText(i,3,(char *)record.movetel);
	m_listctrl.SetItemText(i,4,(char *)record.birday);
	m_listctrl.SetItemText(i,5,(char *)record.icq);
	m_listctrl.SetItemText(i,6,(char *)record.addr);
	//Set these Vriablers save in file;
	if(Status)
	{ 
	  file.SeekToEnd();
      file.Write(&record,sizeof(record));
	  file.Flush();
	  file.Seek(-recordsize,CFile::current);
	}
     //************************************************************
   m_name_ctrl.SetFocus();*/
    
}

BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_3dbtn.SetFontStyle("隶书");
	// TODO: Add extra initialization here
      
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CCFxTxDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	m_listctrl.DeleteItem(m_listctrl.GetNextItem(-1,LVNI_ALL|LVNI_SELECTED));
}

void CCFxTxDlg::OnQuery() 
{
    BOOL isfind=FALSE;
	UpdateData();
    
       int ln=file.GetLength()/recordsize;
	   if(ln>=0)
	   {
		   for(int i=0;i<ln;i++)
		   {
			 
             file.Seek(recordsize*i,CFile::begin);
             file.Read(&record,sizeof(record));
		     if(0==strcmp((char *)record.name,(LPCTSTR)m_name))
			 {  
				  m_name_ctrl.SetWindowText((char *)record.name);
				  m_famtel_ctrl.SetWindowText((char *)record.famtel);
				  m_offtel_ctrl.SetWindowText((char *)record.offtel);
				  m_movetel_ctrl.SetWindowText((char *)record.movetel);
				  m_icq_ctrl.SetWindowText((char *)record.icq);
				  m_birday_ctrl.SetWindowText((char *)record.birday);
				  m_addr_ctrl.SetWindowText((char *)record.addr);
				  
			 }
			 
		   }
             

	   }


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -