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