]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/PrinterSetupWizard/PrinterSetupWizardApp.cpp
mDNSResponder-98.tar.gz
[apple/mdnsresponder.git] / Clients / PrinterSetupWizard / PrinterSetupWizardApp.cpp
1 /*
2 * Copyright (c) 1997-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22
23 Change History (most recent first):
24
25 $Log: PrinterSetupWizardApp.cpp,v $
26 Revision 1.5 2005/01/25 18:30:02 shersche
27 Fix call to PathForResource() by passing in NULL as first parameter.
28
29 Revision 1.4 2005/01/25 08:54:41 shersche
30 <rdar://problem/3911084> Load resource DLLs at startup.
31 Bug #: 3911084
32
33 Revision 1.3 2004/07/13 21:24:23 rpantos
34 Fix for <rdar://problem/3701120>.
35
36 Revision 1.2 2004/06/24 20:12:08 shersche
37 Clean up source code
38 Submitted by: herscher
39
40 Revision 1.1 2004/06/18 04:36:57 rpantos
41 First checked in
42
43
44 */
45
46 #include "stdafx.h"
47 #include "PrinterSetupWizardApp.h"
48 #include "PrinterSetupWizardSheet.h"
49 #include "DebugServices.h"
50 #include "loclibrary.h"
51
52 #ifdef _DEBUG
53 #define new DEBUG_NEW
54 #endif
55
56 // Stash away pointers to our resource DLLs
57
58 static HINSTANCE g_nonLocalizedResources = NULL;
59 static HINSTANCE g_localizedResources = NULL;
60
61
62 HINSTANCE
63 GetNonLocalizedResources()
64 {
65 return g_nonLocalizedResources;
66 }
67
68
69 HINSTANCE
70 GetLocalizedResources()
71 {
72 return g_localizedResources;
73 }
74
75
76 // CPrinterSetupWizardApp
77
78 BEGIN_MESSAGE_MAP(CPrinterSetupWizardApp, CWinApp)
79 ON_COMMAND(ID_HELP, CWinApp::OnHelp)
80 END_MESSAGE_MAP()
81
82
83 // CPrinterSetupWizardApp construction
84
85 CPrinterSetupWizardApp::CPrinterSetupWizardApp()
86 {
87 // TODO: add construction code here,
88 // Place all significant initialization in InitInstance
89 }
90
91
92 // The one and only CPrinterSetupWizardApp object
93
94 CPrinterSetupWizardApp theApp;
95
96
97 // CPrinterSetupWizardApp initialization
98
99 BOOL CPrinterSetupWizardApp::InitInstance()
100 {
101 CString errorMessage;
102 CString errorCaption;
103 wchar_t resource[MAX_PATH];
104 int res;
105 OSStatus err = kNoErr;
106
107 //
108 // initialize the debugging framework
109 //
110 debug_initialize( kDebugOutputTypeWindowsDebugger, "PrinterSetupWizard", NULL );
111 debug_set_property( kDebugPropertyTagPrintLevel, kDebugLevelTrace );
112
113 // Before we load the resources, let's load the error string
114
115 errorMessage.LoadString( IDS_REINSTALL );
116 errorCaption.LoadString( IDS_REINSTALL_CAPTION );
117
118 // Load Resources
119
120 res = PathForResource( NULL, L"RendezvousPrinterWizard.dll", resource, MAX_PATH );
121 err = translate_errno( res != 0, kUnknownErr, kUnknownErr );
122 require_noerr( err, exit );
123
124 g_nonLocalizedResources = LoadLibrary( resource );
125 translate_errno( g_nonLocalizedResources, GetLastError(), kUnknownErr );
126 require_noerr( err, exit );
127
128 res = PathForResource( NULL, L"RendezvousPrinterWizardLocalized.dll", resource, MAX_PATH );
129 err = translate_errno( res != 0, kUnknownErr, kUnknownErr );
130 require_noerr( err, exit );
131
132 g_localizedResources = LoadLibrary( resource );
133 translate_errno( g_localizedResources, GetLastError(), kUnknownErr );
134 require_noerr( err, exit );
135
136 AfxSetResourceHandle( g_localizedResources );
137
138 // InitCommonControls() is required on Windows XP if an application
139 // manifest specifies use of ComCtl32.dll version 6 or later to enable
140 // visual styles. Otherwise, any window creation will fail.
141 InitCommonControls();
142
143 CWinApp::InitInstance();
144
145 AfxEnableControlContainer();
146
147 {
148 CPrinterSetupWizardSheet dlg(IDS_CAPTION);
149
150 m_pMainWnd = &dlg;
151
152 try
153 {
154 INT_PTR nResponse = dlg.DoModal();
155
156 if (nResponse == IDOK)
157 {
158 // TODO: Place code here to handle when the dialog is
159 // dismissed with OK
160 }
161 else if (nResponse == IDCANCEL)
162 {
163 // TODO: Place code here to handle when the dialog is
164 // dismissed with Cancel
165 }
166 }
167 catch (CPrinterSetupWizardSheet::WizardException & exc)
168 {
169 MessageBox(NULL, exc.text, exc.caption, MB_OK|MB_ICONEXCLAMATION);
170 }
171 }
172
173 exit:
174
175 if ( err )
176 {
177 MessageBox( NULL, errorMessage, errorCaption, MB_ICONERROR | MB_OK );
178 }
179
180 if ( g_nonLocalizedResources )
181 {
182 FreeLibrary( g_nonLocalizedResources );
183 }
184
185 if ( g_localizedResources )
186 {
187 FreeLibrary( g_localizedResources );
188 }
189
190 // Since the dialog has been closed, return FALSE so that we exit the
191 // application, rather than start the application's message pump.
192 return FALSE;
193 }