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