防止多文档文档重复打开
来源:互联网 发布:网络技术支持与维护 编辑:程序博客网 时间:2024/04/30 15:26
1、调用此函数,程序会自动判断文档是否已经打开,若已经打开则把打开的此文档设为活动文档。
CRadPupApp*pApp=(CRadPupApp*)AfxGetApp();pApp->OpenDocumentFile(filepath);//调用此函数,程序会自动判断
2、自己写代码判断
void CRadPupApp::OpenFile(LPCTSTR lpszPathName)//OpenFile为自己写的打开函数{POSITION curTemplatePos = GetFirstDocTemplatePosition();while(curTemplatePos != NULL){CDocTemplate* curTemplate = GetNextDocTemplate(curTemplatePos);POSITION posDoc = curTemplate->GetFirstDocPosition();while (posDoc!= NULL){CRadPupDoc * pDoc = (CRadPupDoc *)curTemplate->GetNextDoc(posDoc);if (DocumentExist(pDoc,lpszPathName))///当文档存在的时候就在当前文档打开{CView * pView = NULL;POSITION pos = pDoc->GetFirstViewPosition();while (pos){pView = pDoc->GetNextView(pos);if (pView->IsKindOf(RUNTIME_CLASS(CRadPupView))){break;}else{pView = NULL;}}if (pView == NULL){return ;}CFrameWnd* pFrame = pView->GetParentFrame();pFrame->ActivateFrame();//关键在这句话return;}}curTemplate->OpenDocumentFile(lpszPathName);return;}}BOOL CRadPupApp::DocumentExist(CRadPupDoc * pDoc, LPCTSTR lpszPathName){if (pDoc == NULL){return FALSE;}CString strTitle = pDoc->GetTitle();CString strFile = lpszPathName;CString strFileTitle = strFile.Right(strFile.GetLength() - strFile.ReverseFind('\\') - 1);if (strTitle == strFileTitle){return TRUE;}return 0;}
注:不管是pApp->OpenDocumentFile(filepath)还是curTemplate->OpenDocumentFile(lpszPathName),最终都会调用Doc类的BOOLCRadPupDoc::OnOpenDocument(LPCTSTRlpszPathName),只要在Doc类写打开代码即可。
- 防止多文档文档重复打开
- vim打开文档和多文档编辑
- MFC多文档默认打开某一个文档
- vim打开文档和多文档编辑
- vim打开文档和多文档编辑
- vim打开文档和多文档编辑
- vim打开文档和多文档编辑
- vim打开文档和多文档编辑
- vim打开文档和多文档编辑
- vim打开文档和多文档编辑
- 防止程序重复打开
- 解决SharePoint2010打开文档需要重复验证登录问题
- word2007文档防止复制
- MFC防止进程重复打开
- 防止C++程序重复打开
- MFC防止进程重复打开
- MFC防止进程重复打开
- MFC 多文档中同时打开多个文档
- Linux下软件包的解压方式大全
- JS函数
- Ios开发知识点小结
- 单片机如何用普通电池供电?
- asp.net中frameset的使用
- 防止多文档文档重复打开
- 复习struts2之访问或添加属性
- 报错:1130-host ... is not allowed to connect to this MySql server
- .ActionContextCleanUp的作用
- 黑马程序员-c#接口和抽象类的区别(非常经典的解说)
- 字符串拷贝和内存拷贝函数
- hlsl初学
- 通过PHP pcntl函数实现多线程功能
- Eclipse项目发布内存溢出问题解决