void CWordPadApp::UpdateRegistry() { USES_CONVERSION; LPOLESTR lpszClassID = NULL; CDocTemplate* pDocTemplate = &DocTemplate; // get registration info from doc template string CString strServerName; CString strLocalServerName; CString strLocalShortName; if (!pDocTemplate->GetDocString(strServerName, CDocTemplate::regFileTypeId) || strServerName.IsEmpty()) { TRACE0("Error: not enough information in DocTemplate to register OLE server.\n"); return; } if (!pDocTemplate->GetDocString(strLocalServerName, CDocTemplate::regFileTypeName)) strLocalServerName = strServerName; // use non-localized name if (!pDocTemplate->GetDocString(strLocalShortName, CDocTemplate::fileNewName)) strLocalShortName = strLocalServerName; // use long name ASSERT(strServerName.Find(' ') == -1); // no spaces allowed ::StringFromCLSID(clsid, &lpszClassID); ASSERT (lpszClassID != NULL); // get path name to server TCHAR szLongPathName[_MAX_PATH]; TCHAR szShortPathName[_MAX_PATH]; ::GetModuleFileName(AfxGetInstanceHandle(), szLongPathName, _MAX_PATH); ::GetShortPathName(szLongPathName, szShortPathName, _MAX_PATH); LPCTSTR rglpszSymbols[NUM_REG_ARGS]; rglpszSymbols[0] = OLE2CT(lpszClassID); rglpszSymbols[1] = strServerName; rglpszSymbols[2] = szShortPathName; rglpszSymbols[3] = strLocalShortName; rglpszSymbols[4] = strLocalServerName; rglpszSymbols[5] = m_pszAppName; // will usually be long, readable name rglpszSymbols[6] = NULL; if (RegisterHelper((LPCTSTR*)rglpszWordPadRegister, rglpszSymbols, FALSE)) RegisterHelper((LPCTSTR*)rglpszWordPadOverwrite, rglpszSymbols, TRUE); // RegisterExt(_T(".txt"), _T("txtfile"), IDS_TEXT_DOC, rglpszSymbols, // (LPCTSTR*)rglpszTxtExtRegister, (LPCTSTR*)rglpszTxtRegister, 3); RegisterExt(_T(".rtf"), _T("rtffile"), IDS_RICHTEXT_DOC, rglpszSymbols, (LPCTSTR*)rglpszRtfExtRegister, (LPCTSTR*)rglpszRtfRegister, 1); RegisterExt(_T(".wri"), _T("wrifile"), IDS_WRITE_DOC, rglpszSymbols, (LPCTSTR*)rglpszWriExtRegister, (LPCTSTR*)rglpszWriRegister, 2); RegisterExt(_T(".doc"), _T("WordPad.Document.1"), IDS_WINWORD6_DOC, rglpszSymbols, (LPCTSTR*)rglpszDocExtRegister, (LPCTSTR*)rglpszDocRegister, 1); // free memory for class ID ASSERT(lpszClassID != NULL); CoTaskMemFree(lpszClassID); }
void CImportExportApp::OnFileOpen() { CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, NULL, NULL ); CString initdir(((OCC_BaseApp*) AfxGetApp())->GetInitDataDir()); initdir += "\\Data"; dlg.m_ofn.lpstrInitialDir = initdir; CString strFilter; CString strDefault; POSITION pos = GetFirstDocTemplatePosition(); CDocTemplate* pTemplate = GetNextDocTemplate(pos); CString strFilterExt, strFilterName; if (pTemplate->GetDocString(strFilterExt, CDocTemplate::filterExt) && !strFilterExt.IsEmpty() && pTemplate->GetDocString(strFilterName, CDocTemplate::filterName) && !strFilterName.IsEmpty()) { // add to filter strFilter += strFilterName; ASSERT(!strFilter.IsEmpty()); // must have a file type name strFilter += (TCHAR)'\0'; // next string please strFilter += (TCHAR)'*'; strFilter += strFilterExt; strFilter += (TCHAR)'\0'; // next string please dlg.m_ofn.nMaxCustFilter++; } // append the "*.*" all files filter CString allFilter; VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER)); strFilter += allFilter; strFilter += (TCHAR)'\0'; // next string please strFilter += _T("*.*"); strFilter += (TCHAR)'\0'; // last string dlg.m_ofn.nMaxCustFilter++; dlg.m_ofn.lpstrFilter = strFilter; if (dlg.DoModal() == IDOK) { AfxGetApp()->OpenDocumentFile(dlg.GetPathName()); } }
void CSaveOptionPage::RegFileType(LPCTSTR pszType) { POSITION posTmpl = AfxGetApp()->GetFirstDocTemplatePosition(); if(posTmpl != NULL) { CDocTemplate* pTemplate = AfxGetApp()->GetNextDocTemplate(posTmpl); CString strFileTypeId; if (pTemplate->GetDocString(strFileTypeId, CDocTemplate::regFileTypeId)) { CString strTemp; LONG lSize = _MAX_PATH * 2; LONG lResult = AfxRegQueryValue(HKEY_CLASSES_ROOT, pszType, strTemp.GetBuffer(lSize), &lSize); strTemp.ReleaseBuffer(); if(strTemp.Compare(strFileTypeId) != 0) { AfxRegSetValue( HKEY_CLASSES_ROOT, pszType, REG_SZ, strFileTypeId, lstrlen(strFileTypeId) * sizeof(TCHAR)); AfxGetApp()->WriteProfileString(_T("Settings"), pszType, strTemp); } } } }
void CInputDoc::OnFileSaveAs() { CDocTemplate* pDT = GetDocTemplate(); CString sFileTypeName; pDT->GetDocString(sFileTypeName, CDocTemplate::regFileTypeName); CString sFilter; pDT-> GetDocString(sFilter, CDocTemplate::filterName); CString sExt;//="txt"; pDT-> GetDocString(sExt, CDocTemplate::filterExt); sFilter += "|*"; sFilter += sExt; sFilter+= "||"; CFileDialog dlg( FALSE, sExt, this->GetPathName(), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, sFilter, NULL ); //CString sPrompt("Save As"); //char* lpszPrompt = new char[sPrompt.GetLength()+1]; //strcpy(lpszPrompt, sPrompt); dlg.m_ofn.lpstrTitle = "Save As";//lpszPrompt; if(IDOK == dlg.DoModal()) { this->SetPathName(dlg.GetPathName()); OnSaveDocument(dlg.GetPathName()); } }
BOOL CDocument::DoSave(LPCTSTR lpszPathName, BOOL bReplace) // Save the document data to a file // lpszPathName = path name where to save document file // if lpszPathName is NULL then the user will be prompted (SaveAs) // note: lpszPathName can be different than 'm_strPathName' // if 'bReplace' is TRUE will change file name if successful (SaveAs) // if 'bReplace' is FALSE will not change path name (SaveCopyAs) { CString newName = lpszPathName; if (newName.IsEmpty()) { CDocTemplate* pTemplate = GetDocTemplate(); ASSERT(pTemplate != NULL); newName = m_strPathName; if (bReplace && newName.IsEmpty()) { newName = m_strTitle; // check for dubious filename int iBad = newName.FindOneOf(_T(":/\\")); if (iBad != -1) newName.ReleaseBuffer(iBad); // append the default suffix if there is one CString strExt; if (pTemplate->GetDocString(strExt, CDocTemplate::filterExt) && !strExt.IsEmpty()) { ASSERT(strExt[0] == '.'); int iStart = 0; newName += strExt.Tokenize(_T(";"), iStart); } } if (!AfxGetApp()->DoPromptFileName(newName, bReplace ? AFX_IDS_SAVEFILE : AFX_IDS_SAVEFILECOPY, OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FALSE, pTemplate)) return FALSE; // don't even attempt to save } CWaitCursor wait; if (!OnSaveDocument(newName)) { if (lpszPathName == NULL) { // be sure to delete the file TRY { CFile::Remove(newName); } CATCH_ALL(e) { TRACE(traceAppMsg, 0, "Warning: failed to delete file after failed SaveAs.\n"); DELETE_EXCEPTION(e); } END_CATCH_ALL } return FALSE; }
BOOL CKSFileDialog::DoSave(LPCTSTR lpszPathName, BOOL bReplace) { if (m_pDoc==NULL){ASSERT (FALSE);return FALSE;} CString newName = lpszPathName; if (newName.IsEmpty()) { CDocTemplate* pTemplate = m_pDoc->GetDocTemplate(); ASSERT(pTemplate != NULL); newName = m_pDoc->GetPathName(); if (bReplace && newName.IsEmpty()) { newName = m_pDoc->GetTitle(); // check for dubious filename int iBad = newName.FindOneOf(_T(" #%;/\\")); if (iBad != -1) newName.ReleaseBuffer(iBad); // append the default suffix if there is one CString strExt; if (pTemplate->GetDocString(strExt, CDocTemplate::filterExt) && !strExt.IsEmpty()) { ASSERT(strExt[0] == '.'); newName += strExt; } } if (DoPromptFileName(newName,bReplace ? AFX_IDS_SAVEFILE : AFX_IDS_SAVEFILECOPY, OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FALSE, pTemplate)) return FALSE; // don't even attempt to save } CWaitCursor wait; if (!m_pDoc->OnSaveDocument(newName)) { if (lpszPathName == NULL) { // be sure to delete the file try { CFile::Remove(newName); } catch( CException * e) { TRACE0("Warning: failed to delete file after failed SaveAs.\n"); do { e->Delete(); } while (0); } } return FALSE; } // reset the title and change the document name if (bReplace) m_pDoc->SetPathName(newName); return TRUE; // success }
// modified from doccore.cpp BOOL CBonfireDoc::DoSave(LPCTSTR lpszPathName, BOOL bReplace) // Save the document data to a file // lpszPathName = path name where to save document file // if lpszPathName is NULL then the user will be prompted (SaveAs) // note: lpszPathName can be different than 'm_strPathName' // if 'bReplace' is TRUE will change file name if successful (SaveAs) // if 'bReplace' is FALSE will not change path name (SaveCopyAs) { CString newName = lpszPathName; if (newName.IsEmpty()) { CDocTemplate* pTemplate = GetDocTemplate(); ASSERT(pTemplate != NULL); newName = m_strPathName; if (bReplace && newName.IsEmpty()) { newName = m_strTitle; // check for dubious filename int iBad = newName.FindOneOf(_T(" #%;/\\")); if (iBad != -1) newName.ReleaseBuffer(iBad); // append the default suffix if there is one CString strExt; if (pTemplate->GetDocString(strExt, CDocTemplate::filterExt) && !strExt.IsEmpty()) { ASSERT(strExt[0] == '.'); newName += strExt; } } if (SaveFileDialog(AfxGetMainWnd(),newName,newName,NULL, GetFileFilter(FILTER_FILES),6,GetDefExt(FILTER_FILES)) <= 0) return FALSE; // don't even attempt to save } CWaitCursor wait; if (!OnSaveDocument(newName)) { if (lpszPathName == NULL) { // be sure to delete the file TRY { CFile::Remove(newName); } CATCH_ALL(e) { TRACE0("Warning: failed to delete file after failed SaveAs.\n"); do { e->Delete(); } while (0); //DELETE_EXCEPTION(e); } END_CATCH_ALL } return FALSE; }
//---------------------------------------------------------------------------- CDocTemplate* GetTemplate( CString Name ) { // получение template документа статьи POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition(); CDocTemplate* tmpl; CString S; do { tmpl = AfxGetApp()->GetNextDocTemplate (pos); tmpl->GetDocString (S, CDocTemplate::regFileTypeId); } while ((tmpl != 0) && (S != Name)); ASSERT (tmpl); return tmpl; }
BOOL CSaveOptionPage::HasRegistered(LPCTSTR pszType) { POSITION posTmpl = AfxGetApp()->GetFirstDocTemplatePosition(); if(posTmpl != NULL) { CDocTemplate* pTemplate = AfxGetApp()->GetNextDocTemplate(posTmpl); CString strFileTypeId; if (pTemplate->GetDocString(strFileTypeId, CDocTemplate::regFileTypeId)) { CString strTemp; LONG lSize = _MAX_PATH * 2; LONG lResult = AfxRegQueryValue(HKEY_CLASSES_ROOT, pszType, strTemp.GetBuffer(lSize), &lSize); strTemp.ReleaseBuffer(); return (strTemp.Compare(strFileTypeId) == 0); } } return FALSE; }
void CSaveOptionPage::UnRegFileType(LPCTSTR pszType) { POSITION posTmpl = AfxGetApp()->GetFirstDocTemplatePosition(); if(posTmpl != NULL) { CDocTemplate* pTemplate = AfxGetApp()->GetNextDocTemplate(posTmpl); CString strFileTypeId; if (pTemplate->GetDocString(strFileTypeId, CDocTemplate::regFileTypeId)) { CString strTemp = AfxGetApp()->GetProfileString(_T("Settings"), pszType); if(strTemp.Compare(strFileTypeId) != 0) { AfxRegSetValue( HKEY_CLASSES_ROOT, pszType, REG_SZ, strTemp, lstrlen(strTemp) * sizeof(TCHAR)); } } } }
BOOL CEtsEodManagerDoc::DoSaveAs() { CDocTemplate* pTemplate = GetDocTemplate(); ASSERT(pTemplate != NULL); CString strNewName; if(m_bIsCurrent) { strNewName = CModuleVersionEx::GetFilePath(m_strPathName); COleDateTime dtToday(COleDateTime::GetCurrentTime()); strNewName += _T("EodReport_"); strNewName += dtToday.Format(_T("%Y%m%d")); CString strExt; pTemplate->GetDocString(strExt, CDocTemplate::filterExt); strNewName += strExt; } else strNewName = m_strPathName; if(!AfxGetApp()->DoPromptFileName(strNewName, AFX_IDS_SAVEFILECOPY, OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FALSE, pTemplate)) return FALSE; // don't even attempt to save strNewName.Trim(); if(_IsCurrent(strNewName)) { AfxGetMainWnd()->MessageBox(_T("Can't save opened report to current report file."), NULL, MB_ICONSTOP); return FALSE; } CWaitCursor wait; if(!OnSaveDocument(strNewName)) return FALSE; return TRUE; // success }
BOOL DocRoot::OnNewDocument() { if (!CDocument::OnNewDocument()) return False; if (gs_Exec.Busy()) { LogError("SysCAD", 0, "Must not be running"); return False; } if (gs_pPrj->pPrjDoc==NULL && !gs_pPrj->bDoingLoad)//sPrjFile.Length() > 0) { LogError("SysCAD", 0, "A project must be opened or a new project created."); return False; } /*CString s = GetTitle(); Strng T = PrjFiles(); T += (const char*)s; GetDocTemplate()->GetDocString(s, CDocTemplate::filterExt); T += (const char*)s; SetPathName(T()); Strng T1,T2; T1.FnName(T()); T2.FnExt(T()); T = T1; T += T2; SetTitle(T());*/ gs_pCmd->ProcessAStr("\x1b"); //Ensure there are no half complete commands gs_pCmd->ProcessAStr("\x1b"); //Ensure there are no half complete commands, call more than once! CDocTemplate* pTemplate = GetDocTemplate(); CString s; bool GrfChangeName = false; if (1) { pTemplate->GetDocString(s, CDocTemplate::filterExt); if (s==".scg") { s = "05_Flowsheet.scg"; SetTitle(s); //this may alter title; GrfChangeName = true; //ChooseTitle(this, s); //SetTitle(s); } } if (!GrfChangeName) { s = GetTitle(); Strng T = (const char*)s; pTemplate->GetDocString(s, CDocTemplate::filterExt); T += (const char*)s; SetTitle(T()); //this may alter title; } Strng PathN = PrjFiles(); s = GetTitle(); PathN += (const char*)s; SetPathName(PathN()); //do this AFTER SetTitle OnAttachDoc(); OnActivate(True); //gs_pCmd->SetDocForCmds(this); //gs_pCmd->ProcessAStr("CLEAR DOCUMENT \r"); //gs_pCmd->SetDocForCmds(NULL); bIsOpen = True; return True; }
//NBNB: KGA: I am overiding this undocumented function; // 3 May 1996 from doccore.cpp; check with future versions of MFC // Last checked Feb 1997 with MSVC++/MFC version 4.2 BOOL DocRoot::DoSave(LPCTSTR lpszPathName, BOOL bReplace) // Save the document data to a file // lpszPathName = path name where to save document file // if lpszPathName is NULL then the user will be prompted (SaveAs) // note: lpszPathName can be different than 'm_strPathName' // if 'bReplace' is TRUE will change file name if successful (SaveAs) // if 'bReplace' is FALSE will not change path name (SaveCopyAs) { CString newName = lpszPathName; if (newName.IsEmpty()) { CDocTemplate* pTemplate = GetDocTemplate(); ASSERT(pTemplate != NULL); newName = m_strPathName; if (bReplace && newName.IsEmpty()) { newName = m_strTitle; #ifndef _MAC // check for dubious filename int iBad = newName.FindOneOf(_T(" #%;/\\")); #else int iBad = newName.FindOneOf(_T(":")); #endif if (iBad != -1) newName.ReleaseBuffer(iBad); #ifndef _MAC // append the default suffix if there is one CString strExt; if (pTemplate->GetDocString(strExt, CDocTemplate::filterExt) && !strExt.IsEmpty()) { ASSERT(strExt[0] == '.'); newName += strExt; } #endif } if (!ScdApp()->DoPromptFileName(newName, bReplace ? AFX_IDS_SAVEFILE : AFX_IDS_SAVEFILECOPY, OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FALSE, pTemplate, false)) return FALSE; // don't even attempt to save } CWaitCursor wait; if (!OnSaveDocument(newName)) { /* KGA, DO NOT DELETE !!! if (0 lpszPathName == NULL) { // be sure to delete the file TRY { CFile::Remove(newName); } CATCH_ALL(e) { TRACE0("Warning: failed to delete file after failed SaveAs.\n"); DELETE_EXCEPTION(e); } END_CATCH_ALL }*/ return FALSE; } // reset the title and change the document name if (bReplace) SetPathName(newName); return TRUE; // success }
void DocRoot::SetTitle(LPCTSTR lpszTitle) { CString s(lpszTitle); CDocTemplate* pTempl = GetDocTemplate(); if (pTempl) { CString se; pTempl->GetDocString(se, CDocTemplate::filterExt); bool Grf = (se==".scg"); int No = 5; flag Found = True; while (Found) { Found = False; POSITION Pos = pTempl->GetFirstDocPosition(); while (Pos && !Found) { CDocument* pDoc = pTempl->GetNextDoc(Pos); if (pDoc!=this) { CString Title = pDoc->GetTitle(); if (Title.GetLength()==s.GetLength() && _stricmp((const char*)s, (const char*)Title)==0) Found = True; } } if (Found) { CString Ext = ""; int DotPos = s.ReverseFind('.'); if (DotPos>=0) { Ext = s.Mid(DotPos, 256); s = s.Left(DotPos); } if (Grf) { s.Format("%02d%s", No, "_Flowsheet"); No += 5; } else { int _Pos = s.ReverseFind('_'); if (_Pos>=0) { CString ss = s.Mid(_Pos+1, 256); s = s.Left(_Pos+1); if (ss.GetLength()>0) { char Buff[32]; sprintf(Buff, "%d", atoi((const char*)ss) + 1); s += Buff; } else s += "1"; } else s += "_1"; } s += Ext; } } } CDocument::SetTitle((const char*)s); }
CBCGPFileDialog::CBCGPFileDialog (LPCTSTR lpszCaption, BOOL bNewPage, LPCTSTR lpszDefExt, LPCTSTR lpszFileName, DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) : CFileDialog (TRUE /*bOpenFileDialog*/, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd #if _MSC_VER >= 1500 ,0 , FALSE // Not Vista-style dialog #endif ), m_pImagesNew (NULL), m_bNewPage (bNewPage), m_strCaption (lpszCaption), m_hIconBig (NULL), m_hIconSmall (NULL), m_iLogoAreaHeight (0), m_iExtraWidth (0), m_iExtraHeight (0) { m_iNewItemIndex = -1; m_pBmpLogo = NULL; CDocManager* pDocManager = AfxGetApp ()->m_pDocManager; if (pDocManager != NULL && lpszFilter == NULL) { CString strDefault; BOOL bFirst = TRUE; m_strFilter.Empty(); for (POSITION pos = pDocManager->GetFirstDocTemplatePosition (); pos != NULL;) { CDocTemplate* pTemplate = pDocManager->GetNextDocTemplate (pos); ASSERT_VALID (pTemplate); CString strFilterExt, strFilterName; if (pTemplate->GetDocString (strFilterExt, CDocTemplate::filterExt) && !strFilterExt.IsEmpty() && pTemplate->GetDocString(strFilterName, CDocTemplate::filterName) && !strFilterName.IsEmpty()) { #if _MSC_VER >= 1300 int iStart = 0; m_strFilter += strFilterName; m_strFilter += (TCHAR)'\0'; do { CString strExtension = strFilterExt.Tokenize( _T( ";" ), iStart ); if (iStart != -1) { // a file based document template - add to filter list // If you hit the following ASSERT, your document template // string is formatted incorrectly. The section of your // document template string that specifies the allowable file // extensions should be formatted as follows: // .<ext1>;.<ext2>;.<ext3> // Extensions may contain wildcards (e.g. '?', '*'), but must // begin with a '.' and be separated from one another by a ';'. // Example: // .jpg;.jpeg ASSERT(strExtension[0] == '.'); if ( strDefault.IsEmpty() ) { // set the default extension strDefault = strExtension.Mid( 1 ); // skip the '.' m_ofn.lpstrDefExt = const_cast< LPTSTR >((LPCTSTR)strDefault); m_ofn.nFilterIndex = m_ofn.nMaxCustFilter + 1; // 1 based number } m_strFilter += (TCHAR)'*'; m_strFilter += strExtension; m_strFilter += (TCHAR)';'; // Always append a ';'. The last ';' will get replaced with a '\0' later. } } while (iStart != -1); m_strFilter.SetAt( m_strFilter.GetLength()-1, '\0' );; // Replace the last ';' with a '\0' m_ofn.nMaxCustFilter++; #else // a file based document template - add to filter list ASSERT(strFilterExt[0] == '.'); if (bFirst) { strDefault = ((LPCTSTR)strFilterExt) + 1; // skip the '.' m_ofn.lpstrDefExt = strDefault; m_ofn.nFilterIndex = m_ofn.nMaxCustFilter + 1; // 1 based number } // add to filter m_strFilter += strFilterName; ASSERT(!m_strFilter.IsEmpty()); // must have a file type name m_strFilter += (TCHAR)'\0'; // next string please m_strFilter += (TCHAR)'*'; m_strFilter += strFilterExt; m_strFilter += (TCHAR)'\0'; // next string please m_ofn.nMaxCustFilter++; #endif } bFirst = FALSE; } CString allFilter; VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER)); m_strFilter += allFilter; m_strFilter += (TCHAR)'\0'; // next string please m_strFilter += _T("*.*"); m_strFilter += (TCHAR)'\0'; // last string m_ofn.nMaxCustFilter++; m_ofn.lpstrFilter = m_strFilter; } }
void CDocManager::RegisterShellFileTypes( BOOL bCompat ) /******************************************************/ { POSITION position = m_templateList.GetHeadPosition(); int nIcon = 0; while( position != NULL ) { CDocTemplate *pTemplate = (CDocTemplate *)m_templateList.GetNext( position ); ASSERT( pTemplate != NULL ); nIcon++; CString strExtension; CString strProgId; CString strFriendlyName; if( !pTemplate->GetDocString( strExtension, CDocTemplate::filterExt ) ) { continue; } if( !pTemplate->GetDocString( strProgId, CDocTemplate::regFileTypeId ) ) { continue; } if( !pTemplate->GetDocString( strFriendlyName, CDocTemplate::regFileTypeName ) ) { continue; } HKEY hKey = NULL; if( ::RegCreateKey( HKEY_CLASSES_ROOT, strExtension, &hKey ) != ERROR_SUCCESS ) { continue; } ::RegSetValue( hKey, NULL, REG_SZ, strProgId, strProgId.GetLength() ); ::RegCloseKey( hKey ); if( ::RegCreateKey( HKEY_CLASSES_ROOT, strProgId, &hKey ) != ERROR_SUCCESS ) { continue; } ::RegSetValue( hKey, NULL, REG_SZ, strFriendlyName, strFriendlyName.GetLength() ); ::RegCloseKey( hKey ); TCHAR szExeName[256]; ::GetModuleFileName( AfxGetInstanceHandle(), szExeName, 255 ); CString strFmt1; CString strFmt2; CString strTemp; // If it's an MDI application, register it for DDE open. BOOL bDDE = !pTemplate->GetDocString( strTemp, CDocTemplate::windowTitle ) || strTemp.IsEmpty(); strFmt1.Format( _T("%s\\shell\\open\\command"), (LPCTSTR)strProgId ); strFmt2 = szExeName; if( bDDE ) { strFmt2 += _T(" /dde"); } if( ::RegCreateKey( HKEY_CLASSES_ROOT, strFmt1, &hKey ) != ERROR_SUCCESS ) { continue; } ::RegSetValue( hKey, NULL, REG_SZ, strFmt2, strFmt2.GetLength() ); ::RegCloseKey( hKey ); if( bDDE ) { strFmt1.Format( _T("%s\\shell\\open\\ddeexec"), (LPCTSTR)strProgId ); strFmt2 = _T("[open(\"%1\")]"); if( ::RegCreateKey( HKEY_CLASSES_ROOT, strFmt1, &hKey ) != ERROR_SUCCESS ) { continue; } ::RegSetValue( hKey, NULL, REG_SZ, strFmt2, strFmt2.GetLength() ); } strFmt1.Format( _T("%s\\DefaultIcon"), (LPCTSTR)strProgId ); strFmt2.Format( _T("%s,%d"), szExeName, nIcon ); if( ::RegCreateKey( HKEY_CLASSES_ROOT, strFmt1, &hKey ) != ERROR_SUCCESS ) { continue; } ::RegSetValue( hKey, NULL, REG_SZ, strFmt2, strFmt2.GetLength() ); ::RegCloseKey( hKey ); if( bCompat ) { strFmt1.Format( _T("%s\\shell\\print\\command"), (LPCTSTR)strProgId ); strFmt2.Format( _T("%s /p"), szExeName ); if( ::RegCreateKey( HKEY_CLASSES_ROOT, strFmt1, &hKey ) != ERROR_SUCCESS ) { continue; } ::RegSetValue( hKey, NULL, REG_SZ, strFmt2, strFmt2.GetLength() ); ::RegCloseKey( hKey ); strFmt1.Format( _T("%s\\shell\\printto\\command"), (LPCTSTR)strProgId ); strFmt2.Format( _T("%s /pt"), szExeName ); if( ::RegCreateKey( HKEY_CLASSES_ROOT, strFmt1, &hKey ) != ERROR_SUCCESS ) { continue; } ::RegSetValue( hKey, NULL, REG_SZ, strFmt2, strFmt2.GetLength() ); ::RegCloseKey( hKey ); } } }
BOOL CMyglApp::InitInstance() { #ifdef _KATMAI if (!KatmaiInit()) { #if 0 ::MessageBox(NULL, "This version requires an Intel Pentium III processor \n Program will be terminated" , _PROGRAM " System Message" , MB_OK | MB_ICONINFORMATION | MB_SYSTEMMODAL | MB_TOPMOST); //AfxMessageBox("This version requires an Intel Katmai processor \n Program will be terminated "); return FALSE; #endif } #endif /* // Initialize COM Library (for RSX) */ m_coResult = CoInitialize(NULL); #ifdef _COM // Initialize the ATL Module _Module.Init(ObjectMap,m_hInstance); #endif // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. m_ChoosePixelFormat = 0; m_ActiveView = 0; #ifndef _NSPLUGIN Enable3dControls(); // VC 2.0 #endif //SetDialogBkColor(); // set dialog background color to gray LoadStdProfileSettings(); // Load standard INI file options (including MRU) GReporter::SetCurrent(new GReporter); // make sure Gv VRML database is init !!! GvDB::init(); // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CDocTemplate *pTemplate; AddDocTemplate(pTemplate=new CSingleDocTemplate(IDR_MAINFRAME, RUNTIME_CLASS(CMyglDoc), RUNTIME_CLASS(CMainFrame), // main SDI frame window RUNTIME_CLASS(CMyglView))); // command line processing here { CString fileArg; // there is a utility function if (m_lpCmdLine[0] != '\0') { char *p,*p1; p=m_lpCmdLine; while (*p) { while (isspace(*p)) p++; if ((*p == '-') || (*p == '/')) { // Option start p++; switch (*p++) { case 'X' : case 'x' : m_ChoosePixelFormat = 1; break; default : Reporter.Error("Unknown commandline option '%c' in %s",*p,m_lpCmdLine); break; } } else { // file argument #if 0 if (fileArg.GetLength()>0) { Reporter.Error("too many commandline arguments in %s",m_lpCmdLine); while (!isspace(*p)) { if (!*p) break;p++;} } else while (!isspace(*p)) { if (!*p) break; fileArg += *p; p++; } #else if (*p == '"') { p++; while (*p != '"') { if (!*p) break; fileArg += *p; p++; } if (*p == '"') p++; while (isspace(*p)) p++; break; // to do: rest of commandline } else fileArg = p; break; #endif } } } if (fileArg.GetLength() > 0) OpenDocumentFile(fileArg); // directly load a file else // create a new (empty) document OnFileNew(); } RegisterShellFileTypes(); // register all extensions { CString strFilterExt,strFileTypeName; //strFileTypeId if (pTemplate->GetDocString(strFileTypeId, CDocTemplate::regFileTypeId) && !strFileTypeId.IsEmpty()) { // enough info to register it if (!pTemplate->GetDocString(strFileTypeName, CDocTemplate::regFileTypeName)) strFileTypeName = strFileTypeId; // use id name } } // for all extensions // enable file manager drag/drop and DDE Execute open m_pMainWnd->DragAcceptFiles(); EnableShellOpen(); // VC 2.0 // The main window has been initialized, so show and update it. //pMainFrame->ShowWindow(m_nCmdShow); //pMainFrame->UpdateWindow(); #ifdef _EVALUATION // increment runcount int runCount = GetProfileInt("GLView","RunCount",0); runCount++; WriteProfileInt("GLView","RunCount",runCount); #endif int version = GetProfileInt("GLView","Version",0); if (version == 0 || version<_VERSION_INT) { version = _VERSION_INT; WriteProfileInt("GLView","Version",version); // Date WriteProfileInt("GLView","Version",version); // increment run-count } return TRUE; }
void CWinAppSingle::RegisterShellFileTypesEx( BOOL bCompat /*FALSE*/, BOOL bRegister /*TRUE*/ ) { // Register all application document types: if( bRegister == TRUE ) CWinApp::RegisterShellFileTypes( bCompat ); // Now register SDI document dde open. // Loop through the document templates: POSITION pos = GetFirstDocTemplatePosition(); while( pos != NULL ) { CString strFileTypeId( _T("") ); CDocTemplate* pTemplate = GetNextDocTemplate( pos ); if( pTemplate->GetDocString( strFileTypeId, CDocTemplate::regFileTypeId ) && !strFileTypeId.IsEmpty() ) { // CDocTemplate::windowTitle is present only in the document template // for SDI applications. So, we detected SDI application and should // overregister shell file types : CString strTemp( _T("") ); if ( pTemplate->GetDocString( strTemp, CDocTemplate::windowTitle ) && !strTemp.IsEmpty() ) { // path\shell\open\ddeexec = [open("%1")] strTemp.Format( _T( "%s\\shell\\open\\%s" ), (LPCTSTR)strFileTypeId, _T( "ddeexec" ) ); #if ( _MFC_VER >= 0x0700 ) CRegKey reg( HKEY_CLASSES_ROOT ); #else CRegKey reg; reg.Attach( HKEY_CLASSES_ROOT ); #endif if( bRegister ) { if( reg.SetKeyValue( strTemp, _T( "[open(\"%1\")]" ) ) == ERROR_SUCCESS ) { strTemp += _T( "\\Application" ); OSVERSIONINFO osvi = { 0 }; osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); ::GetVersionEx( & osvi ); if( !( osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion == 5 && osvi.dwMinorVersion >= 1 ) ) { reg.SetKeyValue( strTemp, AfxGetAppName() ); } else reg.DeleteSubKey( strTemp ); } } else // Unregister 'ddeexec' registry entry: reg.RecurseDeleteKey( strTemp ); #if ( _MFC_VER >= 0x0700 ) reg.Flush(); #else ::RegFlushKey( reg ); #endif reg.Close(); } } } // Unregister all application document types: if( bRegister == FALSE ) CWinApp::UnregisterShellFileTypes(); }
void CDocument::OnFileSendMail() { ASSERT_VALID(this); ASSERT(_afxIsMailAvail); // update handler always gets called first CWaitCursor wait; _AFX_MAIL_STATE* pMailState = _afxMailState; if (pMailState->m_hInstMail == NULL) pMailState->m_hInstMail = ::LoadLibraryA("MAPI32.DLL"); if (pMailState->m_hInstMail == NULL) { AfxMessageBox(AFX_IDP_FAILED_MAPI_LOAD); return; } ASSERT(pMailState->m_hInstMail != NULL); ULONG (PASCAL *lpfnSendMail)(ULONG, ULONG, MapiMessage*, FLAGS, ULONG); (FARPROC&)lpfnSendMail = GetProcAddress(pMailState->m_hInstMail, "MAPISendMail"); if (lpfnSendMail == NULL) { AfxMessageBox(AFX_IDP_INVALID_MAPI_DLL); return; } ASSERT(lpfnSendMail != NULL); TCHAR szTempName[_MAX_PATH]; TCHAR szPath[_MAX_PATH]; BOOL bRemoveTemp = FALSE; if (m_strPathName.IsEmpty() || IsModified()) { // save to temporary path VERIFY(GetTempPath(_countof(szPath), szPath) != 0); VERIFY(GetTempFileName(szPath, _T("afx"), 0, szTempName) != 0); // save it, but remember original modified flag BOOL bModified = IsModified(); BOOL bResult = DoSave(szTempName, FALSE); SetModifiedFlag(bModified); if (!bResult) { TRACE0("Warning: file save failed during File.Send Mail.\n"); return; } bRemoveTemp = TRUE; } else { // use actual file since it isn't modified lstrcpyn(szTempName, m_strPathName, _countof(szTempName)); } #ifdef _UNICODE char szTempNameA[_MAX_PATH]; _wcstombsz(szTempNameA, szTempName, _countof(szTempNameA)); #endif // build an appropriate title for the attachment TCHAR szTitle[_MAX_PATH]; if (!m_strPathName.IsEmpty()) AfxGetFileName(m_strPathName, szTitle, _countof(szTitle)); else { lstrcpyn(szTitle, m_strTitle, _countof(szTitle)); if (m_strTitle.Find('.') == -1) // no extension { // append the default suffix if there is one CString strExt; CDocTemplate* pTemplate = GetDocTemplate(); if (pTemplate != NULL && pTemplate->GetDocString(strExt, CDocTemplate::filterExt)) { lstrcat(szTitle, strExt); } } } #ifdef _UNICODE char szTitleA[_MAX_PATH]; _wcstombsz(szTitleA, szTitle, _countof(szTitleA)); #endif // prepare the file description (for the attachment) MapiFileDesc fileDesc; memset(&fileDesc, 0, sizeof(fileDesc)); fileDesc.nPosition = (ULONG)-1; #ifdef _UNICODE fileDesc.lpszPathName = szTempNameA; fileDesc.lpszFileName = szTitleA; #else fileDesc.lpszPathName = szTempName; fileDesc.lpszFileName = szTitle; #endif // prepare the message (empty with 1 attachment) MapiMessage message; memset(&message, 0, sizeof(message)); message.nFileCount = 1; message.lpFiles = &fileDesc; // prepare for modal dialog box AfxGetApp()->EnableModeless(FALSE); HWND hWndTop; CWnd* pParentWnd = CWnd::GetSafeOwner(NULL, &hWndTop); // some extra precautions are required to use MAPISendMail as it // tends to enable the parent window in between dialogs (after // the login dialog, but before the send note dialog). pParentWnd->SetCapture(); ::SetFocus(NULL); pParentWnd->m_nFlags |= WF_STAYDISABLED; int nError = lpfnSendMail(0, (ULONG)pParentWnd->GetSafeHwnd(), &message, MAPI_LOGON_UI|MAPI_DIALOG, 0); // after returning from the MAPISendMail call, the window must // be re-enabled and focus returned to the frame to undo the workaround // done before the MAPI call. ::ReleaseCapture(); pParentWnd->m_nFlags &= ~WF_STAYDISABLED; pParentWnd->EnableWindow(TRUE); ::SetActiveWindow(NULL); pParentWnd->SetActiveWindow(); pParentWnd->SetFocus(); if (hWndTop != NULL) ::EnableWindow(hWndTop, TRUE); AfxGetApp()->EnableModeless(TRUE); if (nError != SUCCESS_SUCCESS && nError != MAPI_USER_ABORT && nError != MAPI_E_LOGIN_FAILURE) { AfxMessageBox(AFX_IDP_FAILED_MAPI_SEND); } // remove temporary file, if temporary file was used if (bRemoveTemp) CFile::Remove(szTempName); }