]> git.saurik.com Git - apple/mdnsresponder.git/blame - Clients/PrinterSetupWizard/PrinterSetupWizardApp.cpp
mDNSResponder-320.18.tar.gz
[apple/mdnsresponder.git] / Clients / PrinterSetupWizard / PrinterSetupWizardApp.cpp
CommitLineData
67c8f8a1
A
1/* -*- Mode: C; tab-width: 4 -*-
2 *
7f0064bd
A
3 * Copyright (c) 1997-2004 Apple Computer, Inc. All rights reserved.
4 *
67c8f8a1
A
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
7f0064bd 8 *
67c8f8a1 9 * http://www.apache.org/licenses/LICENSE-2.0
7f0064bd 10 *
67c8f8a1
A
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
7f0064bd 15 * limitations under the License.
263eeeab 16 */
7f0064bd
A
17
18#include "stdafx.h"
19#include "PrinterSetupWizardApp.h"
20#include "PrinterSetupWizardSheet.h"
21#include "DebugServices.h"
283ee3ff 22#include "loclibrary.h"
7f0064bd
A
23
24#ifdef _DEBUG
25#define new DEBUG_NEW
26#endif
27
32bb7e43
A
28#ifndef HeapEnableTerminationOnCorruption
29# define HeapEnableTerminationOnCorruption (HEAP_INFORMATION_CLASS) 1
30#endif
31
32
283ee3ff
A
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
7f0064bd
A
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{
283ee3ff
A
78 CString errorMessage;
79 CString errorCaption;
80 wchar_t resource[MAX_PATH];
81 int res;
82 OSStatus err = kNoErr;
83
32bb7e43
A
84 HeapSetInformation( NULL, HeapEnableTerminationOnCorruption, NULL, 0 );
85
7f0064bd
A
86 //
87 // initialize the debugging framework
88 //
89 debug_initialize( kDebugOutputTypeWindowsDebugger, "PrinterSetupWizard", NULL );
90 debug_set_property( kDebugPropertyTagPrintLevel, kDebugLevelTrace );
91
283ee3ff
A
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
4aea607d 99 res = PathForResource( NULL, L"PrinterWizardResources.dll", resource, MAX_PATH );
283ee3ff
A
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
7cb34e5c 107 res = PathForResource( NULL, L"PrinterWizardLocalized.dll", resource, MAX_PATH );
283ee3ff
A
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 );
7cb34e5c
A
113 require_noerr( err, exit );
114
115 AfxSetResourceHandle( g_localizedResources );
7f0064bd
A
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
283ee3ff
A
126 {
127 CPrinterSetupWizardSheet dlg(IDS_CAPTION);
7f0064bd 128
283ee3ff 129 m_pMainWnd = &dlg;
7f0064bd 130
283ee3ff 131 try
7f0064bd 132 {
283ee3ff
A
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 }
7f0064bd 145 }
283ee3ff 146 catch (CPrinterSetupWizardSheet::WizardException & exc)
7f0064bd 147 {
283ee3ff 148 MessageBox(NULL, exc.text, exc.caption, MB_OK|MB_ICONEXCLAMATION);
7f0064bd
A
149 }
150 }
283ee3ff
A
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 )
7f0064bd 165 {
283ee3ff 166 FreeLibrary( g_localizedResources );
7f0064bd
A
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}