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

📄 subject_26393.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:26393 发表者:美丽的小东西 发表日期:2002-12-31 16:42:32
<br>主题:如何判断某文件存在?如何使用list控件的FindItem?
<br>内容:期望能遇高人指点!<BR>1。存储文件时,如何判断文件是否存在?如何覆盖已有的文件?<BR>2。如何查找LIst控件中符合条件的条目?万分感谢!
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:bird 回复日期:2002-12-31 16:51:32
<br>内容:1.CreateFile()中有参数dwCreationDispostion 来判断,看看MSDN吧!<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:bird 回复日期:2002-12-31 16:53:18
<br>内容:2.呵呵...........!MSDN的copy!<BR><BR>CListCtrl::FindItem<BR>int FindItem( LVFINDINFO* pFindInfo, int nStart = -1 ) const;<BR><BR>Return Value<BR><BR>The index of the item if successful or -1 otherwise.<BR><BR>Parameters<BR><BR>pFindInfo<BR><BR>A pointer to aLVFINDINFO structure containing information about the item to be searched for. <BR><BR>nStart<BR><BR>Index of the item to begin the search with, or -1 to start from the beginning. The item at nStart is excluded from the search if nStart is not equal to -1.<BR><BR>Remarks<BR><BR>Use this function to search for a list view item having specified characteristics.<BR><BR>The pFindInfo parameter points to an LVFINDINFO structure, which contains information used to search for a list view item.<BR><BR>Example<BR><BR>// The pointer to my list view control.<BR>extern CListCtrl* pmyListCtrl;<BR>// The string to match.<BR>extern LPCTSTR lpszmyString;<BR><BR>LVFINDINFO info;<BR>int nIndex;<BR><BR>info.flags = LVFI_PARTIAL|LVFI_STRING;<BR>info.psz = lpszmyString;<BR><BR>// Delete all of the items that begin with the string lpszmyString.<BR>while ((nIndex=pmyListCtrl-&gt;FindItem(&amp;info)) != -1)<BR>{<BR>&nbsp;&nbsp; pmyListCtrl-&gt;DeleteItem(nIndex);<BR>}<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:bb 回复日期:2002-12-31 17:04:27
<br>内容:判断文件是否存在<BR>access(filename, 0)&lt;0 不存在<BR>覆盖文件<BR>fopen(filename, "wb+");<BR><BR>open(filename, _O_TRUNC|_O_RDWR|_O_BINARY|_O_CREAT, _S_IREAD|_S_IWRITE);<BR><BR>CreateFile(filename,GENERIC_ALL,FILE_SHARE_READ, NULL, TRUNCATE_EXISTING|CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE, NULL);<BR><BR>Finditem as "bird"
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:美丽的小东西 回复日期:2003-01-02 11:29:22
<br>内容:非常感谢bb和bird!!还有不懂,希望赐教!下面是保存文件的代码:<BR>CFileDialog m_file(FALSE,"mdb","",OFN_OVERWRITEPROMPT,"acess文件(*.mdb)|*.mdb||"); //创建文件<BR>CString filepath;<BR>if (m_file.DoModal()==IDOK)<BR>{<BR>&nbsp;&nbsp; filepath=m_file.GetPathName();<BR>&nbsp;&nbsp;///加入<BR>&nbsp;&nbsp; if(::access(filepath,0)&lt;0)&nbsp;&nbsp; //出错<BR>&nbsp;&nbsp;&nbsp;&nbsp;......<BR>}<BR>错误信息:error C2039: 'access' : is not a member of '`global namespace''<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;error C2065: 'access' : undeclared identifier<BR>是哪里错了?那怎么办呢?<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:美丽的小东西 回复日期:2003-01-02 11:46:53
<br>内容:呜呜!原来是我没有加入头文件导致错误的。非常感谢bird and bb.以后多多指教哦!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:upstream 回复日期:2003-01-02 12:23:28
<br>内容:如果用_access的话,需要头文件#include "io.h"<BR><BR>我一般是这样来判断文件存在与否。<BR><BR>BOOL FileExist(CString strFileName)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;CFile file;<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(file.Open(_T(strFileName),CFile::modeRead,NULL))<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file.Close();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return TRUE;<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;return FALSE;<BR>}<BR><BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

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