CFile::Open virtual BOOL Open( LPCTSTR lpszFileName, UINT nOpenFlags, CFileException* pError = NULL );Return ValueNonzero if the open was successful; otherwise 0. The pError parameter is meaningful only if 0 is returned.不检查返回值可不是个好习惯
CStdioFile InfoFile; LPCSTR lpszFileName; lpszFileName = "d:\\info.INF"; InfoFile.Open(lpszFileName,CFile::modeRead); CString str; InfoFile.ReadString(str);//?第一行 InfoFile.Close(); 我在VC中New a file named the above name,and type one line,and run the above codes,the result is correct! 你可以再找找其原因
to ydogg(灰毛兔):sorry,我没把意思表述清楚,我是想按下按钮1,edit中显示“str1”,按下按钮2,edit中另起一行显示“str2”,这是不是实际上要移动光标cursor? 另外FindFile(*.*)好像是可以的,现在要命的是,我并不确定目录里的文件叫什么名字(每天更新,名字不确定),怎么find呢?to : neomeng(大胖)要是在OnTimer就关掉,不就不能循环了吗?
就ok了
第二个问题吗 你多比较比较 标准的建立进程的方法 看有没有问题
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent == 1){
CCPublishDlg::Process();
} CDialog::OnTimer(nIDEvent);
}
void CCPublishDlg::Process()
{
//读取配置文件信息
CStdioFile InfoFile;
LPCSTR lpszFileName;
lpszFileName = "d:\info.INF";
InfoFile.Open(lpszFileName,CFile::modeRead);
CString str;
InfoFile.ReadString(str);//读第一行
InfoFile.Close();
}drawtext可以在对话框中直接显示吗?假如我想在edit中显示呢(看着美观些)?
改为:
lpszFileName = "d:\\info.INF";试一试
改为:
lpszFileName = "d:\\info.INF";试一试
drawtext好象不能在对话框中直接显示。要在edit中显示,可以用函数SetWinowText(...)
virtual BOOL Open( LPCTSTR lpszFileName, UINT nOpenFlags, CFileException* pError = NULL );Return ValueNonzero if the open was successful; otherwise 0. The pError parameter is meaningful only if 0 is returned.不检查返回值可不是个好习惯
Debug Assert Failed
Program:...ICROSOFT VISUAL
……
File:fgets.c
Line:60
Exception:str != NULL
……另外问一个让诸位晕倒的问题:怎样看布尔函数的返回值,我在Debug下找不见(唉……),将open拉下来也不行,怎么做?
在你完成了某一任务时,可改变其标题。
GetDlgItem(IDC_STATIC_YOUR)->SetWindowText("程序正在运行");2."\"在C,C++中是一个很特殊的符号,需要表示\时,应用如下方式:"\\"
另外,你打开文件的方式需要注意。
如果你的d:\info.INF文件尚未建立,则这样用modeRead方式打开是错误的。
这里你的错误在:
InfoFile.ReadString(&str)//你没有使用引用
InfoFile.ReadString(&str)//你没有使用引用
这句话是错误的,其参数为引用而已。
不要用&.将InfoFile.Open(lpszFileName,CFile::modeRead);
换为
InfoFile.Open(lpszFileName,CFile::modeCreate|CFile::modeRead);
试试看返回值。
LPCSTR lpszFileName;
lpszFileName = "d:\\info.INF";
InfoFile.Open(lpszFileName,CFile::modeRead);
CString str;
InfoFile.ReadString(str);//?第一行
InfoFile.Close();
我在VC中New a file named the above name,and type one line,and run the above codes,the result is correct!
你可以再找找其原因
SetWindowsText("正在运行...\r\n现在的状态")//
FindFile()不支持统配符*.需要明确的写出文件名
SetWindowsText("正在运行...\r\nfile1.txt\r\nfile2....")
2 用FindFirstFile和FindNextFile
另外FindFile(*.*)好像是可以的,现在要命的是,我并不确定目录里的文件叫什么名字(每天更新,名字不确定),怎么find呢?to : neomeng(大胖)要是在OnTimer就关掉,不就不能循环了吗?
如果用CFileFind类的话,*.txt也应该是可以的。
CFileFind ff;
BOOL bFind;
bFind=ff.FindFile("d:\\document\\*.txt");
while(bFind)
{
...
...
bFind=ff.FindNextFile();
}
你的意思我明白了。可是如果在一个Edit中想换行表示,就要将两个字符串联在一起(中间加\r\n)
你可以这样去做:
1.每次显示时,先得到Edit中目前存在的内容,可用GetWindowText(temp);
2.temp=+"\\r\\n";
temp
显示这样可以吧。
你的意思我明白了。可是如果在一个Edit中想换行表示,就要将两个字符串联在一起(中间加\r\n)
你可以这样去做:
1.每次显示时,先得到Edit中目前存在的内容,可用GetWindowText(temp);
2.temp+="\\r\\n";
temp+=yournewstr;
3.显示这样可以吧。
bFind值为0,why?
2.在c的字符串中'\'是转意字符,要想表示反斜杆必须用'\\'(这里'\\'只表示一个字符,
所以用了单引号),'\r'表示回车,'\n'表示换行。
3。bFind=ff.FindFile("d:\\document\\*.txt")我测试是成功的,你检查一下你的路径是否正确,txt文件是否存在