📄 listtextdlg.cpp
字号:
// ListTextDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ListText.h"
#include "ListTextDlg.h"
#include "MyDialog.h"
#include "afx.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();
void MyTrim(char *pbuffer, int len)
{ char *PByte = pbuffer;
for (int i = 0; i<len; i++)
{ if ((*PByte)==' ')
{(*PByte)=0;
break;
};
PByte++;
};
}
// 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()
/////////////////////////////////////////////////////////////////////////////
// CListTextDlg dialog
CListTextDlg::CListTextDlg(CWnd* pParent /*=NULL*/)
: CDialog(CListTextDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CListTextDlg)
m_Edit1 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CListTextDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CListTextDlg)
DDX_Control(pDX, IDC_LIST1, m_ListCtrl);
DDX_Text(pDX, IDC_EDIT1, m_Edit1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CListTextDlg, CDialog)
//{{AFX_MSG_MAP(CListTextDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(LVN_INSERTITEM, IDC_LIST1, OnInsertitemList1)
ON_BN_CLICKED(IDC_BUTTON2, OnDel)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CListTextDlg message handlers
BOOL CListTextDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// SPS Sps[]=
//
// {//信息
/*
{"红梅",0,"1000","30","30000"},
{"黄梅",0,"1000","29","29000"},
{"绿梅",0,"1000","28","28000"},
{"青梅",0,"1000","27","27000"},
{"白梅",0,"1000","31","31000"},
{"红梅",1,"1000","30","30000"},
{"黄梅",1,"1000","29","29000"},
{"绿梅",1,"1000","28","28000"},
{"青梅",1,"1000","27","27000"},
{"白梅",1,"1000","31","31000"}}; */
LV_ITEM lvitem;
LV_COLUMN lvcol;
int i;
lvcol.mask=LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;
lvcol.fmt=LVCFMT_CENTER;//居中
i=0;
lvcol.pszText="日期";
lvcol.iSubItem=i;
lvcol.cx=70;
m_ListCtrl.InsertColumn(i++,&lvcol);
lvcol.pszText="发送人";
lvcol.iSubItem=i;
lvcol.cx=70;
m_ListCtrl.InsertColumn(i++,&lvcol);
lvcol.pszText="单 价";
lvcol.iSubItem=i;
lvcol.cx=70;
m_ListCtrl.InsertColumn(i++,&lvcol);
lvcol.pszText="金 额";
lvcol.iSubItem=i;
lvcol.cx=70;
m_ListCtrl.InsertColumn(i++,&lvcol);
lvcol.pszText="数量";
lvcol.iSubItem=i;
lvcol.cx=70;
m_ListCtrl.InsertColumn(i++,&lvcol);
//向列表控制中添加表项
//const int ItemsAmount=60;
CFile myfile;
myfile.Open("wokao.txt",CFile::modeReadWrite);
//ULONGLONG flength;
int b;
b=sizeof(SPS);
int flength=myfile.GetLength();
int ItemsAmount=int (flength/b);
SPS buf[60];
//{
// {"hongmei",0,"1","30","30000"},
// {"huangmei",0,"1","29","29000"}
//};
//myfile.Write(buf,ItemsAmount*sizeof(SPS));
int count=myfile.Read(buf,ItemsAmount*sizeof(SPS));
myfile.Close();
UpdateData(0);
char sbuffer[20];
//Sps=buf;
//SPS Sps;
//SPS buf[100];
// myfile_1.Open("wokao.txt",CFile::modeRead);
// int Record=i+1;
// buf=GetData(myfile_2,Record);
// int offset;
// SPS buf;
//计算第nRecord条记录在文件中的位置
// offset=(Record-1)*sizeof(SPS);
//文件指针移到文件头
// myfile_1.SeekToBegin();
//从当前位置移动offset个字节
// myfile_1.Seek(offset, CFile::begin);
//读取记录信息
// myfile_1.Read(buf,sizeof(SPS));
int q=ItemsAmount-1;
int j=0;
while (q>=0)
{ int iPos;
if (count<=0)
break;
memcpy(sbuffer,buf[j].szPm,10);
MyTrim(sbuffer,10);
lvitem.mask=LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
// lvitem.iItem=i;
// lvitem.iSubItem=0;
// lvitem.pszText=buf[i].szPm;
//lvitem.iImage=buf[i].Lx;
//lvitem.lParam=i;
iPos=m_ListCtrl.InsertItem(j,sbuffer);//返回表项插入后的索引号
//m_ListCtrl.SetItemText(iPos,1,buf[j].szPm);
memcpy(sbuffer,buf[j].Lx,2);
MyTrim(sbuffer,2);
m_ListCtrl.SetItemText(iPos,1,sbuffer);
memcpy(sbuffer,buf[j].szSl,5);
MyTrim(sbuffer,5);
m_ListCtrl.SetItemText(iPos,2,sbuffer);
memcpy(sbuffer,buf[j].szDj,5);
MyTrim(sbuffer,5);
m_ListCtrl.SetItemText(iPos,3,sbuffer);
memcpy(sbuffer,buf[j].szJe,5);
MyTrim(sbuffer,5);
m_ListCtrl.SetItemText(iPos,4,sbuffer);
/*lvitem.mask=LVIF_TEXT;
lvitem.iItem=iPos;
lvitem.iSubItem=1;
lvitem.pszText=buf[i].szSl;
m_ListCtrl.SetItem(&lvitem);
lvitem.iSubItem=2;
lvitem.pszText=buf[i].szDj;
m_ListCtrl.SetItem(&lvitem);
lvitem.iSubItem=3;
lvitem.pszText=buf[i].szJe;
m_ListCtrl.SetItem(&lvitem); */
j++;
q--;
count-=sizeof(SPS);
UpdateData(true);
}
// 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
return TRUE; // return TRUE unless you set the focus to a control
}
void CListTextDlg::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 CListTextDlg::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 CListTextDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CListTextDlg::OnInsertitemList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
//m_List.InsertColumn(
*pResult = 0;
}
void CListTextDlg::OnDel()
{
// TODO: Add your control notification handler code here
int i,iState;
int nItemSelected=m_ListCtrl.GetSelectedCount();//所选表项数
int nItemCount=m_ListCtrl.GetItemCount();//表项总数
if(nItemSelected<1) return;
for(i=nItemCount-1;i>=0;i--){
iState=m_ListCtrl.GetItemState(i,LVIS_SELECTED);
if(iState!=0) m_ListCtrl.DeleteItem(i);
}
}
void CListTextDlg::OnButton1()
{
// TODO: Add your control notification handler code here
//void MyDialog::OnChangeSmsEdit() ;
/* MyDialog dlg;
dlg.DoModal();
//dlg.m_MySms=buf[];
// CFileDialog dlg(TRUE, NULL,"*.txt",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"*.txt",NULL);
// UpdateData(true);
// char *pszFileName = "wokao.txt";
char szBuffer[300];
int i;
UINT dwActual;
for( i=0; i<100; i++ )
szBuffer = NULL;
CFile myfile;
// CFileException fileException;
myfile.Open("wokao.txt",CFile::modeRead);
myfile.Seek( 0, CFile::begin );
dwActual = (UINT)myfile.SeekToEnd();
myfile.SeekToBegin();
myfile.Read(szBuffer, sizeof(szBuffer));
myfile.Close();
m_MySms=szBuffer;
UpdateData(0);
}
// dlg.SetWindowText("hhahaaha");
// dlg.ShowWindow(SW_SHOW);
//CFile file;
// const char*filename="D:\\wokao.txt";
/*file.Open("wokao.txt",CFile::modeRead);
ULONGLONG flength;
flength=file.GetLength();
char buf[128];
CString nBytesRead;
nBytesRead=file.Read(buf,sizeof(buf));
m_Edit1=nBytesRead;
file.Abort();
}*/
}
void CListTextDlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
void MyDialog::SmsContent();
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -