📄 subject_59980.htm
字号:
<p>
序号:59980 发表者:123213 发表日期:2003-11-11 13:36:37
<br>主题:MFC自动生成的“打开”文档功能,怎么修改一下?
<br>内容:MFC自动生成的“打开”文档功能,怎么修改一下能满足一次可以连续打开多个文档?
<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>回复者:视频新手 回复日期:2003-11-11 16:42:36
<br>内容:在CAaaaApp类中给ID_FILE_OPEN加一个处理函数OnFileOpen()<BR><BR>void CAaaaApp::OnFileOpen() <BR>{<BR> CFileDialog dlg(TRUE);<BR> dlg.m_ofn.Flags |= OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT;<BR> if (dlg.DoModal() == IDOK) {<BR> POSITION pos = dlg.GetStartPosition( );<BR> while (pos != NULL) {<BR> CString str = dlg.GetNextPathName(pos);<BR> LPCTSTR lpszPathName = str.GetBuffer (str.GetLength()+1);<BR> OpenDocumentFile(lpszPathName);<BR> }<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>
回复者:巴拉克 回复日期:2003-11-11 17:10:30
<br>内容:这个OFN_ALLOWMULTISELECT就是允许选择多个。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:GreatGuo 回复日期:2003-11-11 22:11:25
<br>内容:我自己写的代码,可以使用,但是要注意如果打开文件特别多,要修改缓冲的大小<BR><BR>#define _MAX_PATH_MULTI_SEL 3*_MAX_PATH<BR>#include <afxtempl.h><BR>void CTHApp::OnFileOpen() <BR>{<BR> ASSERT(m_pDocManager);<BR> BeginWaitCursor();<BR> CString newName;<BR> if (!DoPromptFileName(newName, AFX_IDS_OPENFILE,<BR> OFN_HIDEREADONLY | OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT, TRUE, NULL)){<BR> newName.ReleaseBuffer();<BR> return; // open cancelled<BR> }<BR> //when user multi selected,the format is PATH NAME\0FILE NAME 1\0<BR> //FILE NAME2\0... because i have set the buffer full of 0,so the <BR> //first encoutered \0\0 is the end of the buffer<BR> CList<char*,char*> nameList;<BR> char* pstr=(char*)(LPCTSTR)newName;<BR> int l=strlen(pstr);<BR> int index=l;<BR> while(l){<BR> nameList.AddTail(pstr);<BR> index++;<BR> pstr=(char*)((LPCTSTR)newName+index) ;<BR> l=strlen(pstr);<BR> index+=l;<BR> }<BR> if(nameList.GetCount()!=0){<BR> if(nameList.GetCount()==1){<BR> OpenDocumentFile(nameList.GetHead());<BR> }else{//multi sel<BR> POSITION pos=nameList.GetHeadPosition();<BR> CString path=nameList.GetNext(pos);<BR> path+="\\";<BR> while(pos!=NULL){<BR> CString file=nameList.GetNext(pos);<BR> OpenDocumentFile(path+file);<BR> }<BR> }<BR> }<BR> nameList.RemoveAll();<BR> newName.ReleaseBuffer();<BR> EndWaitCursor();<BR><BR>}<BR><BR>BOOL CTHApp::DoPromptFileName(CString &fileName, UINT nIDSTitle, DWORD lFlags, BOOL bOpenFileDialog, CDocTemplate *pTemplate)<BR>{<BR> CString strFilter;<BR> strFilter.LoadString(IDS_FILE_TYPE);<BR> CString allFilter;<BR> VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER));<BR> strFilter += allFilter;<BR> strFilter += (TCHAR)'|'; // next string please<BR> strFilter += _T("*.*");<BR> strFilter += (TCHAR)'||'; // last string<BR> CFileDialog dlgFile(bOpenFileDialog,"dhg",NULL,0,LPCTSTR(strFilter));<BR><BR> CString title;<BR> VERIFY(title.LoadString(nIDSTitle));<BR><BR> dlgFile.m_ofn.Flags |= lFlags;<BR><BR> dlgFile.m_ofn.lpstrTitle = title;<BR> dlgFile.m_ofn.nMaxFile=_MAX_PATH_MULTI_SEL;<BR> dlgFile.m_ofn.lpstrFile = fileName.GetBuffer(_MAX_PATH_MULTI_SEL);<BR> //set the buttfer with 0<BR> memset(dlgFile.m_ofn.lpstrFile,0,_MAX_PATH_MULTI_SEL);<BR> int nResult = dlgFile.DoModal();<BR> return nResult == IDOK;<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-11-12 13:38:04
<br>内容:开是向导中选择基于MDI支持多文档!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:123213 回复日期:2003-11-12 14:23:03
<br>内容:各位老兄: 我的情况是这样的:<BR> 我想修改ID_FILE_OPEN原来的MFC的代码, 因为如果按照这样修改还会影响到其它的问题.对视频新手老师提供的方法,能否直接修改MFC的代码.
<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-11-13 10:09:14
<br>内容:<BLOCKQUOTE>引用“第5楼”所言<BR><Q>各位老兄: 我的情况是这样的: 我想修改ID_FILE_OPEN原来的MFC的代码, 因为如果按照这样修改还会影响到其它的问题.对视频新手老师提供的方法,能否直接修改MFC的代码.</Q></BLOCKQUOTE><BR><BR>最好不要改MFC源码, 否则以后你开发别的程序就会受影响.<BR>另外正如3楼说的, 如果选中的文件比较多, 那么CFileDialog的缓冲区会不够大,<BR>至于如何处理, 可以去看MSDN中CFileDialog的说明.<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 + -