在single view中显示数据 大家好~我有个问题想请教大家~ 现在我写了一个TXT文档,里面存了300行数据,其中任意一行数据都包含5个数字,我想在view中将文档中的数据读取显示出来,一次显示一行数据,显示完一行数据自动提行,总之,经过300次显示之后,在窗口中显示的数据与文档中的数据内容、格式都一样~ 请问能实现吗~有啥思路呢~ 多谢了~急求~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CFileDialog dlg(FALSE, "txt ",NULL,OFN_EXPLORER |OFN_HIDEREADONLY); dlg.m_ofn.lpstrTitle="Save Files "; dlg.m_ofn.lpstrFilter="Text files(*.txt)\0*.txt\0 "; if(IDOK==dlg.DoModal()) { CString path=dlg.GetPathName(); CFile file; CString temp; float a = 12.234567, b = 12.3, c = 12.4,d=12.5,e=12.6,f=12.7; file.Open(path, CFile::modeCreate | CFile::modeReadWrite); temp = "通道1 通道2 通道3 通道4 通道5 通道6\r\n"; file.Write(temp, temp.GetLength()); CString m_str; for(int i = 0; i < 1; i++) { temp.Empty(); m_str.Format("%f ", a); temp += m_str; m_str.Format("%f ", b); temp += m_str; m_str.Format("%f ", c); temp += m_str; m_str.Format("%f ", d); temp += m_str; m_str.Format("%f ", e); temp += m_str; m_str.Format("%f ", f); temp += m_str; temp += "\r\n"; file.Write(temp, temp.GetLength()); } file.Close(); } 噢,这个是将数据保存到txt中的 山寨一点就是使用CString类的Find,Mid之类的函数来查找,专业一点的就是用正则表达式去做 首先视图如果要显示数据 需要使用PDC->TextOut()相当与是画出来的,还要计算下一行位置,还有窗口重绘的问题,挺麻烦的建议在试图中添加一个 CRichEditCtrl或者CEdit 控件 并是他与视图大小相同,相当于控件中显示文本1.视图的.h文件中声明 CRichEditCtrl m_list;2.为View类响应WM_CREATE消息int CMy123View::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; m_list.Create(ES_MULTILINE|ES_WANTRETURN|WS_CHILD|WS_VISIBLE|WS_VSCROLL,CRect(0,0,0,0,),this,1); return 0;}3.为View类增加响应消息 WM_SIZE 使控件与视图大小一致void CMy123View::OnSize(UINT nType, int cx, int cy) { CView::OnSize(nType, cx, cy); CRect rect; GetClientRect(rect); m_list.SetWindowPos(&wndTop,0,0,rect.right-rect.left,rect.bottom-rect.top,SWP_SHOWWINDOW); }4.通过ClassWizard为View类增加OnInitialUpdate()函数 在此函数中读取文件数据void CMy123View::OnInitialUpdate() { CView::OnInitialUpdate(); CStdioFile file; CString str; CString path; CString text; text=""; file.Open("my.txt",CFile::modeRead,NULL); for(int i=0;i<300;i++) { if(!file.ReadString(str)) { m_list.SetWindowText(text + "Read END"); } else { text = text + str + "\r\n"; m_list.SetWindowText(text); } } file.Close();} 我希望达到的效果是,按一个BUTTON之后,自动开始一行一行显示数据~不知道怎么下手~ 我希望达到的效果是,按下BUTTON之后自动开始显示数据,一行接一行,知道300行数据都显示完毕~不知道从哪里下手~ 我4楼的回复 对你没有一点启示么 吧我显示文本哪些函数 弄到一个 BUTTON响应函数下 不久可以显示了么 我感觉OnSize好像有点问题,我一调用OnSize,就无法运行了~ 三个线程同步+性能的问题 如何使用ADO将SQL2000中的数据添加到虚拟列表中去? 一个对话框边缘的问题? 怎么用VC 判断操作系统 请问VC全局鼠标挂钩的实现 VC6的COMMBOX 操作问题 关于m_combo.AddString(str1); 为什么鼠标钩子里WM_LBUTTONDOWN和WM_LBUTTONUP总是捕捉不到呢?(高级钩子问题) 窗体的事件顺序 Two small questions about VC 大家能不能给看看List为什么不对啊[源码] 如何得到某种字体的所有汉字的坐标信息?
CFileDialog dlg(FALSE, "txt ",NULL,OFN_EXPLORER |OFN_HIDEREADONLY);
dlg.m_ofn.lpstrTitle="Save Files ";
dlg.m_ofn.lpstrFilter="Text files(*.txt)\0*.txt\0 ";
if(IDOK==dlg.DoModal())
{
CString path=dlg.GetPathName();
CFile file;
CString temp;
float a = 12.234567, b = 12.3, c = 12.4,d=12.5,e=12.6,f=12.7;
file.Open(path, CFile::modeCreate | CFile::modeReadWrite);
temp = "通道1 通道2 通道3 通道4 通道5 通道6\r\n";
file.Write(temp, temp.GetLength());
CString m_str;
for(int i = 0; i < 1; i++)
{
temp.Empty();
m_str.Format("%f ", a);
temp += m_str;
m_str.Format("%f ", b);
temp += m_str;
m_str.Format("%f ", c);
temp += m_str;
m_str.Format("%f ", d);
temp += m_str;
m_str.Format("%f ", e);
temp += m_str;
m_str.Format("%f ", f);
temp += m_str;
temp += "\r\n";
file.Write(temp, temp.GetLength());
} file.Close();
}
专业一点的就是用正则表达式去做
建议在试图中添加一个 CRichEditCtrl或者CEdit 控件 并是他与视图大小相同,相当于控件中显示文本
1.视图的.h文件中声明 CRichEditCtrl m_list;
2.为View类响应WM_CREATE消息int CMy123View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1; m_list.Create(ES_MULTILINE|ES_WANTRETURN|WS_CHILD|WS_VISIBLE|WS_VSCROLL,CRect(0,0,0,0,),this,1);
return 0;
}3.为View类增加响应消息 WM_SIZE 使控件与视图大小一致void CMy123View::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
CRect rect;
GetClientRect(rect);
m_list.SetWindowPos(&wndTop,0,0,rect.right-rect.left,rect.bottom-rect.top,SWP_SHOWWINDOW);
}4.通过ClassWizard为View类增加OnInitialUpdate()函数 在此函数中读取文件数据void CMy123View::OnInitialUpdate()
{
CView::OnInitialUpdate();
CStdioFile file;
CString str;
CString path;
CString text;
text="";
file.Open("my.txt",CFile::modeRead,NULL);
for(int i=0;i<300;i++)
{
if(!file.ReadString(str))
{ m_list.SetWindowText(text + "Read END");
}
else
{
text = text + str + "\r\n";
m_list.SetWindowText(text);
}
}
file.Close();
}
不知道从哪里下手~