我正在做一个SDI项目。我有两个函数名称sendtext(CString str)和 displaytext(CString inr)都在不同的类。 我有一个指针名称pView发送字符串str功能“displaytext”。 问题是一些操作后,我得到一个文本在str中,我发送该文本来显示输出屏幕中的文本我得到的文本和文第二个文本来到“显示文本”前文本消失,最新的字符串只存在。 Pleae帮助我如何显示ClistCtrl类上的输出窗口中的文本。在VC++ SDI应用程序中函数之间传递的字符串
Void sendtext()
{
CTreeCtrl& trCtrl = GetTreeCtrl();
HTREEITEM hItem,hsc;
CExerciseDoc *pDoc = GetDocument();
CString pathname,strLine;
CString filename;
CFileDialog dlg(TRUE);
dlg.DoModal();
if(dlg.DoModal() == IDOK)
{
pathname=dlg.GetPathName(); // return full path and filename
}
CStdioFile File;
if(File.Open(pathname, CFile::modeRead)) // Open file to be read
{
while(File.ReadString(strLine)) // Read file
{
int Position = 0;
CString Token;
CAtlString str(strLine);
CAtlString resToken,resToken1;
resToken = str.Tokenize(_T("-:, "), Position);
pDoc->pSendview->displaytext(resToken);
if(resToken != (_T(""))) // Empty File Check
hItem = trCtrl.InsertItem(resToken , 0, 2);
while(resToken!="")
{
resToken = str.Tokenize(_T("-:@, "), Position);
}
}
}
}
}
void CRightView::displaytext(CAtlString league)
{
CListCtrl &ctlRightView = this->GetListCtrl();
ResetLeagues();
CAtlString resToken;
ctlRightView.InsertColumn(1, _T("First "), LVCFMT_LEFT, 80);
ctlRightView.InsertColumn(1, _T("Second "), LVCFMT_LEFT, 80);
int nItem;
nItem = ctlRightView.InsertItem(0, league);
ctlRightView.SetItemText(nItem, 1, league);
}
文本文件包含以下内容
男人,女人
兄弟姐妹
让我解释一下你。在sendtext()我打开一个文本文件打开后,我记号化它和标记化输出是resToken其被发送通过
pDoc->pLeftView->displaytext(resToken);
到displaytext(),当我在客户端窗口运行时我运行该应用我我得到文本“人”,它用于空文件检查,并在while循环被打破后它来到相同的标记区域,并开始标记化文本文件中的新行,如兄弟姐妹和标记输出发送到显示文本通过上面提到的同一段代码。
在客户端窗口我得到的东西为“兄弟”我没有看到“人” ..我想无论是“人哥”显示为
优先(列名)
哥哥
人
更加明确,并提供更多的代码。 –
嘿请看看代码这是我做甲肝至今 –
OK,请编辑您的问题,以便:1)格式化你的源代码,这是可读的正确缩进的话)。 2)提供路径名中文件内容的样本。 3)描述列表控件应该如何与第2点提供的文件一样)。 –