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