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