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