/******************************************************************************************* > BOOL BitmapPreviewData::GenerateHTMLStub(BrowserPreviewOptions BrowserOptions) Author: Stefan_Stoykov (Xara Group Ltd) <*****@*****.**> Created: 24/6/97 Inputs: BrowserOptions - the options for generating the html page Purpose: Generate a html file which includes our bitmap, together with some other optional stuff. Used for browser preview. *******************************************************************************************/ BOOL BitmapPreviewData::GenerateHTMLStub(BrowserPreviewOptions BrowserOptions) { PORTNOTE("other","Removed _R(IDD_TIMAPOPTIONS) - isn't wanted yet") #ifndef EXCLUDE_FROM_XARALX // sanity checks // check for export options ERROR3IF(m_pOptions == NULL, "BitmapPreviewData::GenerateHTMLStub - need export options"); if (m_pOptions == NULL) // we need export options return FALSE; // get the path for the exported bitmap from the options PathName TempPath = m_pOptions->GetPathName(); // check for exported bitmap ERROR3IF((m_pOptions->HasTempFile() == FALSE) || (TempPath.IsValid() == FALSE), "BitmapPreviewData::GenerateHTMLStub - need exported bitmap"); if ((m_pOptions->HasTempFile() == FALSE) || (TempPath.IsValid() == FALSE)) return FALSE; // delete the previous temp file, if any if (m_pTempHTMLPath != NULL) FileUtil::DeleteFile(m_pTempHTMLPath); else m_pTempHTMLPath = new PathName; // safety check if (m_pTempHTMLPath == NULL) return FALSE; // create a new temp file if (FileUtil::GetTemporaryPathName( _T("htm"),m_pTempHTMLPath) == FALSE) { delete m_pTempHTMLPath; m_pTempHTMLPath = NULL; return FALSE; } // start creating the html page // create a disk file CCDiskFile TempDiskFile(1024, FALSE, TRUE); // get path name to server, so we can find the logo bitmaps CString str; AfxGetModuleShortFileName(AfxGetInstanceHandle(), str); String_256 strPathName(str.GetBuffer(0)); // create a path name object from the program name PathName ProgramPath(strPathName); try { // open it for reading if (!TempDiskFile.open(*m_pTempHTMLPath, ios::out)) return FALSE; // output header String_256 s(_R(IDS_HTML_HEAD)); TempDiskFile.write(s); // set the background attributes switch (BrowserOptions.m_Background) { case BROWSER_BGR_DOC: { // set the background from the document page if (!SetBackgroundFromPage(TempDiskFile, BrowserOptions.m_pSpread)) ERROR3("Setting the html background from the document page failed\n"); } break; case BROWSER_BGR_CHECKER: { // display the checkered bitmap as background // get the checkered bitmap name String_256 Checker(_R(IDS_HTML_CHECKER)); // set it in the path ProgramPath.SetFileNameAndType(Checker); // set the checkered bitmap as background image s.MakeMsg(_R(IDS_CHECK_BACK), (TCHAR *)ProgramPath.GetWebAddress()); TempDiskFile.write(s); } break; case BROWSER_BGR_BITMAP: { // set our bitmap as background image s.MakeMsg(_R(IDS_BITMAPED_BACKGROUND), (TCHAR *)TempPath.GetWebAddress()); TempDiskFile.write(s); } break; case BROWSER_BGR_NONE: { String_256 background(_R(IDS_PLAIN_BACKGROUND)); TempDiskFile.write(background); } break; default: ERROR3("Unknown type of BrowserOptions.m_Background"); break; } // end of switch(BrowserOptions.m_Background) block // Get a pointer to the actual bitmap so that we can get some details from it. // OILBitmap *pOilBitmap = m_pBitmap->ActualBitmap; // ERROR3IF(pOilBitmap == NULL,"BitmapPreviewData::GenerateBitmapInfoStrings NULL oil bitmap pointer"); // Get the details from the specified bitmap // BitmapInfo BmInfo; // pOilBitmap->GetInfo(&BmInfo); // output our bitmap, but only if it wasn't already set as background String_256 s2(_R(IDS_PAGE_TITLE)); TempDiskFile.write(s2); if (BrowserOptions.m_Background != BROWSER_BGR_BITMAP) { // output the bitmap if (m_pOptions->GetFilterType() == MAKE_BITMAP_FILTER) { // GIF animation s.MakeMsg(_R(IDS_DISPLAY_PIC), (const TCHAR *)TempPath.GetFileName()); } else { if( m_pOptions->GetFilterNameStrID() == _R(IDN_FILTERNAME_GIF) || m_pOptions->GetFilterNameStrID() == _R(IDS_JPG_EXP_FILTERNAME) || m_pOptions->GetFilterNameStrID() == _R(IDT_FILTERNAME_BMP) ) { s.MakeMsg(_R(IDS_DISPLAY_BMP), (const TCHAR *)TempPath.GetFileName()); } else if( m_pOptions->GetFilterNameStrID() == _R(IDS_FILTERNAME_PNG) ) s.MakeMsg(_R(IDS_DISPLAY_PNG), (const TCHAR *)TempPath.GetFileName()); } TempDiskFile.write(s); } else { s.MakeMsg(_R(IDS_EMPTY_BOX)); TempDiskFile.write(s); } switch (m_pOptions->GetFilterNameStrID()) { case _R(IDT_FILTERNAME_BMP): s2.MakeMsg(_R(IDS_BMP_MESSAGE)); s.MakeMsg(_R(IDS_WARNING_BOX), (TCHAR *)s2); TempDiskFile.write(s); break; case _R(IDS_FILTERNAME_PNG): s2.MakeMsg(_R(IDS_PNG_MESSAGE)); s.MakeMsg(_R(IDS_WARNING_BOX), (TCHAR *)s2); TempDiskFile.write(s); break; } // end of switch(m_pOptions->GetFilterNameStrID()) s.MakeMsg(_R(IDS_DETAILS_BUILD)); TempDiskFile.write(s); // output the bitmap info, if requested if (BrowserOptions.m_bInfo != FALSE) { String_64 ImageSize; String_64 FileSize; BOOL m_bTransparent = FALSE; INT32 count; count=0; // generate the info strings if (m_pOptions->GetFilterType() == MAKE_BITMAP_FILTER) { // This is actually the export animated GIF using the frame gallery system MakeBitmapExportOptions* pMkBOptions = (MakeBitmapExportOptions*)m_pOptions; ERROR3IF(!pMkBOptions->IS_KIND_OF(MakeBitmapExportOptions), "pMkBOptions isn't"); PALETTE Palette = PAL_OPTIMISED; DITHER DitherType; UINT32 colDepth; String_64 sPalette; String_64 Dither; UINT32 NoOfColours; NoOfColours=m_pOptions->GetNumColsInPalette(); // Palette = pMkBOptions->GetPalette(); DitherType = pMkBOptions->GetDither(); colDepth = pMkBOptions->GetDepth(); s2.MakeMsg(_R(IDS_ANIMATED_GIF)); if (pMkBOptions->WantTransparent()) { s2.MakeMsg(_R(IDS_TRANSPARENT),"animated GIF"); } s.MakeMsg(_R(IDS_TEXTLINE_BR),(const TCHAR*)s2); TempDiskFile.write(s); switch (Palette) { case PAL_OPTIMISED: sPalette.MakeMsg(_R(IDS_OPTIMISED_PAL)); break; case PAL_BROWSER: case PAL_STANDARD: sPalette.MakeMsg(_R(IDS_BROWSER_PAL)); break; case PAL_GLOBALOPTIMISED: sPalette.MakeMsg(_R(IDS_GLOBAL_OPT)); break; } if (colDepth == 8 && (Palette == PAL_STANDARD || Palette == PAL_BROWSER) ) { NoOfColours = 216; } switch (colDepth) { case 32: case 24: s2.MakeMsg(_R(IDS_TRUECOLOUR),colDepth); break; case 8: { // Include the transparent colour in the colour depth check UINT32 RealNumberOfColours = NoOfColours; if (colDepth <= 8 && pMkBOptions->WantTransparent()) { UINT32 MaxColours = UINT32(pow(2,colDepth)); RealNumberOfColours++; if (RealNumberOfColours > MaxColours) RealNumberOfColours = MaxColours; } // We say 8 but we really mean the number of colours deep // We cannot say 2 colours = 2bpp as we save it as 10 colours due // to having 1 transparent colour and the usual lets pick 10 as the // transparent colour. Cannot allow the user to choose 1 as the code // then outputs 8bpp as GRenderOptPalette::GetOptimisedPalette has the // test if (ReservedColours < NumColours), which fails. /* if (RealNumberOfColours <= 2) s2.MakeMsg(_R(IDS_PALETTEINFO),2,NoOfColours,(const TCHAR*)sPalette); else */ if (RealNumberOfColours <= 16) s2.MakeMsg(_R(IDS_PALETTEINFO),4,NoOfColours,(const TCHAR*)sPalette); else s2.MakeMsg(_R(IDS_AN_PALINFO),colDepth,NoOfColours,(const TCHAR*)sPalette); break; } case 1: s2.MakeMsg(_R(IDS_MONO),colDepth); break; case 4: default: s2.MakeMsg(_R(IDS_PALETTEINFO),colDepth,NoOfColours,(const TCHAR*)sPalette); break; } TempDiskFile.write(s2); s.MakeMsg(_R(IDS_NODITHER)); switch (DitherType) { case XARADITHER_ORDERED: case XARADITHER_ORDERED_GREY: Dither.MakeMsg(_R(IDS_DITH_ORDER)); s.MakeMsg(_R(IDS_DITHERING),(const TCHAR*) Dither); break; case XARADITHER_ERROR_DIFFUSION: case XARADITHER_SIMPLE: Dither.MakeMsg(_R(IDS_DITH_ERROR)); s.MakeMsg(_R(IDS_DITHERING),(const TCHAR*) Dither); break; case XARADITHER_NONE: s.MakeMsg(_R(IDS_NODITHER)); break; } TempDiskFile.write(s); } // if (m_pOptions->GetFilterType() == MAKE_BITMAP_FILTER) block ends else { switch (m_pOptions->GetFilterNameStrID()) { case _R(IDN_FILTERNAME_GIF): { GIFExportOptions* pGIFOptions = (GIFExportOptions*)m_pOptions; ERROR3IF(!pGIFOptions->IS_KIND_OF(GIFExportOptions), "pGIFOptions isn't"); PALETTE Palette = PAL_OPTIMISED; DITHER DitherType; UINT32 colDepth; String_64 sPalette; String_64 Dither; UINT32 NoOfColours; NoOfColours=m_pOptions->GetNumColsInPalette(); // Palette = pGIFOptions->GetPalette(); DitherType = pGIFOptions->GetDither(); colDepth = pGIFOptions->GetDepth(); if (pGIFOptions->WantTransparent()) count=count+1; if (pGIFOptions->WantInterlaced()) count=count+2; s.MakeMsg(_R(IDS_GIF)); s2.MakeMsg(_R(IDS_A), (const TCHAR*)s); switch (count) { case 1: s2.MakeMsg(_R(IDS_TRANSPARENT),"GIF"); break; case 2: s2.MakeMsg(_R(IDS_INTERLACED),"GIF"); break; case 3: s2.MakeMsg(_R(IDS_INTER_TRANS),"GIF"); break; case 0: break; } s.MakeMsg(_R(IDS_TEXTLINE_BR),(const TCHAR*)s2); TempDiskFile.write(s); switch (Palette) { case PAL_OPTIMISED: sPalette.MakeMsg(_R(IDS_OPTIMISED_PAL)); break; case PAL_BROWSER: case PAL_STANDARD: sPalette.MakeMsg(_R(IDS_BROWSER_PAL)); break; case PAL_GLOBALOPTIMISED: sPalette.MakeMsg(_R(IDS_GLOBAL_OPT)); break; } if (colDepth == 8 && (Palette == PAL_STANDARD || Palette == PAL_BROWSER) ) { NoOfColours = 216; } s2.MakeMsg(_R(IDS_PALETTEINFO),colDepth,NoOfColours,(const TCHAR*)sPalette); if (colDepth == 8) s2.MakeMsg(_R(IDS_AN_PALINFO),colDepth,NoOfColours,(const TCHAR*)sPalette); if (colDepth == 1) s2.MakeMsg(_R(IDS_MONO),colDepth); if (colDepth > 8) s2.MakeMsg(_R(IDS_TRUECOLOUR),colDepth); TempDiskFile.write(s2); s.MakeMsg(_R(IDS_NODITHER)); switch (DitherType) { case XARADITHER_ORDERED: case XARADITHER_ORDERED_GREY: Dither.MakeMsg(_R(IDS_DITH_ORDER)); s.MakeMsg(_R(IDS_DITHERING),(const TCHAR*) Dither); break; case XARADITHER_ERROR_DIFFUSION: case XARADITHER_SIMPLE: Dither.MakeMsg(_R(IDS_DITH_ERROR)); s.MakeMsg(_R(IDS_DITHERING),(const TCHAR*) Dither); break; case XARADITHER_NONE: s.MakeMsg(_R(IDS_NODITHER)); break; } TempDiskFile.write(s); } // end case _R(IDN_FILTERNAME_GIF) break; case _R(IDS_JPG_EXP_FILTERNAME): { JPEGExportOptions* pJPEGOptions = (JPEGExportOptions *)m_pOptions; ERROR3IF(!pJPEGOptions->IS_KIND_OF(JPEGExportOptions), "pJPEGOptions isn't"); INT32 Quality = pJPEGOptions->GetQuality(); // Default Quality BOOL Progressive = pJPEGOptions->DoAsProgressive(); if (Quality > 100) Quality = 100; s.MakeMsg(_R(IDS_JPEG)); s2.MakeMsg(_R(IDS_A), (const TCHAR*)s); if (Progressive) s2.MakeMsg(_R(IDS_PROGRESSIVE)); s.MakeMsg(_R(IDS_TEXTLINE_BR),(const TCHAR*)s2); TempDiskFile.write(s); s.MakeMsg(_R(IDS_JCOMPRESSION),Quality); TempDiskFile.write(s); } // end case _R(IDS_JPG_EXP_FILTERNAME) break; case _R(IDT_FILTERNAME_BMP): { BMPExportOptions* pBMPOptions = (BMPExportOptions*)m_pOptions; ERROR3IF(!pBMPOptions->IS_KIND_OF(BMPExportOptions), "pBMPOptions isn't"); PALETTE Palette; DITHER DitherType; UINT32 colDepth; String_64 sPalette; String_64 Dither; UINT32 NoOfColours; NoOfColours=m_pOptions->GetNumColsInPalette(); Palette = pBMPOptions->GetPalette(); DitherType = pBMPOptions->GetDither(); colDepth = pBMPOptions->GetDepth(); s.MakeMsg(_R(IDS_BMP)); s2.MakeMsg(_R(IDS_A), (const TCHAR*)s); s.MakeMsg(_R(IDS_TEXTLINE_BR),(const TCHAR*)s2); TempDiskFile.write(s); switch (Palette) { case PAL_OPTIMISED: sPalette.MakeMsg(_R(IDS_OPTIMISED_PAL)); break; case PAL_BROWSER: case PAL_STANDARD: sPalette.MakeMsg(_R(IDS_BROWSER_PAL)); break; case PAL_GLOBALOPTIMISED: sPalette.MakeMsg(_R(IDS_GLOBAL_OPT)); break; } if (colDepth == 8 && (Palette == PAL_STANDARD || Palette == PAL_BROWSER) ) { NoOfColours = 216; } if (colDepth == 8 && NoOfColours > 256) NoOfColours = 256; s2.MakeMsg(_R(IDS_PALETTEINFO),colDepth,NoOfColours,(const TCHAR*)sPalette); if (colDepth == 8) s2.MakeMsg(_R(IDS_AN_PALINFO),colDepth,NoOfColours,(const TCHAR*)sPalette); if (colDepth == 1) s2.MakeMsg(_R(IDS_MONO),colDepth); if (colDepth > 8) s2.MakeMsg(_R(IDS_TRUECOLOUR),colDepth); TempDiskFile.write(s2); s.MakeMsg(_R(IDS_NODITHER)); switch (DitherType) { case XARADITHER_ORDERED: case XARADITHER_ORDERED_GREY: Dither.MakeMsg(_R(IDS_DITH_ORDER)); s.MakeMsg(_R(IDS_DITHERING),(const TCHAR*) Dither); break; case XARADITHER_ERROR_DIFFUSION: case XARADITHER_SIMPLE: Dither.MakeMsg(_R(IDS_DITH_ERROR)); s.MakeMsg(_R(IDS_DITHERING),(const TCHAR*) Dither); break; case XARADITHER_NONE: s.MakeMsg(_R(IDS_NODITHER)); break; } TempDiskFile.write(s); } // end case _R(IDT_FILTERNAME_BMP) break; case _R(IDS_FILTERNAME_PNG): { PNGExportOptions* pPNGOptions = (PNGExportOptions*)m_pOptions; ERROR3IF(!pPNGOptions->IS_KIND_OF(PNGExportOptions), "pPNGOptions isn't"); PALETTE Palette = PAL_OPTIMISED; DITHER DitherType; UINT32 colDepth; String_64 sPalette; String_64 Dither; UINT32 NoOfColours; NoOfColours=m_pOptions->GetNumColsInPalette(); // Palette = pPNGOptions->GetPalette(); DitherType = pPNGOptions->GetDither(); colDepth = pPNGOptions->GetDepth(); if (pPNGOptions->WantTransparent()) count=count+1; if (pPNGOptions->WantInterlaced()) count=count+2; s.MakeMsg(_R(IDS_PNG)); s2.MakeMsg(_R(IDS_A), (const TCHAR*)s); switch (count) { case 1: s2.MakeMsg(_R(IDS_TRANSPARENT),"PNG"); break; case 2: s2.MakeMsg(_R(IDS_INTERLACED),"PNG"); break; case 3: s2.MakeMsg(_R(IDS_INTER_TRANS),"PNG"); break; case 0: break; } s.MakeMsg(_R(IDS_TEXTLINE_BR),(const TCHAR*)s2); TempDiskFile.write(s); switch (Palette) { case PAL_OPTIMISED: sPalette.MakeMsg(_R(IDS_OPTIMISED_PAL)); break; case PAL_BROWSER: case PAL_STANDARD: sPalette.MakeMsg(_R(IDS_BROWSER_PAL)); break; case PAL_GLOBALOPTIMISED: sPalette.MakeMsg(_R(IDS_GLOBAL_OPT)); break; } if (colDepth == 8 && (Palette == PAL_STANDARD || Palette == PAL_BROWSER) ) { NoOfColours = 216; } s2.MakeMsg(_R(IDS_PALETTEINFO),colDepth,NoOfColours,(const TCHAR*)sPalette); if (colDepth == 8) s2.MakeMsg(_R(IDS_AN_PALINFO),colDepth,NoOfColours,(const TCHAR*)sPalette); if (colDepth == 1) s2.MakeMsg(_R(IDS_MONO),colDepth); if (colDepth > 8) s2.MakeMsg(_R(IDS_TRUECOLOUR),colDepth); TempDiskFile.write(s2); s.MakeMsg(_R(IDS_NODITHER)); switch (DitherType) { case XARADITHER_ORDERED: case XARADITHER_ORDERED_GREY: Dither.MakeMsg(_R(IDS_DITH_ORDER)); s.MakeMsg(_R(IDS_DITHERING),(const TCHAR*) Dither); break; case XARADITHER_ERROR_DIFFUSION: case XARADITHER_SIMPLE: Dither.MakeMsg(_R(IDS_DITH_ERROR)); s.MakeMsg(_R(IDS_DITHERING),(const TCHAR*) Dither); break; case XARADITHER_NONE: s.MakeMsg(_R(IDS_NODITHER)); break; } TempDiskFile.write(s); } // end case _R(IDS_FILTERNAME_PNG) break; } // end switch (m_pOptions->GetFilterNameStrID()) } // end else block GenerateBitmapInfoStrings(ImageSize, FileSize); // output the bitmap info s.MakeMsg(_R(IDS_HTML_INFO1), (TCHAR *)ImageSize); TempDiskFile.write(s); // output the bitmap file size info s.MakeMsg(_R(IDS_HTML_INFO2), (TCHAR *)FileSize); TempDiskFile.write(s); s.MakeMsg(_R(IDS_CLOSE_CENTER)); TempDiskFile.write(s); s.MakeMsg(_R(IDS_TDTR_CLOSE)); TempDiskFile.write(s); s.MakeMsg(_R(IDS_BANNER_BOX)); TempDiskFile.write(s); s.MakeMsg(_R(IDS_SPEED_BUILD)); TempDiskFile.write(s); // s.MakeMsg(_R(IDS_SPEED_BUILD2)); // TempDiskFile.write(s); s.MakeMsg(_R(IDS_ES_TR)); TempDiskFile.write(s); String_64 times; s.MakeMsg(_R(IDS_TIME_ENTRY),"14.4k"); TempDiskFile.write(s); CalculateTime(times,14400.0); TempDiskFile.write(times); s.MakeMsg(_R(IDS_ES_TR)); TempDiskFile.write(s); s.MakeMsg(_R(IDS_TIME_ENTRY),"28.8k"); TempDiskFile.write(s); CalculateTime(times,28800.0); TempDiskFile.write(times); s.MakeMsg(_R(IDS_ES_TR)); TempDiskFile.write(s); s.MakeMsg(_R(IDS_TIME_ENTRY),"33.6k"); TempDiskFile.write(s); CalculateTime(times,33600.0); TempDiskFile.write(times); s.MakeMsg(_R(IDS_ES_TR)); TempDiskFile.write(s); s.MakeMsg(_R(IDS_TIME_ENTRY),"57.6k"); TempDiskFile.write(s); CalculateTime(times,57600.0); TempDiskFile.write(times); s.MakeMsg(_R(IDS_ES_TR)); TempDiskFile.write(s); s.MakeMsg(_R(IDS_TIME_ENTRY),"64k"); TempDiskFile.write(s); CalculateTime(times,65536.0); TempDiskFile.write(times); s.MakeMsg(_R(IDS_ES_TR)); TempDiskFile.write(s); s.MakeMsg(_R(IDS_TIME_ENTRY),"128k"); TempDiskFile.write(s); CalculateTime(times,131072.0); TempDiskFile.write(times); // s.MakeMsg(_R(IDS_ES_TR)); // TempDiskFile.write(s); s.MakeMsg(_R(IDS_SPEED_END)); TempDiskFile.write(s); TRACE( _T("m_FileSize = %d"), m_FileSize); } // end of if (BrowserOptions.m_bInfo != FALSE) String_64 webaddy(_R(IDS_HTML_URL_PROGRAM)); //Mark Howitt, 29/10/97. Setup the _R(IDS_HTML_URL_VISITMSG) To be a TCHAR* Also. It likes it that way! String_64 webvmess(_R(IDS_HTML_URL_VISITMSG)); s.MakeMsg(_R(IDS_LINK_BOX),(TCHAR *)webaddy,(TCHAR *)webvmess); TempDiskFile.write(s); //end of my stuff s.MakeMsg(_R(IDS_END_TABLE)); TempDiskFile.write(s); s.MakeMsg(_R(IDS_CLOSE_CENTER)); TempDiskFile.write(s); // output the "Exported from" string // get the xara logo file name String_256 Logo(_R(IDS_HTML_XARALOGO)); // set it in the path ProgramPath.SetFileNameAndType(Logo); // get the xara link String_256 URL(_R(IDS_HTML_URL_XARA)); // output the xara link and the xara logo s.MakeMsg(_R(IDS_HTML_XARA), (TCHAR *)URL, (TCHAR *)ProgramPath.GetWebAddress()); TempDiskFile.write(s); // Do not display the Xara X logo bottom right... /* // get the program logo file name Logo.Load(_R(IDS_HTML_PROGRAMLOGO)); // set it in the path ProgramPath.SetFileNameAndType(Logo); // output the program link URL.Load(_R(IDS_HTML_URL_PROGRAM)); s.MakeMsg(_R(IDS_HTML_PROGRAM), (TCHAR *)URL, (TCHAR *)ProgramPath.GetWebAddress()); TempDiskFile.write(s); */ // output the end of the file s.Load(_R(IDS_HTML_END)); TempDiskFile.write(s); // close the file TempDiskFile.close(); // now export the image map, if the option for that is set if (BrowserOptions.m_bImagemap != FALSE) { // export the image map ExportImagemap( TempDiskFile, m_pTempHTMLPath, m_pOptions->GetSelectionType(), m_pOptions->GetDPI(), BrowserOptions.m_ifoImagemapOptions); } TCHAR *FileWebAddress = m_pTempHTMLPath->GetWebAddress(); //Graham 17/9/97 ProgramPath.SetFileNameAndType(PRODUCT_WEBLINKEXENAME); const TCHAR *PathToWebLink = (const TCHAR *)ProgramPath.GetPath(); String_256 CmdLine = PathToWebLink + String_256(" -f ") + FileWebAddress; //TCHAR *CommandLine = (TCHAR *)CmdLine; if (!InvokeWeblink(CmdLine)) return FALSE; } // end of TRY block catch( CFileException ) { // any disk problems - come here // not much we can do really - just close the file and return FALSE if (TempDiskFile.isOpen()) TempDiskFile.close(); return FALSE; } #endif return TRUE; }
BOOL CFamiTrackerApp::InitInstance() { // InitCommonControls() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. InitCommonControls(); #ifdef SUPPORT_TRANSLATIONS LoadLocalization(); #endif CWinApp::InitInstance(); TRACE("App: InitInstance\n"); if (!AfxOleInit()) { TRACE("OLE initialization failed\n"); } // 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 // Change the registry key under which our settings are stored // TODO: You should modify this string to be something appropriate // such as the name of your company or organization SetRegistryKey(_T("")); LoadStdProfileSettings(MAX_RECENT_FILES); // Load standard INI file options (including MRU) // Load program settings m_pSettings = CSettings::GetObject(); m_pSettings->LoadSettings(); // Parse command line for standard shell commands, DDE, file open + some custom ones CFTCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); if (CheckSingleInstance(cmdInfo)) return FALSE; //who: added by Derek Andrews <*****@*****.**> //why: Load all custom exporter plugins on startup. TCHAR pathToPlugins[MAX_PATH]; GetModuleFileName(NULL, pathToPlugins, MAX_PATH); PathRemoveFileSpec(pathToPlugins); PathAppend(pathToPlugins, _T("\\Plugins")); m_customExporters = new CCustomExporters( pathToPlugins ); // Load custom accelerator m_pAccel = new CAccelerator(); m_pAccel->LoadShortcuts(m_pSettings); m_pAccel->Setup(); // Create the MIDI interface m_pMIDI = new CMIDI(); // Create sound generator m_pSoundGenerator = new CSoundGen(); // Create channel map m_pChannelMap = new CChannelMap(); // Start sound generator thread, initially suspended if (!m_pSoundGenerator->CreateThread(CREATE_SUSPENDED)) { // If failed, restore and save default settings m_pSettings->DefaultSettings(); m_pSettings->SaveSettings(); // Show message and quit AfxMessageBox(IDS_START_ERROR, MB_ICONERROR); return FALSE; } // Check if the application is themed CheckAppThemed(); // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views CDocTemplate0CC* pDocTemplate = new CDocTemplate0CC( // // // IDR_MAINFRAME, RUNTIME_CLASS(CFamiTrackerDoc), RUNTIME_CLASS(CMainFrame), RUNTIME_CLASS(CFamiTrackerView)); if (!pDocTemplate) return FALSE; if (m_pDocManager == NULL) // // // m_pDocManager = new CDocManager0CC { }; m_pDocManager->AddDocTemplate(pDocTemplate); // Work-around to enable file type registration in windows vista/7 if (IsWindowsVistaOrGreater()) { // // // HKEY HKCU; long res_reg = ::RegOpenKey(HKEY_CURRENT_USER, _T("Software\\Classes"), &HKCU); if(res_reg == ERROR_SUCCESS) RegOverridePredefKey(HKEY_CLASSES_ROOT, HKCU); } // Enable DDE Execute open EnableShellOpen(); // Skip this if in wip/beta mode #if !defined(WIP) && !defined(_DEBUG) // Add shell options RegisterShellFileTypes(); // // // static const LPCTSTR FILE_ASSOC_NAME = _T("0CC-FamiTracker Module"); AfxRegSetValue(HKEY_CLASSES_ROOT, "0CCFamiTracker.Document", REG_SZ, FILE_ASSOC_NAME, lstrlen(FILE_ASSOC_NAME) * sizeof(TCHAR)); // Add an option to play files CString strPathName, strTemp, strFileTypeId; AfxGetModuleShortFileName(AfxGetInstanceHandle(), strPathName); CString strOpenCommandLine = strPathName; strOpenCommandLine += _T(" /play \"%1\""); if (pDocTemplate->GetDocString(strFileTypeId, CDocTemplate::regFileTypeId) && !strFileTypeId.IsEmpty()) { strTemp.Format(_T("%s\\shell\\play\\%s"), (LPCTSTR)strFileTypeId, _T("command")); AfxRegSetValue(HKEY_CLASSES_ROOT, strTemp, REG_SZ, strOpenCommandLine, lstrlen(strOpenCommandLine) * sizeof(TCHAR)); } #endif // Handle command line export if (cmdInfo.m_bExport) { CCommandLineExport exporter; exporter.CommandLineExport(cmdInfo.m_strFileName, cmdInfo.m_strExportFile, cmdInfo.m_strExportLogFile, cmdInfo.m_strExportDPCMFile); ExitProcess(0); } // Dispatch commands specified on the command line. Will return FALSE if // app was launched with /RegServer, /Register, /Unregserver or /Unregister. if (!ProcessShellCommand(cmdInfo)) { if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppUnregister) { // Also clear settings from registry when unregistering m_pSettings->DeleteSettings(); } return FALSE; } // Move root key back to default if (IsWindowsVistaOrGreater()) { // // // ::RegOverridePredefKey(HKEY_CLASSES_ROOT, NULL); } // The one and only window has been initialized, so show and update it m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); // call DragAcceptFiles only if there's a suffix // In an SDI app, this should occur after ProcessShellCommand // Enable drag/drop open m_pMainWnd->DragAcceptFiles(); // Initialize the sound interface, also resumes the thread if (!m_pSoundGenerator->InitializeSound(m_pMainWnd->m_hWnd)) { // If failed, restore and save default settings m_pSettings->DefaultSettings(); m_pSettings->SaveSettings(); // Quit program AfxMessageBox(IDS_START_ERROR, MB_ICONERROR); return FALSE; } // Initialize midi unit m_pMIDI->Init(); if (cmdInfo.m_bPlay) theApp.StartPlayer(MODE_PLAY); #ifdef EXPORT_TEST if (cmdInfo.m_bVerifyExport) { m_bExportTesting = true; VerifyExport(cmdInfo.m_strVerifyFile); } else { // Append menu option m_pMainWnd->GetMenu()->GetSubMenu(2)->AppendMenu(MF_SEPARATOR); m_pMainWnd->GetMenu()->GetSubMenu(2)->AppendMenu(MF_STRING, ID_MODULE_TEST_EXPORT, _T("Test exporter")); } #endif // Save the main window handle RegisterSingleInstance(); #ifndef _DEBUG m_pMainWnd->GetMenu()->GetSubMenu(4)->RemoveMenu(ID_MODULE_CHANNELS, MF_BYCOMMAND); // // // #endif if (m_pSettings->General.bCheckVersion) // // // CheckNewVersion(true); // Initialization is done TRACE("App: InitInstance done\n"); return TRUE; }
BOOL AFXAPI AfxOleRegisterControlClass(HINSTANCE hInstance, REFCLSID clsid, LPCTSTR pszProgID, UINT idTypeName, UINT idBitmap, int nRegFlags, DWORD dwMiscStatus, REFGUID tlid, WORD wVerMajor, WORD wVerMinor) { USES_CONVERSION; BOOL bSuccess = FALSE; // Format class ID as a string OLECHAR szClassID[GUID_CCH]; int cchGuid = ::StringFromGUID2(clsid, szClassID, GUID_CCH); LPCTSTR lpszClassID = OLE2CT(szClassID); ASSERT(cchGuid == GUID_CCH); // Did StringFromGUID2 work? if (cchGuid != GUID_CCH) return FALSE; // Format typelib guid as a string OLECHAR szTypeLibID[GUID_CCH]; cchGuid = ::StringFromGUID2(tlid, szTypeLibID, GUID_CCH); ASSERT(cchGuid == GUID_CCH); // Did StringFromGUID2 work? if (cchGuid != GUID_CCH) return FALSE; CString strPathName; AfxGetModuleShortFileName(hInstance, strPathName); CString strTypeName; if (!strTypeName.LoadString(idTypeName)) { ASSERT(FALSE); // Name string not present in resources strTypeName = lpszClassID; // Use Class ID instead } TCHAR szBitmapID[_MAX_PATH]; _itot(idBitmap, szBitmapID, 10); TCHAR szMiscStatus[_MAX_PATH]; _ltot(dwMiscStatus, szMiscStatus, 10); // Format version string as "major.minor" TCHAR szVersion[_MAX_PATH]; wsprintf(szVersion, _T("%d.%d"), wVerMajor, wVerMinor); // Attempt to open registry keys. HKEY hkeyClassID = NULL; HKEY hkeyProgID = NULL; TCHAR szScratch[_MAX_PATH]; wsprintf(szScratch, _T("CLSID\\%s"), lpszClassID); if (::RegCreateKey(HKEY_CLASSES_ROOT, szScratch, &hkeyClassID) != ERROR_SUCCESS) goto Error; if (::RegCreateKey(HKEY_CLASSES_ROOT, pszProgID, &hkeyProgID) != ERROR_SUCCESS) goto Error; ASSERT(hkeyClassID != NULL); ASSERT(hkeyProgID != NULL); LPCTSTR rglpszSymbols[7]; rglpszSymbols[0] = strTypeName; rglpszSymbols[1] = lpszClassID; bSuccess = AfxOleRegisterHelper(_afxCtrlProgID, rglpszSymbols, 2, TRUE, hkeyProgID); if (!bSuccess) goto Error; rglpszSymbols[1] = pszProgID; rglpszSymbols[2] = strPathName; rglpszSymbols[3] = szBitmapID; rglpszSymbols[4] = szMiscStatus; rglpszSymbols[5] = OLE2CT(szTypeLibID); rglpszSymbols[6] = szVersion; bSuccess = AfxOleRegisterHelper(_afxCtrlClassID, rglpszSymbols, 7, TRUE, hkeyClassID); if (!bSuccess) goto Error; if (nRegFlags & afxRegInsertable) { bSuccess = (::RegSetValue(hkeyProgID, _T("Insertable"), REG_SZ, _T(""), 0) == ERROR_SUCCESS) && (::RegSetValue(hkeyClassID, _T("Insertable"), REG_SZ, _T(""), 0) == ERROR_SUCCESS); } if (nRegFlags & afxRegApartmentThreading) { HKEY hkeyInprocServer32; bSuccess = (::RegOpenKey(hkeyClassID, INPROCSERVER, &hkeyInprocServer32) == ERROR_SUCCESS); if (!bSuccess) goto Error; ASSERT(hkeyInprocServer32 != NULL); static TCHAR szApartment[] = _T("Apartment"); bSuccess = (::RegSetValueEx(hkeyInprocServer32, _T("ThreadingModel"), 0, REG_SZ, (const BYTE*)szApartment, (lstrlen(szApartment)+1) * sizeof(TCHAR)) == ERROR_SUCCESS); ::RegCloseKey(hkeyInprocServer32); } Error: if (hkeyProgID != NULL) ::RegCloseKey(hkeyProgID); if (hkeyClassID != NULL) ::RegCloseKey(hkeyClassID); return bSuccess; }
BOOL AFXAPI AfxOleRegisterPropertyPageClass(HINSTANCE hInstance, REFCLSID clsid, UINT idTypeName, int nRegFlags) { ASSERT(!(nRegFlags & afxRegInsertable)); // can't be insertable USES_CONVERSION; BOOL bSuccess = FALSE; // Format class ID as a string OLECHAR szClassID[GUID_CCH]; int cchGuid = ::StringFromGUID2(clsid, szClassID, GUID_CCH); LPCTSTR lpszClassID = OLE2CT(szClassID); ASSERT(cchGuid == GUID_CCH); // Did StringFromGUID2 work? if (cchGuid != GUID_CCH) return FALSE; CString strPathName; AfxGetModuleShortFileName(hInstance, strPathName); CString strTypeName; if (!strTypeName.LoadString(idTypeName)) { ASSERT(FALSE); // Name string not present in resources strTypeName = lpszClassID; // Use Class ID instead } HKEY hkeyClassID = NULL; TCHAR szKey[_MAX_PATH]; wsprintf(szKey, _T("CLSID\\%s"), lpszClassID); if (::RegCreateKey(HKEY_CLASSES_ROOT, szKey, &hkeyClassID) != ERROR_SUCCESS) goto Error; LPCTSTR rglpszSymbols[2]; rglpszSymbols[0] = strTypeName; rglpszSymbols[1] = strPathName; bSuccess = AfxOleRegisterHelper(_afxPropPageClass, rglpszSymbols, 2, TRUE, hkeyClassID); if (!bSuccess) goto Error; if (nRegFlags & afxRegApartmentThreading) { HKEY hkeyInprocServer32; bSuccess = (::RegOpenKey(hkeyClassID, INPROCSERVER, &hkeyInprocServer32) == ERROR_SUCCESS); if (!bSuccess) goto Error; ASSERT(hkeyInprocServer32 != NULL); static TCHAR szApartment[] = _T("Apartment"); bSuccess = (::RegSetValueEx(hkeyInprocServer32, _T("ThreadingModel"), 0, REG_SZ, (const BYTE*)szApartment, (lstrlen(szApartment)+1) * sizeof(TCHAR)) == ERROR_SUCCESS); ::RegCloseKey(hkeyInprocServer32); } Error: if (hkeyClassID != NULL) ::RegCloseKey(hkeyClassID); return bSuccess; }
void AfxRegisterShellFileTypes(BOOL bCompat) { CString strPathName, strTemp; AfxGetModuleShortFileName(AfxGetInstanceHandle(), strPathName); CString strOpenCommandLine = strPathName; CString strPrintCommandLine = strPathName; CString strPrintToCommandLine = strPathName; CString strDefaultIconCommandLine = strPathName; CString strMainFrame; VERIFY(strMainFrame.LoadString( IDR_MAINFRAME )); if (bCompat) { CString strIconIndex; HICON hIcon = ::ExtractIcon(AfxGetInstanceHandle(), strPathName, 1); if (hIcon != NULL) { strIconIndex.Format(_afxIconIndexFmt, 1); DestroyIcon(hIcon); } else { strIconIndex.Format(_afxIconIndexFmt, DEFAULT_ICON_INDEX); } strDefaultIconCommandLine += strIconIndex; } CString strFilterExt, strFileTypeId, strFileTypeName; if (AfxExtractSubString( strFileTypeId, strMainFrame, CDocTemplate::regFileTypeId) && !strFileTypeId.IsEmpty()) { // enough info to register it if (!AfxExtractSubString( strFileTypeName, strMainFrame, CDocTemplate::regFileTypeName)) strFileTypeName = strFileTypeId; // use id name ASSERT(strFileTypeId.Find(' ') == -1); // no spaces allowed // first register the type ID of our server if (!AfxSetRegKey(strFileTypeId, strFileTypeName)) return; // just skip it if (bCompat) { // path\DefaultIcon = path,1 strTemp.Format(_afxDefaultIconFmt, (LPCTSTR)strFileTypeId); if (!AfxSetRegKey(strTemp, strDefaultIconCommandLine)) return; // just skip it } // path\shell\open\command = path filename // path\shell\print\command = path /p filename // path\shell\printto\command = path /pt filename printer driver port strOpenCommandLine += _afxOpenArg; if (bCompat) { strPrintCommandLine += _afxPrintArg; strPrintToCommandLine += _afxPrintToArg; } // path\shell\open\command = path filename strTemp.Format(_afxShellOpenFmt, (LPCTSTR)strFileTypeId, (LPCTSTR)_afxCommand); if (!AfxSetRegKey(strTemp, strOpenCommandLine)) return; // just skip it if (bCompat) { // path\shell\print\command = path /p filename strTemp.Format(_afxShellPrintFmt, (LPCTSTR)strFileTypeId, (LPCTSTR)_afxCommand); if (!AfxSetRegKey(strTemp, strPrintCommandLine)) return; // just skip it // path\shell\printto\command = path /pt filename printer driver port strTemp.Format(_afxShellPrintToFmt, (LPCTSTR)strFileTypeId, (LPCTSTR)_afxCommand); if (!AfxSetRegKey(strTemp, strPrintToCommandLine)) return; // just skip it } AfxExtractSubString( strFilterExt, strMainFrame, CDocTemplate::filterExt); if (!strFilterExt.IsEmpty()) { ASSERT(strFilterExt[0] == '.'); LONG lSize = _MAX_PATH * 2; LONG lResult = ::RegQueryValue(HKEY_CLASSES_ROOT, strFilterExt, strTemp.GetBuffer(lSize), &lSize); strTemp.ReleaseBuffer(); if (lResult != ERROR_SUCCESS || strTemp.IsEmpty() || strTemp == strFileTypeId) { // no association for that suffix if (!AfxSetRegKey(strFilterExt, strFileTypeId)) return; if (bCompat) { strTemp.Format(_afxShellNewFmt, (LPCTSTR)strFilterExt); (void)AfxSetRegKey(strTemp, _afxShellNewValue, _afxShellNewValueName); } } } } }