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