]> git.saurik.com Git - wxWidgets.git/blame - src/msw/app.cpp
Unicode fixes
[wxWidgets.git] / src / msw / app.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: app.cpp
3// Purpose: wxApp
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
a5e0e655 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
e5c0b16a
VZ
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
e5c0b16a 21 #pragma implementation "app.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
2bda0e17
KB
25#include "wx/wxprec.h"
26
27#if defined(__BORLANDC__)
e5c0b16a 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
31#ifndef WX_PRECOMP
e5c0b16a
VZ
32 #include "wx/frame.h"
33 #include "wx/app.h"
34 #include "wx/utils.h"
35 #include "wx/gdicmn.h"
36 #include "wx/pen.h"
37 #include "wx/brush.h"
38 #include "wx/cursor.h"
39 #include "wx/icon.h"
40 #include "wx/palette.h"
41 #include "wx/dc.h"
42 #include "wx/dialog.h"
43 #include "wx/msgdlg.h"
44 #include "wx/intl.h"
45 #include "wx/dynarray.h"
72cdf4c9
VZ
46 #include "wx/wxchar.h"
47 #include "wx/icon.h"
2bda0e17
KB
48#endif
49
2bda0e17
KB
50#include "wx/log.h"
51#include "wx/module.h"
4bf78aae 52
4286a5b5
RR
53#include "wx/msw/private.h"
54
4bf78aae 55#if wxUSE_THREADS
bee503b0
VZ
56 #include "wx/thread.h"
57
58 // define the array of MSG strutures
59 WX_DECLARE_OBJARRAY(MSG, wxMsgArray);
60
61 #include "wx/arrimpl.cpp"
62
63 WX_DEFINE_OBJARRAY(wxMsgArray);
64#endif // wxUSE_THREADS
2bda0e17 65
47d67540 66#if wxUSE_WX_RESOURCES
e5c0b16a 67 #include "wx/resource.h"
2bda0e17
KB
68#endif
69
e5c0b16a 70// OLE is used for drag-and-drop, clipboard, OLE Automation...
7dee726c 71#ifndef wxUSE_NORLANDER_HEADERS
e5c0b16a
VZ
72#if defined(__GNUWIN32__) || defined(__SC__) || defined(__SALFORDC__)
73 #undef wxUSE_OLE
74
75 #define wxUSE_OLE 0
76#endif // broken compilers
7dee726c 77#endif
e5c0b16a
VZ
78
79#if wxUSE_OLE
6e0d9d43 80 #include <ole2.h>
d05237ea 81#endif
ce3ed50d 82
2bda0e17 83#include <string.h>
a5e0e655 84#include <ctype.h>
2bda0e17 85
65fd5cb0 86#if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
e5c0b16a 87 #include <commctrl.h>
2bda0e17
KB
88#endif
89
6e0d9d43 90#include "wx/msw/msvcrt.h"
370382c7 91
e5c0b16a
VZ
92// ---------------------------------------------------------------------------
93// global variables
94// ---------------------------------------------------------------------------
95
837e5743
OK
96extern wxChar *wxBuffer;
97extern wxChar *wxOsVersion;
2bda0e17 98extern wxList *wxWinHandleList;
cde9f08e 99extern wxList WXDLLEXPORT wxPendingDelete;
2bda0e17
KB
100extern void wxSetKeyboardHook(bool doIt);
101extern wxCursor *g_globalCursor;
102
c4e7c2aa 103HINSTANCE wxhInstance = 0;
42e69d6b 104MSG s_currentMsg;
2bda0e17
KB
105wxApp *wxTheApp = NULL;
106
e5c0b16a 107// FIXME why not const? and not static?
193fe989
VZ
108
109// NB: all "NoRedraw" classes must have the same names as the "normal" classes
110// with NR suffix - wxWindow::MSWCreate() supposes this
223d09f6
KB
111wxChar wxFrameClassName[] = wxT("wxFrameClass");
112wxChar wxFrameClassNameNoRedraw[] = wxT("wxFrameClassNR");
113wxChar wxMDIFrameClassName[] = wxT("wxMDIFrameClass");
114wxChar wxMDIFrameClassNameNoRedraw[] = wxT("wxMDIFrameClassNR");
115wxChar wxMDIChildFrameClassName[] = wxT("wxMDIChildFrameClass");
116wxChar wxMDIChildFrameClassNameNoRedraw[] = wxT("wxMDIChildFrameClassNR");
117wxChar wxPanelClassName[] = wxT("wxPanelClass");
118wxChar wxCanvasClassName[] = wxT("wxCanvasClass");
2bda0e17 119
57c208c5
JS
120HICON wxSTD_FRAME_ICON = (HICON) NULL;
121HICON wxSTD_MDICHILDFRAME_ICON = (HICON) NULL;
122HICON wxSTD_MDIPARENTFRAME_ICON = (HICON) NULL;
2bda0e17 123
57c208c5
JS
124HICON wxDEFAULT_FRAME_ICON = (HICON) NULL;
125HICON wxDEFAULT_MDICHILDFRAME_ICON = (HICON) NULL;
126HICON wxDEFAULT_MDIPARENTFRAME_ICON = (HICON) NULL;
2bda0e17 127
57c208c5 128HBRUSH wxDisableButtonBrush = (HBRUSH) 0;
2bda0e17 129
3135f4a7 130LRESULT WXDLLEXPORT APIENTRY wxWndProc(HWND, UINT, WPARAM, LPARAM);
2bda0e17 131
57c208c5 132#if defined(__WIN95__) && !defined(__TWIN32__)
e5c0b16a 133 #define wxUSE_RICHEDIT 1
57c208c5 134#else
e5c0b16a 135 #define wxUSE_RICHEDIT 0
57c208c5
JS
136#endif
137
138#if wxUSE_RICHEDIT
e5c0b16a 139 static HINSTANCE gs_hRichEdit = (HINSTANCE) NULL;
2bda0e17
KB
140#endif
141
e5c0b16a
VZ
142// ===========================================================================
143// implementation
144// ===========================================================================
589f0e3e 145
e5c0b16a
VZ
146// ---------------------------------------------------------------------------
147// wxApp
148// ---------------------------------------------------------------------------
149
150#if !USE_SHARED_LIBRARY
151 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
152
153 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
154 EVT_IDLE(wxApp::OnIdle)
155 EVT_END_SESSION(wxApp::OnEndSession)
156 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
157 END_EVENT_TABLE()
158#endif
159
e5c0b16a 160//// Initialize
589f0e3e 161bool wxApp::Initialize()
2bda0e17 162{
c030b70f
JS
163 // Some people may wish to use this, but
164 // probably it shouldn't be here by default.
165#ifdef __WXDEBUG__
e5c0b16a 166 // wxRedirectIOToConsole();
c030b70f
JS
167#endif
168
837e5743 169 wxBuffer = new wxChar[1500]; // FIXME
589f0e3e 170
aa0b7e1e 171 wxClassInfo::InitializeClasses();
589f0e3e 172
aa0b7e1e 173#if wxUSE_RESOURCES
223d09f6 174 wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion);
aa0b7e1e 175#endif
589f0e3e 176
4d3a259a 177#if wxUSE_THREADS
8e193f38 178 wxPendingEventsLocker = new wxCriticalSection;
4d3a259a
GL
179#endif
180
aa0b7e1e
JS
181 wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
182 wxTheColourDatabase->Initialize();
589f0e3e 183
aa0b7e1e
JS
184 wxInitializeStockLists();
185 wxInitializeStockObjects();
589f0e3e 186
aa0b7e1e 187#if wxUSE_WX_RESOURCES
a5e0e655 188 wxInitializeResourceSystem();
aa0b7e1e 189#endif
2bda0e17 190
aa0b7e1e 191 wxBitmap::InitStandardHandlers();
2bda0e17 192
aa0b7e1e 193#if defined(__WIN95__)
a5e0e655 194 InitCommonControls();
57c208c5
JS
195
196#if wxUSE_RICHEDIT
223d09f6 197 gs_hRichEdit = LoadLibrary(wxT("RICHED32.DLL"));
2bda0e17 198
57c208c5 199 if (gs_hRichEdit == (HINSTANCE) NULL)
a5e0e655 200 {
e5c0b16a 201 wxLogError(_("Could not initialise Rich Edit DLL"));
a5e0e655 202 }
e5c0b16a 203#endif // wxUSE_RICHEDIT
57c208c5 204
e5c0b16a 205#endif // __WIN95__
2bda0e17 206
c49245f8
VZ
207#if wxUSE_OLE
208
209#ifdef __WIN16__
e5c0b16a 210 // for OLE, enlarge message queue to be as large as possible
aa0b7e1e 211 int iMsg = 96;
c49245f8
VZ
212 while (!SetMessageQueue(iMsg) && (iMsg -= 8))
213 ;
214#endif // Win16
a5e0e655
VZ
215 // we need to initialize OLE library
216 if ( FAILED(::OleInitialize(NULL)) )
e5c0b16a 217 wxLogError(_("Cannot initialize OLE"));
c49245f8 218#endif // wxUSE_OLE
2bda0e17 219
1f112209 220#if wxUSE_CTL3D
a5e0e655 221 if (!Ctl3dRegister(wxhInstance))
223d09f6 222 wxLogError(wxT("Cannot register CTL3D"));
2bda0e17 223
a5e0e655 224 Ctl3dAutoSubclass(wxhInstance);
aa0b7e1e 225#endif
2bda0e17 226
aa0b7e1e 227 g_globalCursor = new wxCursor;
589f0e3e 228
223d09f6
KB
229 wxSTD_FRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_FRAME"));
230 wxSTD_MDIPARENTFRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_MDIPARENTFRAME"));
231 wxSTD_MDICHILDFRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_MDICHILDFRAME"));
2bda0e17 232
223d09f6
KB
233 wxDEFAULT_FRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_FRAME"));
234 wxDEFAULT_MDIPARENTFRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_MDIPARENTFRAME"));
235 wxDEFAULT_MDICHILDFRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_MDICHILDFRAME"));
2bda0e17 236
aa0b7e1e 237 RegisterWindowClasses();
2bda0e17 238
aa0b7e1e 239 // Create the brush for disabling bitmap buttons
2bda0e17 240
42e69d6b 241 LOGBRUSH lb;
aa0b7e1e 242 lb.lbStyle = BS_PATTERN;
223d09f6 243 lb.lbHatch = (int)LoadBitmap( wxhInstance, wxT("wxDISABLE_BUTTON_BITMAP") );
3a5ffa81
VZ
244 if ( lb.lbHatch )
245 {
246 wxDisableButtonBrush = ::CreateBrushIndirect( & lb );
247 ::DeleteObject( (HGDIOBJ)lb.lbHatch );
248 }
249 //else: wxWindows resources are probably not linked in
2bda0e17 250
aa0b7e1e 251#if wxUSE_PENWINDOWS
a5e0e655 252 wxRegisterPenWin();
aa0b7e1e 253#endif
2bda0e17 254
aa0b7e1e 255 wxWinHandleList = new wxList(wxKEY_INTEGER);
2bda0e17 256
6e0d9d43 257 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
8cbd2bde 258 // PLEASE DO NOT ALTER THIS.
3f4a0c5b 259#if defined(__VISUALC__) && !defined(WXMAKINGDLL)
a5e0e655
VZ
260 extern char wxDummyChar;
261 if (wxDummyChar) wxDummyChar++;
aa0b7e1e 262#endif
a5e0e655 263
aa0b7e1e 264 wxSetKeyboardHook(TRUE);
2bda0e17 265
aa0b7e1e
JS
266 wxModule::RegisterModules();
267 if (!wxModule::InitializeModules())
268 return FALSE;
269 return TRUE;
2bda0e17
KB
270}
271
42e69d6b
VZ
272// ---------------------------------------------------------------------------
273// RegisterWindowClasses
274// ---------------------------------------------------------------------------
589f0e3e 275
b782f2e0
VZ
276// TODO we should only register classes really used by the app. For this it
277// would be enough to just delay the class registration until an attempt
278// to create a window of this class is made.
bb6290e3 279bool wxApp::RegisterWindowClasses()
2bda0e17 280{
42e69d6b 281 WNDCLASS wndclass;
e5c0b16a 282
193fe989
VZ
283 // for each class we register one with CS_(V|H)REDRAW style and one
284 // without for windows created with wxNO_FULL_REDRAW_ON_REPAINT flag
285 static const long styleNormal = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
286 static const long styleNoRedraw = CS_DBLCLKS;
287
42e69d6b 288 // the fields which are common to all classes
e5c0b16a
VZ
289 wndclass.lpfnWndProc = (WNDPROC)wxWndProc;
290 wndclass.cbClsExtra = 0;
193fe989 291 wndclass.cbWndExtra = sizeof( DWORD ); // VZ: what is this DWORD used for?
e5c0b16a 292 wndclass.hInstance = wxhInstance;
42e69d6b
VZ
293 wndclass.hIcon = (HICON) NULL;
294 wndclass.hCursor = ::LoadCursor((HINSTANCE)NULL, IDC_ARROW);
e5c0b16a 295 wndclass.lpszMenuName = NULL;
42e69d6b
VZ
296
297 // Register the frame window class.
298 wndclass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
e5c0b16a 299 wndclass.lpszClassName = wxFrameClassName;
b782f2e0 300 wndclass.style = styleNormal;
e5c0b16a 301
42e69d6b 302 if ( !RegisterClass(&wndclass) )
e5c0b16a 303 {
42e69d6b
VZ
304 wxLogLastError("RegisterClass(frame)");
305
306 return FALSE;
e5c0b16a
VZ
307 }
308
193fe989
VZ
309 // "no redraw" frame
310 wndclass.lpszClassName = wxFrameClassNameNoRedraw;
311 wndclass.style = styleNoRedraw;
312
313 if ( !RegisterClass(&wndclass) )
314 {
315 wxLogLastError("RegisterClass(no redraw frame)");
316
317 return FALSE;
318 }
319
e5c0b16a 320 // Register the MDI frame window class.
42e69d6b 321 wndclass.hbrBackground = (HBRUSH)NULL; // paint MDI frame ourselves
b782f2e0
VZ
322 wndclass.lpszClassName = wxMDIFrameClassName;
323 wndclass.style = styleNormal;
42e69d6b
VZ
324
325 if ( !RegisterClass(&wndclass) )
e5c0b16a 326 {
42e69d6b
VZ
327 wxLogLastError("RegisterClass(MDI parent)");
328
329 return FALSE;
e5c0b16a
VZ
330 }
331
193fe989 332 // "no redraw" MDI frame
b782f2e0 333 wndclass.lpszClassName = wxMDIFrameClassNameNoRedraw;
193fe989
VZ
334 wndclass.style = styleNoRedraw;
335
336 if ( !RegisterClass(&wndclass) )
337 {
338 wxLogLastError("RegisterClass(no redraw MDI parent frame)");
339
340 return FALSE;
341 }
342
e5c0b16a 343 // Register the MDI child frame window class.
42e69d6b
VZ
344 wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
345 wndclass.lpszClassName = wxMDIChildFrameClassName;
b782f2e0 346 wndclass.style = styleNormal;
42e69d6b
VZ
347
348 if ( !RegisterClass(&wndclass) )
e5c0b16a 349 {
42e69d6b
VZ
350 wxLogLastError("RegisterClass(MDI child)");
351
352 return FALSE;
e5c0b16a
VZ
353 }
354
193fe989
VZ
355 // "no redraw" MDI child frame
356 wndclass.lpszClassName = wxMDIChildFrameClassNameNoRedraw;
357 wndclass.style = styleNoRedraw;
358
359 if ( !RegisterClass(&wndclass) )
360 {
361 wxLogLastError("RegisterClass(no redraw MDI child)");
362
363 return FALSE;
364 }
365
e5c0b16a 366 // Register the panel window class.
42e69d6b
VZ
367 wndclass.hbrBackground = (HBRUSH) GetStockObject( LTGRAY_BRUSH );
368 wndclass.lpszClassName = wxPanelClassName;
b782f2e0 369 wndclass.style = styleNormal;
42e69d6b
VZ
370
371 if ( !RegisterClass(&wndclass) )
e5c0b16a 372 {
42e69d6b
VZ
373 wxLogLastError("RegisterClass(panel)");
374
375 return FALSE;
e5c0b16a
VZ
376 }
377
e5c0b16a 378 // Register the canvas and textsubwindow class name
42e69d6b
VZ
379 wndclass.hbrBackground = (HBRUSH)NULL;
380 wndclass.lpszClassName = wxCanvasClassName;
381
382 if ( !RegisterClass(&wndclass) )
e5c0b16a 383 {
42e69d6b
VZ
384 wxLogLastError("RegisterClass(canvas)");
385
386 return FALSE;
e5c0b16a
VZ
387 }
388
389 return TRUE;
2bda0e17
KB
390}
391
42e69d6b
VZ
392// ---------------------------------------------------------------------------
393// Convert Windows to argc, argv style
394// ---------------------------------------------------------------------------
589f0e3e
JS
395
396void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine)
397{
da36f544 398 wxStringList args;
589f0e3e 399
da36f544
JS
400 wxString cmdLine(lpCmdLine);
401 int count = 0;
589f0e3e 402
da36f544 403 // Get application name
837e5743 404 wxChar name[260]; // 260 is MAX_PATH value from windef.h
da36f544
JS
405 ::GetModuleFileName(wxhInstance, name, WXSIZEOF(name));
406
da36f544 407 args.Add(name);
50ef256e 408 count++;
589f0e3e 409
837e5743 410 wxStrcpy(name, wxFileNameFromPath(name));
da36f544
JS
411 wxStripExtension(name);
412 wxTheApp->SetAppName(name);
589f0e3e 413
da36f544
JS
414 // Break up string
415 // Treat strings enclosed in double-quotes as single arguments
416 int i = 0;
417 int len = cmdLine.Length();
418 while (i < len)
a5e0e655 419 {
da36f544 420 // Skip whitespace
837e5743 421 while ((i < len) && wxIsspace(cmdLine.GetChar(i)))
da36f544
JS
422 i ++;
423
424 if (i < len)
425 {
223d09f6 426 if (cmdLine.GetChar(i) == wxT('"')) // We found the start of a string
da36f544
JS
427 {
428 i ++;
429 int first = i;
223d09f6 430 while ((i < len) && (cmdLine.GetChar(i) != wxT('"')))
da36f544
JS
431 i ++;
432
433 wxString arg(cmdLine.Mid(first, (i - first)));
434
435 args.Add(arg);
436 count ++;
437
438 if (i < len)
439 i ++; // Skip past 2nd quote
440 }
441 else // Unquoted argument
442 {
443 int first = i;
837e5743 444 while ((i < len) && !wxIsspace(cmdLine.GetChar(i)))
da36f544
JS
445 i ++;
446
447 wxString arg(cmdLine.Mid(first, (i - first)));
448
449 args.Add(arg);
450 count ++;
451 }
452 }
a5e0e655 453 }
a5e0e655 454
837e5743 455 wxTheApp->argv = new wxChar*[count + 1];
da36f544 456 for (i = 0; i < count; i++)
a5e0e655 457 {
da36f544 458 wxString arg(args[i]);
837e5743 459 wxTheApp->argv[i] = copystring((const wxChar*)arg);
a5e0e655 460 }
da36f544
JS
461 wxTheApp->argv[count] = NULL; // argv[] is a NULL-terminated list
462 wxTheApp->argc = count;
589f0e3e
JS
463}
464
465//// Cleans up any wxWindows internal structures left lying around
466
bb6290e3 467void wxApp::CleanUp()
2bda0e17 468{
e5c0b16a
VZ
469 //// COMMON CLEANUP
470
546db2a8 471#if wxUSE_LOG
e5c0b16a
VZ
472 // flush the logged messages if any and install a 'safer' log target: the
473 // default one (wxLogGui) can't be used after the resources are freed just
474 // below and the user suppliedo ne might be even more unsafe (using any
475 // wxWindows GUI function is unsafe starting from now)
476 wxLog::DontCreateOnDemand();
f5e5bd66 477
e5c0b16a
VZ
478 // this will flush the old messages if any
479 delete wxLog::SetActiveTarget(new wxLogStderr);
546db2a8 480#endif // wxUSE_LOG
f5e5bd66 481
e5c0b16a
VZ
482 // One last chance for pending objects to be cleaned up
483 wxTheApp->DeletePendingObjects();
f5e5bd66 484
e5c0b16a 485 wxModule::CleanUpModules();
2bda0e17 486
47d67540 487#if wxUSE_WX_RESOURCES
e5c0b16a 488 wxCleanUpResourceSystem();
589f0e3e 489
e5c0b16a 490 // wxDefaultResourceTable->ClearTable();
589f0e3e
JS
491#endif
492
e5c0b16a
VZ
493 // Indicate that the cursor can be freed, so that cursor won't be deleted
494 // by deleting the bitmap list before g_globalCursor goes out of scope
495 // (double deletion of the cursor).
496 wxSetCursor(wxNullCursor);
497 delete g_globalCursor;
2a47d3c1 498 g_globalCursor = NULL;
589f0e3e 499
42e69d6b 500 wxDeleteStockObjects();
589f0e3e 501
e5c0b16a
VZ
502 // Destroy all GDI lists, etc.
503 wxDeleteStockLists();
589f0e3e 504
e5c0b16a
VZ
505 delete wxTheColourDatabase;
506 wxTheColourDatabase = NULL;
589f0e3e 507
e5c0b16a 508 wxBitmap::CleanUpHandlers();
589f0e3e 509
e5c0b16a
VZ
510 delete[] wxBuffer;
511 wxBuffer = NULL;
589f0e3e 512
e5c0b16a 513 //// WINDOWS-SPECIFIC CLEANUP
2bda0e17 514
e5c0b16a 515 wxSetKeyboardHook(FALSE);
2bda0e17
KB
516
517#ifdef __WIN95__
57c208c5
JS
518
519#if wxUSE_RICHEDIT
e5c0b16a
VZ
520 if (gs_hRichEdit != (HINSTANCE) NULL)
521 FreeLibrary(gs_hRichEdit);
2bda0e17
KB
522#endif
523
57c208c5
JS
524#endif
525
47d67540 526#if wxUSE_PENWINDOWS
e5c0b16a 527 wxCleanUpPenWin();
2bda0e17
KB
528#endif
529
e5c0b16a
VZ
530 if (wxSTD_FRAME_ICON)
531 DestroyIcon(wxSTD_FRAME_ICON);
532 if (wxSTD_MDICHILDFRAME_ICON)
533 DestroyIcon(wxSTD_MDICHILDFRAME_ICON);
534 if (wxSTD_MDIPARENTFRAME_ICON)
535 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON);
536
537 if (wxDEFAULT_FRAME_ICON)
538 DestroyIcon(wxDEFAULT_FRAME_ICON);
539 if (wxDEFAULT_MDICHILDFRAME_ICON)
540 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON);
541 if (wxDEFAULT_MDIPARENTFRAME_ICON)
542 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON);
543
544 if ( wxDisableButtonBrush )
42e69d6b 545 ::DeleteObject( wxDisableButtonBrush );
e5c0b16a
VZ
546
547#if wxUSE_OLE
548 ::OleUninitialize();
5de5db0e 549#endif
2bda0e17 550
1f112209 551#if wxUSE_CTL3D
e5c0b16a 552 Ctl3dUnregister(wxhInstance);
2bda0e17
KB
553#endif
554
e5c0b16a 555 if (wxWinHandleList)
42e69d6b 556 delete wxWinHandleList;
d50b2a58 557
3135f4a7 558 // GL: I'm annoyed ... I don't know where to put this and I don't want to
4d3a259a 559 // create a module for that as it's part of the core.
4d3a259a 560 delete wxPendingEvents;
8e193f38 561#if wxUSE_THREADS
4d3a259a 562 delete wxPendingEventsLocker;
63863e09
JS
563 // If we don't do the following, we get an apparent memory leak.
564 ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker();
4d3a259a
GL
565#endif
566
e5c0b16a 567 wxClassInfo::CleanUpClasses();
0c32066b 568
e5c0b16a
VZ
569 delete wxTheApp;
570 wxTheApp = NULL;
184b5d99
JS
571
572#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
e5c0b16a
VZ
573 // At this point we want to check if there are any memory
574 // blocks that aren't part of the wxDebugContext itself,
575 // as a special case. Then when dumping we need to ignore
576 // wxDebugContext, too.
d13c32e9 577 if (wxDebugContext::CountObjectsLeft(TRUE) > 0)
e5c0b16a 578 {
223d09f6 579 wxLogDebug(wxT("There were memory leaks."));
e5c0b16a
VZ
580 wxDebugContext::Dump();
581 wxDebugContext::PrintStatistics();
582 }
583 // wxDebugContext::SetStream(NULL, NULL);
184b5d99
JS
584#endif
585
546db2a8 586#if wxUSE_LOG
e5c0b16a
VZ
587 // do it as the very last thing because everything else can log messages
588 delete wxLog::SetActiveTarget(NULL);
546db2a8 589#endif // wxUSE_LOG
2bda0e17
KB
590}
591
2bda0e17
KB
592#if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
593
e5c0b16a
VZ
594// temporarily disable this warning which would be generated in release builds
595// because of __try
3f4a0c5b 596#ifdef __VISUALC__
f8a3e080
VZ
597 #pragma warning(disable: 4715) // not all control paths return a value
598#endif // Visual C++
599
589f0e3e 600//// Main wxWindows entry point
a5e0e655
VZ
601int wxEntry(WXHINSTANCE hInstance,
602 WXHINSTANCE WXUNUSED(hPrevInstance),
603 char *lpCmdLine,
604 int nCmdShow,
605 bool enterLoop)
2bda0e17 606{
6e0d9d43
VZ
607 // do check for memory leaks on program exit
608 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
609 // deallocated memory which may be used to simulate low-memory condition)
610 wxCrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
611
e5c0b16a
VZ
612 // take everything into a try-except block in release build
613 // FIXME other compilers must support Win32 SEH (structured exception
614 // handling) too, just find the appropriate keyword in their docs!
615 // Please note that it's _not_ the same as C++ exceptions!
3f4a0c5b 616#if !defined(__WXDEBUG__) && defined(__VISUALC__)
f8a3e080
VZ
617 #define CATCH_PROGRAM_EXCEPTIONS
618
3f4a0c5b 619 __try {
f8a3e080
VZ
620#else
621 #undef CATCH_PROGRAM_EXCEPTIONS
a5e0e655
VZ
622#endif
623
e5c0b16a 624 wxhInstance = (HINSTANCE) hInstance;
2bda0e17 625
e5c0b16a
VZ
626 if (!wxApp::Initialize())
627 return 0;
2bda0e17 628
e5c0b16a
VZ
629 // create the application object or ensure that one already exists
630 if (!wxTheApp)
631 {
632 // The app may have declared a global application object, but we recommend
633 // the IMPLEMENT_APP macro is used instead, which sets an initializer
634 // function for delayed, dynamic app object construction.
635 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
223d09f6 636 wxT("No initializer - use IMPLEMENT_APP macro.") );
f8a3e080 637
e5c0b16a
VZ
638 wxTheApp = (*wxApp::GetInitializerFunction()) ();
639 }
640
223d09f6 641 wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
e5c0b16a
VZ
642
643 // save the WinMain() parameters
644 wxTheApp->ConvertToStandardCommandArgs(lpCmdLine);
645 wxTheApp->m_nCmdShow = nCmdShow;
a5e0e655 646
e5c0b16a
VZ
647 // GUI-specific initialisation. In fact on Windows we don't have any,
648 // but this call is provided for compatibility across platforms.
42e69d6b 649 wxTheApp->OnInitGui();
f8a3e080 650
36edded9
JS
651 // We really don't want timestamps by default, because it means
652 // we can't simply double-click on the error message and get to that
653 // line in the source. So VC++ at least, let's have a sensible default.
654#ifdef __VISUALC__
655 wxLog::SetTimestamp(NULL);
656#endif
657
e5c0b16a
VZ
658 int retValue = 0;
659
660 if ( wxTheApp->OnInit() )
661 {
662 if ( enterLoop )
663 {
664 retValue = wxTheApp->OnRun();
665 }
666 else
667 // We want to initialize, but not run or exit immediately.
668 return 1;
669 }
670 //else: app initialization failed, so we skipped OnRun()
671
672 wxWindow *topWindow = wxTheApp->GetTopWindow();
673 if ( topWindow )
674 {
675 // Forcibly delete the window.
676 if ( topWindow->IsKindOf(CLASSINFO(wxFrame)) ||
677 topWindow->IsKindOf(CLASSINFO(wxDialog)) )
678 {
679 topWindow->Close(TRUE);
680 wxTheApp->DeletePendingObjects();
681 }
682 else
683 {
684 delete topWindow;
685 wxTheApp->SetTopWindow(NULL);
686 }
687 }
688
689 wxTheApp->OnExit();
690
691 wxApp::CleanUp();
692
693 return retValue;
694
695#ifdef CATCH_PROGRAM_EXCEPTIONS
696 }
697 __except ( EXCEPTION_EXECUTE_HANDLER ) {
698 /*
699 if ( wxTheApp )
700 wxTheApp->OnFatalException();
701 */
702
703 // using wxLog would be unsafe here
704 ::MessageBox(NULL,
705 _("Unrecoverable program error detected: "
706 " the application will terminate."),
707 _("Fatal Error"),
708 MB_APPLMODAL | MB_ICONSTOP | MB_OK);
709
710 ::ExitProcess(3); // the same exit code as abort()
711
712 // NOTREACHED
713 }
f8a3e080 714#endif // CATCH_PROGRAM_EXCEPTIONS
2bda0e17
KB
715}
716
f8a3e080 717// restore warning state
3f4a0c5b 718#ifdef __VISUALC__
f8a3e080
VZ
719 #pragma warning(default: 4715) // not all control paths return a value
720#endif // Visual C++
721
2bda0e17
KB
722#else /* _WINDLL */
723
589f0e3e
JS
724//// Entry point for DLLs
725
2bda0e17
KB
726int wxEntry(WXHINSTANCE hInstance)
727{
e5c0b16a
VZ
728 wxhInstance = (HINSTANCE) hInstance;
729 wxApp::Initialize();
2bda0e17 730
e5c0b16a
VZ
731 // The app may have declared a global application object, but we recommend
732 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
733 // for delayed, dynamic app object construction.
734 if (!wxTheApp)
a5e0e655 735 {
e5c0b16a
VZ
736 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
737 "No initializer - use IMPLEMENT_APP macro." );
2bda0e17 738
e5c0b16a
VZ
739 wxTheApp = (* wxApp::GetInitializerFunction()) ();
740 }
2bda0e17 741
e5c0b16a 742 wxCHECK_MSG( wxTheApp, 0, "You have to define an instance of wxApp!" );
2bda0e17 743
e5c0b16a
VZ
744 wxTheApp->argc = 0;
745 wxTheApp->argv = NULL;
2bda0e17 746
e5c0b16a 747 wxTheApp->OnInitGui();
2bda0e17 748
e5c0b16a 749 wxTheApp->OnInit();
2bda0e17 750
e5c0b16a
VZ
751 wxWindow *topWindow = wxTheApp->GetTopWindow();
752 if ( topWindow && topWindow->GetHWND())
753 {
754 topWindow->Show(TRUE);
755 }
2bda0e17 756
e5c0b16a 757 return 1;
2bda0e17
KB
758}
759#endif // _WINDLL
760
589f0e3e
JS
761//// Static member initialization
762
c94ad3c3 763wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL;
2bda0e17 764
bb6290e3 765wxApp::wxApp()
2bda0e17 766{
e5c0b16a
VZ
767 m_topWindow = NULL;
768 wxTheApp = this;
42e69d6b
VZ
769 m_wantDebugOutput = TRUE;
770
e5c0b16a
VZ
771 argc = 0;
772 argv = NULL;
e5c0b16a 773 m_printMode = wxPRINT_WINDOWS;
e5c0b16a
VZ
774 m_exitOnFrameDelete = TRUE;
775 m_auto3D = TRUE;
2bda0e17
KB
776}
777
589f0e3e
JS
778wxApp::~wxApp()
779{
e5c0b16a
VZ
780 // Delete command-line args
781 int i;
782 for (i = 0; i < argc; i++)
783 {
784 delete[] argv[i];
785 }
786 delete[] argv;
589f0e3e
JS
787}
788
bb6290e3 789bool wxApp::Initialized()
2bda0e17
KB
790{
791#ifndef _WINDLL
e5c0b16a
VZ
792 if (GetTopWindow())
793 return TRUE;
794 else
795 return FALSE;
2bda0e17
KB
796#endif
797#ifdef _WINDLL // Assume initialized if DLL (no way of telling)
e5c0b16a 798 return TRUE;
2bda0e17
KB
799#endif
800}
801
802/*
803 * Get and process a message, returning FALSE if WM_QUIT
bee503b0 804 * received (and also set the flag telling the app to exit the main loop)
2bda0e17
KB
805 *
806 */
bb6290e3 807bool wxApp::DoMessage()
2bda0e17 808{
bee503b0
VZ
809 BOOL rc = ::GetMessage(&s_currentMsg, (HWND) NULL, 0, 0);
810 if ( rc == 0 )
811 {
812 // got WM_QUIT
813 m_keepGoing = FALSE;
4a9968f9 814
bee503b0
VZ
815 return FALSE;
816 }
817 else if ( rc == -1 )
818 {
819 // should never happen, but let's test for it nevertheless
820 wxLogLastError("GetMessage");
821 }
822 else
823 {
824#if wxUSE_THREADS
825 wxASSERT_MSG( wxThread::IsMain(),
223d09f6 826 wxT("only the main thread can process Windows messages") );
d50b2a58 827
bee503b0
VZ
828 static bool s_hadGuiLock = TRUE;
829 static wxMsgArray s_aSavedMessages;
830
831 // if a secondary thread owns is doing GUI calls, save all messages for
832 // later processing - we can't process them right now because it will
833 // lead to recursive library calls (and we're not reentrant)
834 if ( !wxGuiOwnedByMainThread() )
835 {
836 s_hadGuiLock = FALSE;
837
4a9968f9
VZ
838 // leave out WM_COMMAND messages: too dangerous, sometimes
839 // the message will be processed twice
840 if ( !wxIsWaitingForThread() ||
e5c0b16a 841 s_currentMsg.message != WM_COMMAND )
4a9968f9
VZ
842 {
843 s_aSavedMessages.Add(s_currentMsg);
844 }
bee503b0
VZ
845
846 return TRUE;
847 }
848 else
849 {
850 // have we just regained the GUI lock? if so, post all of the saved
851 // messages
852 //
853 // FIXME of course, it's not _exactly_ the same as processing the
854 // messages normally - expect some things to break...
855 if ( !s_hadGuiLock )
856 {
857 s_hadGuiLock = TRUE;
858
859 size_t count = s_aSavedMessages.Count();
860 for ( size_t n = 0; n < count; n++ )
861 {
862 MSG& msg = s_aSavedMessages[n];
863
864 if ( !ProcessMessage((WXMSG *)&msg) )
865 {
866 ::TranslateMessage(&msg);
867 ::DispatchMessage(&msg);
868 }
869 }
870
871 s_aSavedMessages.Empty();
872 }
873 }
874#endif // wxUSE_THREADS
875
876 // Process the message
877 if ( !ProcessMessage((WXMSG *)&s_currentMsg) )
878 {
879 ::TranslateMessage(&s_currentMsg);
bee503b0
VZ
880 ::DispatchMessage(&s_currentMsg);
881 }
882 }
883
884 return TRUE;
2bda0e17
KB
885}
886
887/*
888 * Keep trying to process messages until WM_QUIT
889 * received.
890 *
891 * If there are messages to be processed, they will all be
892 * processed and OnIdle will not be called.
893 * When there are no more messages, OnIdle is called.
894 * If OnIdle requests more time,
895 * it will be repeatedly called so long as there are no pending messages.
896 * A 'feature' of this is that once OnIdle has decided that no more processing
897 * is required, then it won't get processing time until further messages
898 * are processed (it'll sit in DoMessage).
899 */
900
bb6290e3 901int wxApp::MainLoop()
2bda0e17 902{
e5c0b16a 903 m_keepGoing = TRUE;
bee503b0 904
e5c0b16a
VZ
905 while ( m_keepGoing )
906 {
907#if wxUSE_THREADS
bee503b0 908 wxMutexGuiLeaveOrEnter();
e5c0b16a 909#endif // wxUSE_THREADS
bee503b0 910
e5c0b16a
VZ
911 while ( !::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) &&
912 ProcessIdle() )
913 {
914 }
bee503b0 915
7214297d 916
e5c0b16a
VZ
917 DoMessage();
918 }
2bda0e17 919
e5c0b16a 920 return s_currentMsg.wParam;
2bda0e17
KB
921}
922
923// Returns TRUE if more time is needed.
bb6290e3 924bool wxApp::ProcessIdle()
2bda0e17
KB
925{
926 wxIdleEvent event;
927 event.SetEventObject(this);
928 ProcessEvent(event);
929
930 return event.MoreRequested();
931}
932
bb6290e3 933void wxApp::ExitMainLoop()
2bda0e17 934{
e5c0b16a 935 m_keepGoing = FALSE;
2bda0e17
KB
936}
937
bb6290e3 938bool wxApp::Pending()
2bda0e17 939{
42e69d6b 940 return (::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) != 0);
2bda0e17
KB
941}
942
bb6290e3 943void wxApp::Dispatch()
2bda0e17 944{
bee503b0 945 DoMessage();
2bda0e17
KB
946}
947
948/*
949 * Give all windows a chance to preprocess
950 * the message. Some may have accelerator tables, or have
951 * MDI complications.
952 */
2a47d3c1 953
d3f0a137 954bool wxApp::ProcessMessage(WXMSG *wxmsg)
2bda0e17 955{
d3f0a137
VZ
956 MSG *msg = (MSG *)wxmsg;
957 HWND hWnd = msg->hwnd;
958 wxWindow *wndThis = wxFindWinFromHandle((WXHWND)hWnd), *wnd;
2bda0e17 959
834362a2
VZ
960 // for some composite controls (like a combobox), wndThis might be NULL
961 // because the subcontrol is not a wxWindow, but only the control itself
962 // is - try to catch this case
963 while ( hWnd && !wndThis )
964 {
965 hWnd = ::GetParent(hWnd);
3135f4a7 966 wndThis = wxFindWinFromHandle((WXHWND)hWnd);
834362a2
VZ
967 }
968
e5c0b16a
VZ
969 // Try translations first; find the youngest window with
970 // a translation table.
d3f0a137 971 for ( wnd = wndThis; wnd; wnd = wnd->GetParent() )
2bda0e17 972 {
d3f0a137
VZ
973 if ( wnd->MSWTranslateMessage(wxmsg) )
974 return TRUE;
2bda0e17 975 }
2bda0e17 976
e5c0b16a 977 // Anyone for a non-translation message? Try youngest descendants first.
d3f0a137 978 for ( wnd = wndThis; wnd; wnd = wnd->GetParent() )
57a7b7c1 979 {
d3f0a137
VZ
980 if ( wnd->MSWProcessMessage(wxmsg) )
981 return TRUE;
57a7b7c1 982 }
d3f0a137 983
e5c0b16a 984 return FALSE;
2bda0e17
KB
985}
986
987void wxApp::OnIdle(wxIdleEvent& event)
988{
3222fde2 989 static bool s_inOnIdle = FALSE;
2bda0e17 990
3222fde2
VZ
991 // Avoid recursion (via ProcessEvent default case)
992 if ( s_inOnIdle )
993 return;
2bda0e17 994
3222fde2 995 s_inOnIdle = TRUE;
2bda0e17 996
3222fde2
VZ
997 // 'Garbage' collection of windows deleted with Close().
998 DeletePendingObjects();
2bda0e17 999
546db2a8 1000#if wxUSE_LOG
3222fde2
VZ
1001 // flush the logged messages if any
1002 wxLog *pLog = wxLog::GetActiveTarget();
1003 if ( pLog != NULL && pLog->HasPendingMessages() )
1004 pLog->Flush();
546db2a8 1005#endif // wxUSE_LOG
c54f78a2 1006
3222fde2
VZ
1007 // Send OnIdle events to all windows
1008 if ( SendIdleEvents() )
1009 {
1010 // SendIdleEvents() returns TRUE if at least one window requested more
1011 // idle events
1012 event.RequestMore(TRUE);
1013 }
2bda0e17 1014
8e193f38
VZ
1015 // If they are pending events, we must process them: pending events are
1016 // either events to the threads other than main or events posted with
1017 // wxPostEvent() functions
aadbdf11 1018 ProcessPendingEvents();
8e193f38 1019
3222fde2 1020 s_inOnIdle = FALSE;
2bda0e17
KB
1021}
1022
1023// Send idle event to all top-level windows
bb6290e3 1024bool wxApp::SendIdleEvents()
2bda0e17
KB
1025{
1026 bool needMore = FALSE;
e146b8c8 1027
f1d534df 1028 wxWindowList::Node* node = wxTopLevelWindows.GetFirst();
3222fde2
VZ
1029 while (node)
1030 {
e146b8c8 1031 wxWindow* win = node->GetData();
3222fde2 1032 if (SendIdleEvents(win))
2bda0e17 1033 needMore = TRUE;
e146b8c8 1034 node = node->GetNext();
3222fde2
VZ
1035 }
1036
2bda0e17
KB
1037 return needMore;
1038}
1039
1040// Send idle event to window and all subwindows
1041bool wxApp::SendIdleEvents(wxWindow* win)
1042{
e5c0b16a 1043 bool needMore = FALSE;
2bda0e17 1044
e5c0b16a
VZ
1045 wxIdleEvent event;
1046 event.SetEventObject(win);
1047 win->GetEventHandler()->ProcessEvent(event);
2bda0e17 1048
e5c0b16a
VZ
1049 if (event.MoreRequested())
1050 needMore = TRUE;
2bda0e17 1051
e5c0b16a
VZ
1052 wxNode* node = win->GetChildren().First();
1053 while (node)
1054 {
1055 wxWindow* win = (wxWindow*) node->Data();
1056 if (SendIdleEvents(win))
1057 needMore = TRUE;
2bda0e17 1058
e5c0b16a
VZ
1059 node = node->Next();
1060 }
42e69d6b 1061 return needMore;
2bda0e17
KB
1062}
1063
bb6290e3 1064void wxApp::DeletePendingObjects()
2bda0e17 1065{
e5c0b16a
VZ
1066 wxNode *node = wxPendingDelete.First();
1067 while (node)
1068 {
1069 wxObject *obj = (wxObject *)node->Data();
d50b2a58 1070
e5c0b16a 1071 delete obj;
2bda0e17 1072
e5c0b16a
VZ
1073 if (wxPendingDelete.Member(obj))
1074 delete node;
2bda0e17 1075
e5c0b16a
VZ
1076 // Deleting one object may have deleted other pending
1077 // objects, so start from beginning of list again.
1078 node = wxPendingDelete.First();
1079 }
2bda0e17
KB
1080}
1081
57c208c5 1082void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
387a3b02
JS
1083{
1084 if (GetTopWindow())
1085 GetTopWindow()->Close(TRUE);
1086}
1087
1088// Default behaviour: close the application with prompts. The
1089// user can veto the close, and therefore the end session.
1090void wxApp::OnQueryEndSession(wxCloseEvent& event)
1091{
1092 if (GetTopWindow())
1093 {
1094 if (!GetTopWindow()->Close(!event.CanVeto()))
1095 event.Veto(TRUE);
1096 }
1097}
1098
bb6290e3
JS
1099int wxApp::GetComCtl32Version() const
1100{
1101 // have we loaded COMCTL32 yet?
223d09f6 1102 HMODULE theModule = ::GetModuleHandle(wxT("COMCTL32"));
bb6290e3 1103 int version = 0;
d50b2a58 1104
bb6290e3
JS
1105 // if so, then we can check for the version
1106 if (theModule)
1107 {
1108 // InitCommonControlsEx is unique to 4.7 and later
1109 FARPROC theProc = ::GetProcAddress(theModule, "InitCommonControlsEx");
d50b2a58 1110
bb6290e3
JS
1111 if (! theProc)
1112 { // not found, must be 4.00
e5c0b16a 1113 version = 400;
bb6290e3
JS
1114 }
1115 else
1116 {
e5c0b16a
VZ
1117 // The following symbol are unique to 4.71
1118 // DllInstall
1119 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
1120 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
1121 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
1122 // FlatSB_ShowScrollBar
1123 // _DrawIndirectImageList _DuplicateImageList
1124 // InitializeFlatSB
1125 // UninitializeFlatSB
1126 // we could check for any of these - I chose DllInstall
1127 FARPROC theProc = ::GetProcAddress(theModule, "DllInstall");
1128 if (! theProc)
1129 {
1130 // not found, must be 4.70
1131 version = 470;
1132 }
1133 else
1134 { // found, must be 4.71
1135 version = 471;
1136 }
bb6290e3
JS
1137 }
1138 }
1139 return version;
1140}
1141
1142void wxExit()
2bda0e17 1143{
e5c0b16a
VZ
1144 wxLogError(_("Fatal error: exiting"));
1145
1146 wxApp::CleanUp();
2bda0e17
KB
1147}
1148
1149// Yield to incoming messages
bb6290e3 1150bool wxYield()
2bda0e17 1151{
8e193f38
VZ
1152 // we don't want to process WM_QUIT from here - it should be processed in
1153 // the main event loop in order to stop it
1154
e5c0b16a 1155 MSG msg;
8e193f38
VZ
1156 while ( PeekMessage(&msg, (HWND)0, 0, 0, PM_NOREMOVE) &&
1157 msg.message != WM_QUIT )
e5c0b16a
VZ
1158 {
1159 if ( !wxTheApp->DoMessage() )
1160 break;
1161 }
8e193f38 1162
aadbdf11 1163 // If they are pending events, we must process them.
6a2f3103 1164 wxTheApp->ProcessPendingEvents();
e5c0b16a
VZ
1165
1166 return TRUE;
2bda0e17 1167}
094637f6 1168
ebea0891
KB
1169wxIcon
1170wxApp::GetStdIcon(int which) const
1171{
094637f6
VZ
1172 switch(which)
1173 {
1174 case wxICON_INFORMATION:
1175 return wxIcon("wxICON_INFO");
1176
1177 case wxICON_QUESTION:
1178 return wxIcon("wxICON_QUESTION");
1179
1180 case wxICON_EXCLAMATION:
1181 return wxIcon("wxICON_WARNING");
1182
1183 default:
223d09f6 1184 wxFAIL_MSG(wxT("requested non existent standard icon"));
094637f6
VZ
1185 // still fall through
1186
1187 case wxICON_HAND:
1188 return wxIcon("wxICON_ERROR");
1189 }
ebea0891
KB
1190}
1191
2bda0e17
KB
1192
1193HINSTANCE wxGetInstance()
1194{
e5c0b16a 1195 return wxhInstance;
2bda0e17
KB
1196}
1197
b97b1af8
RD
1198void wxSetInstance(HINSTANCE hInst)
1199{
1200 wxhInstance = hInst;
1201}
1202
2bda0e17
KB
1203// For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
1204// if in a separate file. So include it here to ensure it's linked.
3f4a0c5b 1205#if (defined(__VISUALC__) && !defined(__WIN32__)) || (defined(__GNUWIN32__) && !defined(__TWIN32__))
e5c0b16a 1206#include "main.cpp"
2bda0e17 1207#endif