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