1/* -*- Mode: C; tab-width: 4 -*- 2 * 3 * Copyright (c) 1997-2004 Apple Computer, Inc. All rights reserved. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18#include "stdafx.h" 19#include "PrinterSetupWizardApp.h" 20#include "PrinterSetupWizardSheet.h" 21#include "DebugServices.h" 22#include "loclibrary.h" 23 24#ifdef _DEBUG 25#define new DEBUG_NEW 26#endif 27 28#ifndef HeapEnableTerminationOnCorruption 29# define HeapEnableTerminationOnCorruption (HEAP_INFORMATION_CLASS) 1 30#endif 31 32 33// Stash away pointers to our resource DLLs 34 35static HINSTANCE g_nonLocalizedResources = NULL; 36static HINSTANCE g_localizedResources = NULL; 37 38 39HINSTANCE 40GetNonLocalizedResources() 41{ 42 return g_nonLocalizedResources; 43} 44 45 46HINSTANCE 47GetLocalizedResources() 48{ 49 return g_localizedResources; 50} 51 52 53// CPrinterSetupWizardApp 54 55BEGIN_MESSAGE_MAP(CPrinterSetupWizardApp, CWinApp) 56 ON_COMMAND(ID_HELP, CWinApp::OnHelp) 57END_MESSAGE_MAP() 58 59 60// CPrinterSetupWizardApp construction 61 62CPrinterSetupWizardApp::CPrinterSetupWizardApp() 63{ 64 // TODO: add construction code here, 65 // Place all significant initialization in InitInstance 66} 67 68 69// The one and only CPrinterSetupWizardApp object 70 71CPrinterSetupWizardApp theApp; 72 73 74// CPrinterSetupWizardApp initialization 75 76BOOL CPrinterSetupWizardApp::InitInstance() 77{ 78 CString errorMessage; 79 CString errorCaption; 80 wchar_t resource[MAX_PATH]; 81 int res; 82 OSStatus err = kNoErr; 83 84 HeapSetInformation( NULL, HeapEnableTerminationOnCorruption, NULL, 0 ); 85 86 // 87 // initialize the debugging framework 88 // 89 debug_initialize( kDebugOutputTypeWindowsDebugger, "PrinterSetupWizard", NULL ); 90 debug_set_property( kDebugPropertyTagPrintLevel, kDebugLevelTrace ); 91 92 // Before we load the resources, let's load the error string 93 94 errorMessage.LoadString( IDS_REINSTALL ); 95 errorCaption.LoadString( IDS_REINSTALL_CAPTION ); 96 97 // Load Resources 98 99 res = PathForResource( NULL, L"PrinterWizardResources.dll", resource, MAX_PATH ); 100 err = translate_errno( res != 0, kUnknownErr, kUnknownErr ); 101 require_noerr( err, exit ); 102 103 g_nonLocalizedResources = LoadLibrary( resource ); 104 translate_errno( g_nonLocalizedResources, GetLastError(), kUnknownErr ); 105 require_noerr( err, exit ); 106 107 res = PathForResource( NULL, L"PrinterWizardLocalized.dll", resource, MAX_PATH ); 108 err = translate_errno( res != 0, kUnknownErr, kUnknownErr ); 109 require_noerr( err, exit ); 110 111 g_localizedResources = LoadLibrary( resource ); 112 translate_errno( g_localizedResources, GetLastError(), kUnknownErr ); 113 require_noerr( err, exit ); 114 115 AfxSetResourceHandle( g_localizedResources ); 116 117 // InitCommonControls() is required on Windows XP if an application 118 // manifest specifies use of ComCtl32.dll version 6 or later to enable 119 // visual styles. Otherwise, any window creation will fail. 120 InitCommonControls(); 121 122 CWinApp::InitInstance(); 123 124 AfxEnableControlContainer(); 125 126 { 127 CPrinterSetupWizardSheet dlg(IDS_CAPTION); 128 129 m_pMainWnd = &dlg; 130 131 try 132 { 133 INT_PTR nResponse = dlg.DoModal(); 134 135 if (nResponse == IDOK) 136 { 137 // TODO: Place code here to handle when the dialog is 138 // dismissed with OK 139 } 140 else if (nResponse == IDCANCEL) 141 { 142 // TODO: Place code here to handle when the dialog is 143 // dismissed with Cancel 144 } 145 } 146 catch (CPrinterSetupWizardSheet::WizardException & exc) 147 { 148 MessageBox(NULL, exc.text, exc.caption, MB_OK|MB_ICONEXCLAMATION); 149 } 150 } 151 152exit: 153 154 if ( err ) 155 { 156 MessageBox( NULL, errorMessage, errorCaption, MB_ICONERROR | MB_OK ); 157 } 158 159 if ( g_nonLocalizedResources ) 160 { 161 FreeLibrary( g_nonLocalizedResources ); 162 } 163 164 if ( g_localizedResources ) 165 { 166 FreeLibrary( g_localizedResources ); 167 } 168 169 // Since the dialog has been closed, return FALSE so that we exit the 170 // application, rather than start the application's message pump. 171 return FALSE; 172} 173