1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 1997-2004 Apple Computer, Inc. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "PrinterSetupWizardApp.h"
20 #include "PrinterSetupWizardSheet.h"
21 #include "DebugServices.h"
22 #include "loclibrary.h"
28 #ifndef HeapEnableTerminationOnCorruption
29 # define HeapEnableTerminationOnCorruption (HEAP_INFORMATION_CLASS) 1
33 // Stash away pointers to our resource DLLs
35 static HINSTANCE g_nonLocalizedResources
= NULL
;
36 static HINSTANCE g_localizedResources
= NULL
;
40 GetNonLocalizedResources()
42 return g_nonLocalizedResources
;
47 GetLocalizedResources()
49 return g_localizedResources
;
53 // CPrinterSetupWizardApp
55 BEGIN_MESSAGE_MAP(CPrinterSetupWizardApp
, CWinApp
)
56 ON_COMMAND(ID_HELP
, CWinApp::OnHelp
)
60 // CPrinterSetupWizardApp construction
62 CPrinterSetupWizardApp::CPrinterSetupWizardApp()
64 // TODO: add construction code here,
65 // Place all significant initialization in InitInstance
69 // The one and only CPrinterSetupWizardApp object
71 CPrinterSetupWizardApp theApp
;
74 // CPrinterSetupWizardApp initialization
76 BOOL
CPrinterSetupWizardApp::InitInstance()
80 wchar_t resource
[MAX_PATH
];
82 OSStatus err
= kNoErr
;
84 HeapSetInformation( NULL
, HeapEnableTerminationOnCorruption
, NULL
, 0 );
87 // initialize the debugging framework
89 debug_initialize( kDebugOutputTypeWindowsDebugger
, "PrinterSetupWizard", NULL
);
90 debug_set_property( kDebugPropertyTagPrintLevel
, kDebugLevelTrace
);
92 // Before we load the resources, let's load the error string
94 errorMessage
.LoadString( IDS_REINSTALL
);
95 errorCaption
.LoadString( IDS_REINSTALL_CAPTION
);
99 res
= PathForResource( NULL
, L
"PrinterWizardResources.dll", resource
, MAX_PATH
);
100 err
= translate_errno( res
!= 0, kUnknownErr
, kUnknownErr
);
101 require_noerr( err
, exit
);
103 g_nonLocalizedResources
= LoadLibrary( resource
);
104 translate_errno( g_nonLocalizedResources
, GetLastError(), kUnknownErr
);
105 require_noerr( err
, exit
);
107 res
= PathForResource( NULL
, L
"PrinterWizardLocalized.dll", resource
, MAX_PATH
);
108 err
= translate_errno( res
!= 0, kUnknownErr
, kUnknownErr
);
109 require_noerr( err
, exit
);
111 g_localizedResources
= LoadLibrary( resource
);
112 translate_errno( g_localizedResources
, GetLastError(), kUnknownErr
);
113 require_noerr( err
, exit
);
115 AfxSetResourceHandle( g_localizedResources
);
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();
122 CWinApp::InitInstance();
124 AfxEnableControlContainer();
127 CPrinterSetupWizardSheet
dlg(IDS_CAPTION
);
133 INT_PTR nResponse
= dlg
.DoModal();
135 if (nResponse
== IDOK
)
137 // TODO: Place code here to handle when the dialog is
140 else if (nResponse
== IDCANCEL
)
142 // TODO: Place code here to handle when the dialog is
143 // dismissed with Cancel
146 catch (CPrinterSetupWizardSheet::WizardException
& exc
)
148 MessageBox(NULL
, exc
.text
, exc
.caption
, MB_OK
|MB_ICONEXCLAMATION
);
156 MessageBox( NULL
, errorMessage
, errorCaption
, MB_ICONERROR
| MB_OK
);
159 if ( g_nonLocalizedResources
)
161 FreeLibrary( g_nonLocalizedResources
);
164 if ( g_localizedResources
)
166 FreeLibrary( g_localizedResources
);
169 // Since the dialog has been closed, return FALSE so that we exit the
170 // application, rather than start the application's message pump.