]> git.saurik.com Git - wxWidgets.git/blame - src/msw/app.cpp
String changes for translations,
[wxWidgets.git] / src / msw / app.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: app.cpp
3// Purpose: wxApp
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
a5e0e655 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
e5c0b16a
VZ
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
e5c0b16a 21 #pragma implementation "app.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
2bda0e17
KB
25#include "wx/wxprec.h"
26
27#if defined(__BORLANDC__)
e5c0b16a 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
31#ifndef WX_PRECOMP
e5c0b16a
VZ
32 #include "wx/frame.h"
33 #include "wx/app.h"
34 #include "wx/utils.h"
35 #include "wx/gdicmn.h"
36 #include "wx/pen.h"
37 #include "wx/brush.h"
38 #include "wx/cursor.h"
39 #include "wx/icon.h"
40 #include "wx/palette.h"
41 #include "wx/dc.h"
42 #include "wx/dialog.h"
43 #include "wx/msgdlg.h"
44 #include "wx/intl.h"
45 #include "wx/dynarray.h"
72cdf4c9
VZ
46 #include "wx/wxchar.h"
47 #include "wx/icon.h"
2bda0e17
KB
48#endif
49
2bda0e17
KB
50#include "wx/log.h"
51#include "wx/module.h"
4bf78aae 52
4286a5b5
RR
53#include "wx/msw/private.h"
54
4bf78aae 55#if wxUSE_THREADS
bee503b0
VZ
56 #include "wx/thread.h"
57
58 // define the array of MSG strutures
59 WX_DECLARE_OBJARRAY(MSG, wxMsgArray);
60
61 #include "wx/arrimpl.cpp"
62
63 WX_DEFINE_OBJARRAY(wxMsgArray);
64#endif // wxUSE_THREADS
2bda0e17 65
47d67540 66#if wxUSE_WX_RESOURCES
e5c0b16a 67 #include "wx/resource.h"
2bda0e17
KB
68#endif
69
e5c0b16a 70// OLE is used for drag-and-drop, clipboard, OLE Automation...
7dee726c 71#ifndef wxUSE_NORLANDER_HEADERS
e5c0b16a
VZ
72#if defined(__GNUWIN32__) || defined(__SC__) || defined(__SALFORDC__)
73 #undef wxUSE_OLE
74
75 #define wxUSE_OLE 0
76#endif // broken compilers
7dee726c 77#endif
e5c0b16a
VZ
78
79#if wxUSE_OLE
6e0d9d43 80 #include <ole2.h>
d05237ea 81#endif
ce3ed50d 82
2bda0e17 83#include <string.h>
a5e0e655 84#include <ctype.h>
2bda0e17 85
65fd5cb0 86#if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
e5c0b16a 87 #include <commctrl.h>
2bda0e17
KB
88#endif
89
6e0d9d43 90#include "wx/msw/msvcrt.h"
370382c7 91
e5c0b16a
VZ
92// ---------------------------------------------------------------------------
93// global variables
94// ---------------------------------------------------------------------------
95
837e5743
OK
96extern wxChar *wxBuffer;
97extern wxChar *wxOsVersion;
2bda0e17 98extern wxList *wxWinHandleList;
cde9f08e 99extern wxList WXDLLEXPORT wxPendingDelete;
2bda0e17
KB
100extern void wxSetKeyboardHook(bool doIt);
101extern wxCursor *g_globalCursor;
102
42e69d6b 103MSG s_currentMsg;
2bda0e17
KB
104wxApp *wxTheApp = NULL;
105
e5c0b16a 106// FIXME why not const? and not static?
193fe989
VZ
107
108// NB: all "NoRedraw" classes must have the same names as the "normal" classes
109// with NR suffix - wxWindow::MSWCreate() supposes this
223d09f6
KB
110wxChar wxFrameClassName[] = wxT("wxFrameClass");
111wxChar wxFrameClassNameNoRedraw[] = wxT("wxFrameClassNR");
112wxChar wxMDIFrameClassName[] = wxT("wxMDIFrameClass");
113wxChar wxMDIFrameClassNameNoRedraw[] = wxT("wxMDIFrameClassNR");
114wxChar wxMDIChildFrameClassName[] = wxT("wxMDIChildFrameClass");
115wxChar wxMDIChildFrameClassNameNoRedraw[] = wxT("wxMDIChildFrameClassNR");
116wxChar wxPanelClassName[] = wxT("wxPanelClass");
117wxChar wxCanvasClassName[] = wxT("wxCanvasClass");
2bda0e17 118
57c208c5
JS
119HICON wxSTD_FRAME_ICON = (HICON) NULL;
120HICON wxSTD_MDICHILDFRAME_ICON = (HICON) NULL;
121HICON wxSTD_MDIPARENTFRAME_ICON = (HICON) NULL;
2bda0e17 122
57c208c5
JS
123HICON wxDEFAULT_FRAME_ICON = (HICON) NULL;
124HICON wxDEFAULT_MDICHILDFRAME_ICON = (HICON) NULL;
125HICON wxDEFAULT_MDIPARENTFRAME_ICON = (HICON) NULL;
2bda0e17 126
57c208c5 127HBRUSH wxDisableButtonBrush = (HBRUSH) 0;
2bda0e17 128
3135f4a7 129LRESULT WXDLLEXPORT APIENTRY wxWndProc(HWND, UINT, WPARAM, LPARAM);
2bda0e17 130
57c208c5 131#if wxUSE_RICHEDIT
6d167489
VZ
132 // the handle to richedit DLL and the version of the DLL loaded
133 static HINSTANCE gs_hRichEdit = (HINSTANCE)NULL;
134 static int gs_verRichEdit = -1;
2bda0e17
KB
135#endif
136
e5c0b16a
VZ
137// ===========================================================================
138// implementation
139// ===========================================================================
589f0e3e 140
e5c0b16a
VZ
141// ---------------------------------------------------------------------------
142// wxApp
143// ---------------------------------------------------------------------------
144
145#if !USE_SHARED_LIBRARY
146 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
147
148 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
149 EVT_IDLE(wxApp::OnIdle)
150 EVT_END_SESSION(wxApp::OnEndSession)
151 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
152 END_EVENT_TABLE()
153#endif
154
e5c0b16a 155//// Initialize
589f0e3e 156bool wxApp::Initialize()
2bda0e17 157{
c030b70f
JS
158 // Some people may wish to use this, but
159 // probably it shouldn't be here by default.
160#ifdef __WXDEBUG__
e5c0b16a 161 // wxRedirectIOToConsole();
c030b70f
JS
162#endif
163
837e5743 164 wxBuffer = new wxChar[1500]; // FIXME
589f0e3e 165
aa0b7e1e 166 wxClassInfo::InitializeClasses();
589f0e3e 167
aa0b7e1e 168#if wxUSE_RESOURCES
223d09f6 169 wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion);
aa0b7e1e 170#endif
589f0e3e 171
4d3a259a 172#if wxUSE_THREADS
8e193f38 173 wxPendingEventsLocker = new wxCriticalSection;
4d3a259a
GL
174#endif
175
aa0b7e1e
JS
176 wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
177 wxTheColourDatabase->Initialize();
589f0e3e 178
aa0b7e1e
JS
179 wxInitializeStockLists();
180 wxInitializeStockObjects();
589f0e3e 181
aa0b7e1e 182#if wxUSE_WX_RESOURCES
a5e0e655 183 wxInitializeResourceSystem();
aa0b7e1e 184#endif
2bda0e17 185
aa0b7e1e 186 wxBitmap::InitStandardHandlers();
2bda0e17 187
aa0b7e1e 188#if defined(__WIN95__)
a5e0e655 189 InitCommonControls();
57c208c5 190
e5c0b16a 191#endif // __WIN95__
2bda0e17 192
c49245f8
VZ
193#if wxUSE_OLE
194
195#ifdef __WIN16__
e5c0b16a 196 // for OLE, enlarge message queue to be as large as possible
aa0b7e1e 197 int iMsg = 96;
c49245f8
VZ
198 while (!SetMessageQueue(iMsg) && (iMsg -= 8))
199 ;
200#endif // Win16
a5e0e655
VZ
201 // we need to initialize OLE library
202 if ( FAILED(::OleInitialize(NULL)) )
e5c0b16a 203 wxLogError(_("Cannot initialize OLE"));
c49245f8 204#endif // wxUSE_OLE
2bda0e17 205
1f112209 206#if wxUSE_CTL3D
a5e0e655 207 if (!Ctl3dRegister(wxhInstance))
223d09f6 208 wxLogError(wxT("Cannot register CTL3D"));
2bda0e17 209
a5e0e655 210 Ctl3dAutoSubclass(wxhInstance);
aa0b7e1e 211#endif
2bda0e17 212
aa0b7e1e 213 g_globalCursor = new wxCursor;
589f0e3e 214
87a1e308
VZ
215 // VZ: these icons are not in wx.rc anyhow (but should they?)!
216#if 0
223d09f6
KB
217 wxSTD_FRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_FRAME"));
218 wxSTD_MDIPARENTFRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_MDIPARENTFRAME"));
219 wxSTD_MDICHILDFRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_MDICHILDFRAME"));
2bda0e17 220
223d09f6
KB
221 wxDEFAULT_FRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_FRAME"));
222 wxDEFAULT_MDIPARENTFRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_MDIPARENTFRAME"));
223 wxDEFAULT_MDICHILDFRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_MDICHILDFRAME"));
87a1e308 224#endif // 0
2bda0e17 225
aa0b7e1e 226 RegisterWindowClasses();
2bda0e17 227
aa0b7e1e 228 // Create the brush for disabling bitmap buttons
2bda0e17 229
42e69d6b 230 LOGBRUSH lb;
aa0b7e1e 231 lb.lbStyle = BS_PATTERN;
223d09f6 232 lb.lbHatch = (int)LoadBitmap( wxhInstance, wxT("wxDISABLE_BUTTON_BITMAP") );
3a5ffa81
VZ
233 if ( lb.lbHatch )
234 {
235 wxDisableButtonBrush = ::CreateBrushIndirect( & lb );
236 ::DeleteObject( (HGDIOBJ)lb.lbHatch );
237 }
238 //else: wxWindows resources are probably not linked in
2bda0e17 239
aa0b7e1e 240#if wxUSE_PENWINDOWS
a5e0e655 241 wxRegisterPenWin();
aa0b7e1e 242#endif
2bda0e17 243
aa0b7e1e 244 wxWinHandleList = new wxList(wxKEY_INTEGER);
2bda0e17 245
6e0d9d43 246 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
8cbd2bde 247 // PLEASE DO NOT ALTER THIS.
3f4a0c5b 248#if defined(__VISUALC__) && !defined(WXMAKINGDLL)
a5e0e655
VZ
249 extern char wxDummyChar;
250 if (wxDummyChar) wxDummyChar++;
aa0b7e1e 251#endif
a5e0e655 252
aa0b7e1e 253 wxSetKeyboardHook(TRUE);
2bda0e17 254
aa0b7e1e
JS
255 wxModule::RegisterModules();
256 if (!wxModule::InitializeModules())
257 return FALSE;
258 return TRUE;
2bda0e17
KB
259}
260
42e69d6b
VZ
261// ---------------------------------------------------------------------------
262// RegisterWindowClasses
263// ---------------------------------------------------------------------------
589f0e3e 264
b782f2e0
VZ
265// TODO we should only register classes really used by the app. For this it
266// would be enough to just delay the class registration until an attempt
267// to create a window of this class is made.
bb6290e3 268bool wxApp::RegisterWindowClasses()
2bda0e17 269{
42e69d6b 270 WNDCLASS wndclass;
e5c0b16a 271
193fe989
VZ
272 // for each class we register one with CS_(V|H)REDRAW style and one
273 // without for windows created with wxNO_FULL_REDRAW_ON_REPAINT flag
274 static const long styleNormal = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
275 static const long styleNoRedraw = CS_DBLCLKS;
276
42e69d6b 277 // the fields which are common to all classes
e5c0b16a
VZ
278 wndclass.lpfnWndProc = (WNDPROC)wxWndProc;
279 wndclass.cbClsExtra = 0;
193fe989 280 wndclass.cbWndExtra = sizeof( DWORD ); // VZ: what is this DWORD used for?
e5c0b16a 281 wndclass.hInstance = wxhInstance;
42e69d6b
VZ
282 wndclass.hIcon = (HICON) NULL;
283 wndclass.hCursor = ::LoadCursor((HINSTANCE)NULL, IDC_ARROW);
e5c0b16a 284 wndclass.lpszMenuName = NULL;
42e69d6b
VZ
285
286 // Register the frame window class.
287 wndclass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
e5c0b16a 288 wndclass.lpszClassName = wxFrameClassName;
b782f2e0 289 wndclass.style = styleNormal;
e5c0b16a 290
42e69d6b 291 if ( !RegisterClass(&wndclass) )
e5c0b16a 292 {
42e69d6b
VZ
293 wxLogLastError("RegisterClass(frame)");
294
295 return FALSE;
e5c0b16a
VZ
296 }
297
193fe989
VZ
298 // "no redraw" frame
299 wndclass.lpszClassName = wxFrameClassNameNoRedraw;
300 wndclass.style = styleNoRedraw;
301
302 if ( !RegisterClass(&wndclass) )
303 {
304 wxLogLastError("RegisterClass(no redraw frame)");
305
306 return FALSE;
307 }
308
e5c0b16a 309 // Register the MDI frame window class.
42e69d6b 310 wndclass.hbrBackground = (HBRUSH)NULL; // paint MDI frame ourselves
b782f2e0
VZ
311 wndclass.lpszClassName = wxMDIFrameClassName;
312 wndclass.style = styleNormal;
42e69d6b
VZ
313
314 if ( !RegisterClass(&wndclass) )
e5c0b16a 315 {
42e69d6b
VZ
316 wxLogLastError("RegisterClass(MDI parent)");
317
318 return FALSE;
e5c0b16a
VZ
319 }
320
193fe989 321 // "no redraw" MDI frame
b782f2e0 322 wndclass.lpszClassName = wxMDIFrameClassNameNoRedraw;
193fe989
VZ
323 wndclass.style = styleNoRedraw;
324
325 if ( !RegisterClass(&wndclass) )
326 {
327 wxLogLastError("RegisterClass(no redraw MDI parent frame)");
328
329 return FALSE;
330 }
331
e5c0b16a 332 // Register the MDI child frame window class.
42e69d6b
VZ
333 wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
334 wndclass.lpszClassName = wxMDIChildFrameClassName;
b782f2e0 335 wndclass.style = styleNormal;
42e69d6b
VZ
336
337 if ( !RegisterClass(&wndclass) )
e5c0b16a 338 {
42e69d6b
VZ
339 wxLogLastError("RegisterClass(MDI child)");
340
341 return FALSE;
e5c0b16a
VZ
342 }
343
193fe989
VZ
344 // "no redraw" MDI child frame
345 wndclass.lpszClassName = wxMDIChildFrameClassNameNoRedraw;
346 wndclass.style = styleNoRedraw;
347
348 if ( !RegisterClass(&wndclass) )
349 {
350 wxLogLastError("RegisterClass(no redraw MDI child)");
351
352 return FALSE;
353 }
354
e5c0b16a 355 // Register the panel window class.
42e69d6b
VZ
356 wndclass.hbrBackground = (HBRUSH) GetStockObject( LTGRAY_BRUSH );
357 wndclass.lpszClassName = wxPanelClassName;
b782f2e0 358 wndclass.style = styleNormal;
42e69d6b
VZ
359
360 if ( !RegisterClass(&wndclass) )
e5c0b16a 361 {
42e69d6b
VZ
362 wxLogLastError("RegisterClass(panel)");
363
364 return FALSE;
e5c0b16a
VZ
365 }
366
e5c0b16a 367 // Register the canvas and textsubwindow class name
42e69d6b
VZ
368 wndclass.hbrBackground = (HBRUSH)NULL;
369 wndclass.lpszClassName = wxCanvasClassName;
370
371 if ( !RegisterClass(&wndclass) )
e5c0b16a 372 {
42e69d6b
VZ
373 wxLogLastError("RegisterClass(canvas)");
374
375 return FALSE;
e5c0b16a
VZ
376 }
377
378 return TRUE;
2bda0e17
KB
379}
380
42e69d6b
VZ
381// ---------------------------------------------------------------------------
382// Convert Windows to argc, argv style
383// ---------------------------------------------------------------------------
589f0e3e
JS
384
385void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine)
386{
da36f544 387 wxStringList args;
589f0e3e 388
da36f544
JS
389 wxString cmdLine(lpCmdLine);
390 int count = 0;
589f0e3e 391
da36f544 392 // Get application name
837e5743 393 wxChar name[260]; // 260 is MAX_PATH value from windef.h
da36f544
JS
394 ::GetModuleFileName(wxhInstance, name, WXSIZEOF(name));
395
da36f544 396 args.Add(name);
50ef256e 397 count++;
589f0e3e 398
837e5743 399 wxStrcpy(name, wxFileNameFromPath(name));
da36f544
JS
400 wxStripExtension(name);
401 wxTheApp->SetAppName(name);
589f0e3e 402
da36f544
JS
403 // Break up string
404 // Treat strings enclosed in double-quotes as single arguments
405 int i = 0;
406 int len = cmdLine.Length();
407 while (i < len)
a5e0e655 408 {
da36f544 409 // Skip whitespace
837e5743 410 while ((i < len) && wxIsspace(cmdLine.GetChar(i)))
da36f544
JS
411 i ++;
412
413 if (i < len)
414 {
223d09f6 415 if (cmdLine.GetChar(i) == wxT('"')) // We found the start of a string
da36f544
JS
416 {
417 i ++;
418 int first = i;
223d09f6 419 while ((i < len) && (cmdLine.GetChar(i) != wxT('"')))
da36f544
JS
420 i ++;
421
422 wxString arg(cmdLine.Mid(first, (i - first)));
423
424 args.Add(arg);
425 count ++;
426
427 if (i < len)
428 i ++; // Skip past 2nd quote
429 }
430 else // Unquoted argument
431 {
432 int first = i;
837e5743 433 while ((i < len) && !wxIsspace(cmdLine.GetChar(i)))
da36f544
JS
434 i ++;
435
436 wxString arg(cmdLine.Mid(first, (i - first)));
437
438 args.Add(arg);
439 count ++;
440 }
441 }
a5e0e655 442 }
a5e0e655 443
837e5743 444 wxTheApp->argv = new wxChar*[count + 1];
da36f544 445 for (i = 0; i < count; i++)
a5e0e655 446 {
da36f544 447 wxString arg(args[i]);
837e5743 448 wxTheApp->argv[i] = copystring((const wxChar*)arg);
a5e0e655 449 }
da36f544
JS
450 wxTheApp->argv[count] = NULL; // argv[] is a NULL-terminated list
451 wxTheApp->argc = count;
589f0e3e
JS
452}
453
454//// Cleans up any wxWindows internal structures left lying around
455
bb6290e3 456void wxApp::CleanUp()
2bda0e17 457{
e5c0b16a
VZ
458 //// COMMON CLEANUP
459
546db2a8 460#if wxUSE_LOG
e5c0b16a
VZ
461 // flush the logged messages if any and install a 'safer' log target: the
462 // default one (wxLogGui) can't be used after the resources are freed just
463 // below and the user suppliedo ne might be even more unsafe (using any
464 // wxWindows GUI function is unsafe starting from now)
465 wxLog::DontCreateOnDemand();
f5e5bd66 466
e5c0b16a
VZ
467 // this will flush the old messages if any
468 delete wxLog::SetActiveTarget(new wxLogStderr);
546db2a8 469#endif // wxUSE_LOG
f5e5bd66 470
e5c0b16a
VZ
471 // One last chance for pending objects to be cleaned up
472 wxTheApp->DeletePendingObjects();
f5e5bd66 473
e5c0b16a 474 wxModule::CleanUpModules();
2bda0e17 475
47d67540 476#if wxUSE_WX_RESOURCES
e5c0b16a 477 wxCleanUpResourceSystem();
589f0e3e 478
e5c0b16a 479 // wxDefaultResourceTable->ClearTable();
589f0e3e
JS
480#endif
481
e5c0b16a
VZ
482 // Indicate that the cursor can be freed, so that cursor won't be deleted
483 // by deleting the bitmap list before g_globalCursor goes out of scope
484 // (double deletion of the cursor).
485 wxSetCursor(wxNullCursor);
486 delete g_globalCursor;
2a47d3c1 487 g_globalCursor = NULL;
589f0e3e 488
42e69d6b 489 wxDeleteStockObjects();
589f0e3e 490
e5c0b16a
VZ
491 // Destroy all GDI lists, etc.
492 wxDeleteStockLists();
589f0e3e 493
e5c0b16a
VZ
494 delete wxTheColourDatabase;
495 wxTheColourDatabase = NULL;
589f0e3e 496
e5c0b16a 497 wxBitmap::CleanUpHandlers();
589f0e3e 498
e5c0b16a
VZ
499 delete[] wxBuffer;
500 wxBuffer = NULL;
589f0e3e 501
e5c0b16a 502 //// WINDOWS-SPECIFIC CLEANUP
2bda0e17 503
e5c0b16a 504 wxSetKeyboardHook(FALSE);
2bda0e17 505
57c208c5 506#if wxUSE_RICHEDIT
e5c0b16a
VZ
507 if (gs_hRichEdit != (HINSTANCE) NULL)
508 FreeLibrary(gs_hRichEdit);
2bda0e17
KB
509#endif
510
47d67540 511#if wxUSE_PENWINDOWS
e5c0b16a 512 wxCleanUpPenWin();
2bda0e17
KB
513#endif
514
e5c0b16a
VZ
515 if (wxSTD_FRAME_ICON)
516 DestroyIcon(wxSTD_FRAME_ICON);
517 if (wxSTD_MDICHILDFRAME_ICON)
518 DestroyIcon(wxSTD_MDICHILDFRAME_ICON);
519 if (wxSTD_MDIPARENTFRAME_ICON)
520 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON);
521
522 if (wxDEFAULT_FRAME_ICON)
523 DestroyIcon(wxDEFAULT_FRAME_ICON);
524 if (wxDEFAULT_MDICHILDFRAME_ICON)
525 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON);
526 if (wxDEFAULT_MDIPARENTFRAME_ICON)
527 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON);
528
529 if ( wxDisableButtonBrush )
42e69d6b 530 ::DeleteObject( wxDisableButtonBrush );
e5c0b16a
VZ
531
532#if wxUSE_OLE
533 ::OleUninitialize();
5de5db0e 534#endif
2bda0e17 535
1f112209 536#if wxUSE_CTL3D
e5c0b16a 537 Ctl3dUnregister(wxhInstance);
2bda0e17
KB
538#endif
539
e5c0b16a 540 if (wxWinHandleList)
42e69d6b 541 delete wxWinHandleList;
d50b2a58 542
3135f4a7 543 // GL: I'm annoyed ... I don't know where to put this and I don't want to
4d3a259a 544 // create a module for that as it's part of the core.
4d3a259a 545 delete wxPendingEvents;
8e193f38 546#if wxUSE_THREADS
4d3a259a 547 delete wxPendingEventsLocker;
63863e09
JS
548 // If we don't do the following, we get an apparent memory leak.
549 ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker();
4d3a259a
GL
550#endif
551
e5c0b16a 552 wxClassInfo::CleanUpClasses();
0c32066b 553
e5c0b16a
VZ
554 delete wxTheApp;
555 wxTheApp = NULL;
184b5d99
JS
556
557#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
e5c0b16a
VZ
558 // At this point we want to check if there are any memory
559 // blocks that aren't part of the wxDebugContext itself,
560 // as a special case. Then when dumping we need to ignore
561 // wxDebugContext, too.
d13c32e9 562 if (wxDebugContext::CountObjectsLeft(TRUE) > 0)
e5c0b16a 563 {
223d09f6 564 wxLogDebug(wxT("There were memory leaks."));
e5c0b16a
VZ
565 wxDebugContext::Dump();
566 wxDebugContext::PrintStatistics();
567 }
568 // wxDebugContext::SetStream(NULL, NULL);
184b5d99
JS
569#endif
570
546db2a8 571#if wxUSE_LOG
e5c0b16a
VZ
572 // do it as the very last thing because everything else can log messages
573 delete wxLog::SetActiveTarget(NULL);
546db2a8 574#endif // wxUSE_LOG
2bda0e17
KB
575}
576
2bda0e17
KB
577#if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
578
e5c0b16a
VZ
579// temporarily disable this warning which would be generated in release builds
580// because of __try
3f4a0c5b 581#ifdef __VISUALC__
f8a3e080
VZ
582 #pragma warning(disable: 4715) // not all control paths return a value
583#endif // Visual C++
584
589f0e3e 585//// Main wxWindows entry point
a5e0e655
VZ
586int wxEntry(WXHINSTANCE hInstance,
587 WXHINSTANCE WXUNUSED(hPrevInstance),
588 char *lpCmdLine,
589 int nCmdShow,
590 bool enterLoop)
2bda0e17 591{
6e0d9d43
VZ
592 // do check for memory leaks on program exit
593 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
594 // deallocated memory which may be used to simulate low-memory condition)
595 wxCrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
6418cb93
SC
596#ifdef __MWERKS__
597#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
598 // This seems to be necessary since there are 'rogue'
599 // objects present at this point (perhaps global objects?)
600 // Setting a checkpoint will ignore them as far as the
601 // memory checking facility is concerned.
602 // Of course you may argue that memory allocated in globals should be
603 // checked, but this is a reasonable compromise.
604 wxDebugContext::SetCheckpoint();
605#endif
606#endif
e5c0b16a
VZ
607 // take everything into a try-except block in release build
608 // FIXME other compilers must support Win32 SEH (structured exception
609 // handling) too, just find the appropriate keyword in their docs!
610 // Please note that it's _not_ the same as C++ exceptions!
3f4a0c5b 611#if !defined(__WXDEBUG__) && defined(__VISUALC__)
f8a3e080
VZ
612 #define CATCH_PROGRAM_EXCEPTIONS
613
3f4a0c5b 614 __try {
f8a3e080
VZ
615#else
616 #undef CATCH_PROGRAM_EXCEPTIONS
a5e0e655 617#endif
e5c0b16a 618 wxhInstance = (HINSTANCE) hInstance;
2bda0e17 619
e5c0b16a
VZ
620 if (!wxApp::Initialize())
621 return 0;
2bda0e17 622
e5c0b16a
VZ
623 // create the application object or ensure that one already exists
624 if (!wxTheApp)
625 {
626 // The app may have declared a global application object, but we recommend
627 // the IMPLEMENT_APP macro is used instead, which sets an initializer
628 // function for delayed, dynamic app object construction.
629 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
223d09f6 630 wxT("No initializer - use IMPLEMENT_APP macro.") );
f8a3e080 631
e5c0b16a
VZ
632 wxTheApp = (*wxApp::GetInitializerFunction()) ();
633 }
634
223d09f6 635 wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
e5c0b16a
VZ
636
637 // save the WinMain() parameters
638 wxTheApp->ConvertToStandardCommandArgs(lpCmdLine);
639 wxTheApp->m_nCmdShow = nCmdShow;
a5e0e655 640
e5c0b16a
VZ
641 // GUI-specific initialisation. In fact on Windows we don't have any,
642 // but this call is provided for compatibility across platforms.
42e69d6b 643 wxTheApp->OnInitGui();
f8a3e080 644
36edded9
JS
645 // We really don't want timestamps by default, because it means
646 // we can't simply double-click on the error message and get to that
647 // line in the source. So VC++ at least, let's have a sensible default.
648#ifdef __VISUALC__
649 wxLog::SetTimestamp(NULL);
650#endif
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
bb6290e3 927void wxApp::ExitMainLoop()
2bda0e17 928{
e5c0b16a 929 m_keepGoing = FALSE;
2bda0e17
KB
930}
931
bb6290e3 932bool wxApp::Pending()
2bda0e17 933{
42e69d6b 934 return (::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) != 0);
2bda0e17
KB
935}
936
bb6290e3 937void wxApp::Dispatch()
2bda0e17 938{
bee503b0 939 DoMessage();
2bda0e17
KB
940}
941
942/*
943 * Give all windows a chance to preprocess
944 * the message. Some may have accelerator tables, or have
945 * MDI complications.
946 */
2a47d3c1 947
d3f0a137 948bool wxApp::ProcessMessage(WXMSG *wxmsg)
2bda0e17 949{
d3f0a137
VZ
950 MSG *msg = (MSG *)wxmsg;
951 HWND hWnd = msg->hwnd;
952 wxWindow *wndThis = wxFindWinFromHandle((WXHWND)hWnd), *wnd;
2bda0e17 953
834362a2
VZ
954 // for some composite controls (like a combobox), wndThis might be NULL
955 // because the subcontrol is not a wxWindow, but only the control itself
956 // is - try to catch this case
957 while ( hWnd && !wndThis )
958 {
959 hWnd = ::GetParent(hWnd);
3135f4a7 960 wndThis = wxFindWinFromHandle((WXHWND)hWnd);
834362a2
VZ
961 }
962
e5c0b16a
VZ
963 // Try translations first; find the youngest window with
964 // a translation table.
d3f0a137 965 for ( wnd = wndThis; wnd; wnd = wnd->GetParent() )
2bda0e17 966 {
d3f0a137
VZ
967 if ( wnd->MSWTranslateMessage(wxmsg) )
968 return TRUE;
2bda0e17 969 }
2bda0e17 970
e5c0b16a 971 // Anyone for a non-translation message? Try youngest descendants first.
d3f0a137 972 for ( wnd = wndThis; wnd; wnd = wnd->GetParent() )
57a7b7c1 973 {
d3f0a137
VZ
974 if ( wnd->MSWProcessMessage(wxmsg) )
975 return TRUE;
57a7b7c1 976 }
d3f0a137 977
e5c0b16a 978 return FALSE;
2bda0e17
KB
979}
980
981void wxApp::OnIdle(wxIdleEvent& event)
982{
3222fde2 983 static bool s_inOnIdle = FALSE;
2bda0e17 984
3222fde2
VZ
985 // Avoid recursion (via ProcessEvent default case)
986 if ( s_inOnIdle )
987 return;
2bda0e17 988
3222fde2 989 s_inOnIdle = TRUE;
2bda0e17 990
3222fde2
VZ
991 // 'Garbage' collection of windows deleted with Close().
992 DeletePendingObjects();
2bda0e17 993
546db2a8 994#if wxUSE_LOG
3222fde2
VZ
995 // flush the logged messages if any
996 wxLog *pLog = wxLog::GetActiveTarget();
997 if ( pLog != NULL && pLog->HasPendingMessages() )
998 pLog->Flush();
546db2a8 999#endif // wxUSE_LOG
c54f78a2 1000
3222fde2
VZ
1001 // Send OnIdle events to all windows
1002 if ( SendIdleEvents() )
1003 {
1004 // SendIdleEvents() returns TRUE if at least one window requested more
1005 // idle events
1006 event.RequestMore(TRUE);
1007 }
2bda0e17 1008
8e193f38
VZ
1009 // If they are pending events, we must process them: pending events are
1010 // either events to the threads other than main or events posted with
1011 // wxPostEvent() functions
aadbdf11 1012 ProcessPendingEvents();
8e193f38 1013
3222fde2 1014 s_inOnIdle = FALSE;
2bda0e17
KB
1015}
1016
1017// Send idle event to all top-level windows
bb6290e3 1018bool wxApp::SendIdleEvents()
2bda0e17
KB
1019{
1020 bool needMore = FALSE;
e146b8c8 1021
f1d534df 1022 wxWindowList::Node* node = wxTopLevelWindows.GetFirst();
3222fde2
VZ
1023 while (node)
1024 {
e146b8c8 1025 wxWindow* win = node->GetData();
3222fde2 1026 if (SendIdleEvents(win))
2bda0e17 1027 needMore = TRUE;
e146b8c8 1028 node = node->GetNext();
3222fde2
VZ
1029 }
1030
2bda0e17
KB
1031 return needMore;
1032}
1033
1034// Send idle event to window and all subwindows
1035bool wxApp::SendIdleEvents(wxWindow* win)
1036{
e5c0b16a 1037 bool needMore = FALSE;
2bda0e17 1038
e5c0b16a
VZ
1039 wxIdleEvent event;
1040 event.SetEventObject(win);
1041 win->GetEventHandler()->ProcessEvent(event);
2bda0e17 1042
e5c0b16a
VZ
1043 if (event.MoreRequested())
1044 needMore = TRUE;
2bda0e17 1045
e5c0b16a
VZ
1046 wxNode* node = win->GetChildren().First();
1047 while (node)
1048 {
1049 wxWindow* win = (wxWindow*) node->Data();
1050 if (SendIdleEvents(win))
1051 needMore = TRUE;
2bda0e17 1052
e5c0b16a
VZ
1053 node = node->Next();
1054 }
42e69d6b 1055 return needMore;
2bda0e17
KB
1056}
1057
bb6290e3 1058void wxApp::DeletePendingObjects()
2bda0e17 1059{
e5c0b16a
VZ
1060 wxNode *node = wxPendingDelete.First();
1061 while (node)
1062 {
1063 wxObject *obj = (wxObject *)node->Data();
d50b2a58 1064
e5c0b16a 1065 delete obj;
2bda0e17 1066
e5c0b16a
VZ
1067 if (wxPendingDelete.Member(obj))
1068 delete node;
2bda0e17 1069
e5c0b16a
VZ
1070 // Deleting one object may have deleted other pending
1071 // objects, so start from beginning of list again.
1072 node = wxPendingDelete.First();
1073 }
2bda0e17
KB
1074}
1075
57c208c5 1076void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
387a3b02
JS
1077{
1078 if (GetTopWindow())
1079 GetTopWindow()->Close(TRUE);
1080}
1081
1082// Default behaviour: close the application with prompts. The
1083// user can veto the close, and therefore the end session.
1084void wxApp::OnQueryEndSession(wxCloseEvent& event)
1085{
1086 if (GetTopWindow())
1087 {
1088 if (!GetTopWindow()->Close(!event.CanVeto()))
1089 event.Veto(TRUE);
1090 }
1091}
1092
6d167489
VZ
1093#if wxUSE_RICHEDIT
1094
1095/* static */
1096bool wxApp::InitRichEdit(int version)
bb6290e3 1097{
6d167489
VZ
1098 wxCHECK_MSG( version >= 1 && version <= 3, FALSE,
1099 _T("incorrect richedit control version requested") );
d50b2a58 1100
6d167489 1101 if ( version <= gs_verRichEdit )
bb6290e3 1102 {
6d167489
VZ
1103 // we've already got this or better
1104 return TRUE;
1105 }
d50b2a58 1106
6d167489
VZ
1107 if ( gs_hRichEdit )
1108 {
1109 ::FreeLibrary(gs_hRichEdit);
1110 }
1111
1112 // always try load riched20.dll first - like this we won't have to reload
1113 // it later if we're first asked for RE 1 and then for RE 2 or 3
1114 wxString dllname = _T("riched20.dll");
1115 gs_hRichEdit = ::LoadLibrary(dllname);
1116 if ( !gs_hRichEdit && (version == 1) )
1117 {
1118 // fall back to RE 1
1119 dllname = _T("riched32.dll");
1120 gs_hRichEdit = ::LoadLibrary(dllname);
1121 }
1122
1123 if ( !gs_hRichEdit )
1124 {
1125 wxLogSysError(_("Could not load Rich Edit DLL '%s'"), dllname.c_str());
1126
1127 gs_verRichEdit = -1;
1128
1129 return FALSE;
1130 }
1131
1132 gs_verRichEdit = version;
1133
1134 return TRUE;
1135}
1136
1137#endif // wxUSE_RICHEDIT
1138
1139/* static */
1140int wxApp::GetComCtl32Version()
1141{
1142 // TODO should use DllGetVersion() instead of this hack
1143
1144 // cache the result
1145 static int s_verComCtl32 = -1; // MT-FIXME
1146
1147 if ( s_verComCtl32 == -1 )
1148 {
1149 s_verComCtl32 = 0;
1150
1151 // have we loaded COMCTL32 yet?
1152 HMODULE theModule = ::GetModuleHandle(wxT("COMCTL32"));
1153
1154 // if so, then we can check for the version
1155 if (theModule)
bb6290e3 1156 {
6d167489
VZ
1157 // InitCommonControlsEx is unique to 4.7 and later
1158 FARPROC theProc = ::GetProcAddress(theModule,
1159 _T("InitCommonControlsEx"));
1160
1161 if ( !theProc )
1162 { // not found, must be 4.00
1163 s_verComCtl32 = 400;
e5c0b16a
VZ
1164 }
1165 else
6d167489
VZ
1166 {
1167 // The following symbol are unique to 4.71
1168 // DllInstall
1169 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
1170 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
1171 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
1172 // FlatSB_ShowScrollBar
1173 // _DrawIndirectImageList _DuplicateImageList
1174 // InitializeFlatSB
1175 // UninitializeFlatSB
1176 // we could check for any of these - I chose DllInstall
1177 FARPROC theProc = ::GetProcAddress(theModule, _T("DllInstall"));
1178 if ( !theProc )
1179 {
1180 // not found, must be 4.70
1181 s_verComCtl32 = 470;
1182 }
1183 else
1184 { // found, must be 4.71
1185 s_verComCtl32 = 471;
1186 }
e5c0b16a 1187 }
bb6290e3
JS
1188 }
1189 }
6d167489
VZ
1190
1191 return s_verComCtl32;
bb6290e3
JS
1192}
1193
1194void wxExit()
2bda0e17 1195{
e5c0b16a
VZ
1196 wxLogError(_("Fatal error: exiting"));
1197
1198 wxApp::CleanUp();
2bda0e17
KB
1199}
1200
1201// Yield to incoming messages
bb6290e3 1202bool wxYield()
2bda0e17 1203{
8e193f38
VZ
1204 // we don't want to process WM_QUIT from here - it should be processed in
1205 // the main event loop in order to stop it
1206
e5c0b16a 1207 MSG msg;
8e193f38
VZ
1208 while ( PeekMessage(&msg, (HWND)0, 0, 0, PM_NOREMOVE) &&
1209 msg.message != WM_QUIT )
e5c0b16a
VZ
1210 {
1211 if ( !wxTheApp->DoMessage() )
1212 break;
1213 }
8e193f38 1214
aadbdf11 1215 // If they are pending events, we must process them.
6a2f3103 1216 wxTheApp->ProcessPendingEvents();
e5c0b16a
VZ
1217
1218 return TRUE;
2bda0e17 1219}
094637f6 1220
9779893b
RD
1221//-----------------------------------------------------------------------------
1222// wxWakeUpIdle
1223//-----------------------------------------------------------------------------
1224
1225void wxWakeUpIdle()
1226{
1227 // Send the top window a dummy message so idle handler processing will
1228 // start up again. Doing it this way ensures that the idle handler
b568d04f
VZ
1229 // wakes up in the right thread (see also wxWakeUpMainThread() which does
1230 // the same for the main app thread only)
9779893b 1231 wxWindow *topWindow = wxTheApp->GetTopWindow();
b568d04f
VZ
1232 if ( topWindow )
1233 {
1234 if ( !::PostMessage(GetHwndOf(topWindow), WM_NULL, 0, 0) )
1235 {
1236 // should never happen
1237 wxLogLastError("PostMessage(WM_NULL)");
1238 }
9779893b
RD
1239 }
1240}
1241
1242//-----------------------------------------------------------------------------
1243
ebea0891
KB
1244wxIcon
1245wxApp::GetStdIcon(int which) const
1246{
094637f6
VZ
1247 switch(which)
1248 {
1249 case wxICON_INFORMATION:
1250 return wxIcon("wxICON_INFO");
1251
1252 case wxICON_QUESTION:
1253 return wxIcon("wxICON_QUESTION");
1254
1255 case wxICON_EXCLAMATION:
1256 return wxIcon("wxICON_WARNING");
1257
1258 default:
223d09f6 1259 wxFAIL_MSG(wxT("requested non existent standard icon"));
094637f6
VZ
1260 // still fall through
1261
1262 case wxICON_HAND:
1263 return wxIcon("wxICON_ERROR");
1264 }
ebea0891
KB
1265}
1266
2bda0e17
KB
1267// For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
1268// if in a separate file. So include it here to ensure it's linked.
3f4a0c5b 1269#if (defined(__VISUALC__) && !defined(__WIN32__)) || (defined(__GNUWIN32__) && !defined(__TWIN32__))
e5c0b16a 1270#include "main.cpp"
2bda0e17 1271#endif