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

📄 teldlg.cpp

📁 HP688的电话薄程序
💻 CPP
字号:
// TelDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Tel.h"
#include "TelDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTelDlg dialog

CTelDlg::CTelDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTelDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTelDlg)
		// 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 CTelDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTelDlg)
	DDX_Control(pDX, IDC_LIST, m_List);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTelDlg, CDialog)
	//{{AFX_MSG_MAP(CTelDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_OPEN, OnOpen)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTelDlg message handlers

BOOL CTelDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

unsigned char Buf[0x100012];
unsigned char IndexBuf[4096];
int  IndexPtr[1024];
void BublebSort(int Array[],int Num)
{
  int i,j,k,m;
  int dat;
  k=0; m=Num-1;
  while(k<m)
  {
     j=m-1;
     m=0;
     for(i=k;i<=j;i++)
       if(Array[i]>Array[i+1])
       {
       	 dat=Array[i];
       	 Array[i]=Array[i+1];
       	 Array[i+1]=dat;
       	 m=i;
       }
     j=k+1;
     k=0;
     for(i=m;i>=j;i--)
       if(Array[i-1]>Array[i])
       {
       	 dat=Array[i];
       	 Array[i]=Array[i-1];
       	 Array[i-1]=dat;
       	 k=i;
       }
  }
}

void CTelDlg::OnOpen() 
{
	int i,j,k;
	char txt[512];
	CString str,fn;
	FILE *fp;
	int n1;
	short s1;

	CFileDialog dlg(TRUE, "rec", "D:\\HP688\\HP688TEL.rec", 
	OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"记录(*.rec)|*.rec|所有文件(*.*)|*.*|", NULL );
	if(dlg.DoModal()==IDOK)		fn=dlg.GetPathName(); 
	else return;

	fp=fopen(fn,"rb");
	fread(Buf,0x100000,1,fp);
	fread(&s1,sizeof(s1),1,fp);
	fread(&Index,sizeof(Index),1,fp);
	fread(&n1,sizeof(n1),1,fp);
	fread(&RecLen,sizeof(RecLen),1,fp);
	fread(&IndexAddr,sizeof(IndexAddr),1,fp);

	for(i=0;i<Index*3;i++)
		IndexBuf[i]=Buf[IndexAddr+i+1];

	for(i=0;i<Index;i++)
		IndexPtr[i]=256*((unsigned int)IndexBuf[i*3+1])+(unsigned int)IndexBuf[i*3];

	BublebSort(IndexPtr,Index);
	m_List.ResetContent();
	for(i=0;i<Index;i++)
	{
		j=0;
		k=0;
		do
		{
		  txt[j]=Buf[j+IndexPtr[i]];
	      if(txt[j]==0x0D)
		  { 
		    txt[j]=',';
			k++;
		  }
		  j++;
		} while(k<6);
		 txt[j]=0;
		m_List.AddString(txt);
	}

	fclose(fp);
	str.Format("共有%d个记录",Index);
	SetDlgItemText(IDC_INFO,str);
}

void CTelDlg::OnSave() 
{
	CString fn;
	FILE *fp;
	int i,j,k;
	char txt[512];
	CButton *pB=(CButton*)GetDlgItem(IDC_CHKTITLE);
	CFileDialog dlg(FALSE, "TXT", "D:\\HP688\\HP688TEL.csv", 
	OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"CSV文件(*.csv)|*.csv|文本文件(*.txt)|*.txt|所有文件(*.*)|*.*|", NULL );
	if(dlg.DoModal()==IDOK)	fn=dlg.GetPathName(); 
	else return;
	fp=fopen(fn,"w");
	if(pB->GetCheck()!=0)	fprintf(fp,"姓名,手机,电话,传真,Email,地址,备注\n");
	for(i=0;i<Index;i++)
	{
		j=0;
		k=0;
		do
		{
		  txt[j]=Buf[j+IndexPtr[i]];
	      if(txt[j]==0x0D)
		  { 
		    txt[j]=',';
			k++;
		  }
		  j++;
		} while(k<6);
		 txt[j]=0;
		 strcat(txt,"\n");
		fprintf(fp,txt);
	}
	CString str;
	str.Format("保存%d个记录",Index);
	SetDlgItemText(IDC_INFO,str);	}

⌨️ 快捷键说明

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