1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "app.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
27 #if defined(__BORLANDC__)
35 #include "wx/gdicmn.h"
38 #include "wx/cursor.h"
40 #include "wx/palette.h"
42 #include "wx/dialog.h"
43 #include "wx/msgdlg.h"
45 #include "wx/dynarray.h"
46 #include "wx/wxchar.h"
51 #include "wx/apptrait.h"
52 #include "wx/filename.h"
53 #include "wx/module.h"
55 #include "wx/msw/private.h"
58 #include "wx/thread.h"
60 // define the array of MSG strutures
61 WX_DECLARE_OBJARRAY(MSG
, wxMsgArray
);
63 #include "wx/arrimpl.cpp"
65 WX_DEFINE_OBJARRAY(wxMsgArray
);
66 #endif // wxUSE_THREADS
69 #include "wx/tooltip.h"
70 #endif // wxUSE_TOOLTIPS
72 // OLE is used for drag-and-drop, clipboard, OLE Automation..., but some
73 // compilers don't support it (missing headers, libs, ...)
74 #if defined(__GNUWIN32_OLD__) || defined(__SYMANTEC__) || defined(__SALFORDC__)
78 #endif // broken compilers
87 #if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__WXMICROWIN__)) && !defined(__CYGWIN10__))
91 // ----------------------------------------------------------------------------
92 // conditional compilation
93 // ----------------------------------------------------------------------------
95 // The macro _WIN32_IE is defined by commctrl.h (unless it had already been
96 // defined before) and shows us what common control features are available
97 // during the compile time (it doesn't mean that they will be available during
98 // the run-time, use GetComCtl32Version() to test for them!). The possible
101 // 0x0200 for comctl32.dll 4.00 shipped with Win95/NT 4.0
102 // 0x0300 4.70 IE 3.x
103 // 0x0400 4.71 IE 4.0
104 // 0x0401 4.72 IE 4.01 and Win98
105 // 0x0500 5.00 IE 5.x and NT 5.0 (Win2000)
108 // minimal set of features by default
109 #define _WIN32_IE 0x0200
112 #if _WIN32_IE >= 0x0300 && \
113 (!defined(__MINGW32__) || wxCHECK_W32API_VERSION( 2, 0 )) && \
118 // ---------------------------------------------------------------------------
120 // ---------------------------------------------------------------------------
122 extern wxChar
*wxBuffer
;
123 extern wxList WXDLLEXPORT wxPendingDelete
;
124 #ifndef __WXMICROWIN__
125 extern void wxSetKeyboardHook(bool doIt
);
130 // NB: all "NoRedraw" classes must have the same names as the "normal" classes
131 // with NR suffix - wxWindow::MSWCreate() supposes this
132 const wxChar
*wxCanvasClassName
= wxT("wxWindowClass");
133 const wxChar
*wxCanvasClassNameNR
= wxT("wxWindowClassNR");
134 const wxChar
*wxMDIFrameClassName
= wxT("wxMDIFrameClass");
135 const wxChar
*wxMDIFrameClassNameNoRedraw
= wxT("wxMDIFrameClassNR");
136 const wxChar
*wxMDIChildFrameClassName
= wxT("wxMDIChildFrameClass");
137 const wxChar
*wxMDIChildFrameClassNameNoRedraw
= wxT("wxMDIChildFrameClassNR");
139 HBRUSH wxDisableButtonBrush
= (HBRUSH
) 0;
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
145 LRESULT WXDLLEXPORT APIENTRY
wxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
147 // ===========================================================================
148 // wxGUIAppTraits implementation
149 // ===========================================================================
151 // private class which we use to pass parameters from BeforeChildWaitLoop() to
152 // AfterChildWaitLoop()
153 struct ChildWaitLoopData
155 ChildWaitLoopData(wxWindowDisabler
*wd_
, wxWindow
*winActive_
)
158 winActive
= winActive_
;
161 wxWindowDisabler
*wd
;
165 void *wxGUIAppTraits::BeforeChildWaitLoop()
168 We use a dirty hack here to disable all application windows (which we
169 must do because otherwise the calls to wxYield() could lead to some very
170 unexpected reentrancies in the users code) but to avoid losing
171 focus/activation entirely when the child process terminates which would
172 happen if we simply disabled everything using wxWindowDisabler. Indeed,
173 remember that Windows will never activate a disabled window and when the
174 last childs window is closed and Windows looks for a window to activate
175 all our windows are still disabled. There is no way to enable them in
176 time because we don't know when the childs windows are going to be
177 closed, so the solution we use here is to keep one special tiny frame
178 enabled all the time. Then when the child terminates it will get
179 activated and when we close it below -- after reenabling all the other
180 windows! -- the previously active window becomes activated again and
185 // first disable all existing windows
186 wxWindowDisabler
*wd
= new wxWindowDisabler
;
188 // then create an "invisible" frame: it has minimal size, is positioned
189 // (hopefully) outside the screen and doesn't appear on the taskbar
190 wxWindow
*winActive
= new wxFrame
192 wxTheApp
->GetTopWindow(),
195 wxPoint(32600, 32600),
197 wxDEFAULT_FRAME_STYLE
| wxFRAME_NO_TASKBAR
201 return new ChildWaitLoopData(wd
, winActive
);
204 void wxGUIAppTraits::AlwaysYield()
209 void wxGUIAppTraits::AfterChildWaitLoop(void *dataOrig
)
213 const ChildWaitLoopData
* const data
= (ChildWaitLoopData
*)dataOrig
;
217 // finally delete the dummy frame and, as wd has been already destroyed and
218 // the other windows reenabled, the activation is going to return to the
219 // window which had had it before
220 data
->winActive
->Destroy();
223 bool wxGUIAppTraits::DoMessageFromThreadWait()
225 return !wxTheApp
|| wxTheApp
->DoMessage();
228 // ===========================================================================
229 // wxApp implementation
230 // ===========================================================================
232 int wxApp::m_nCmdShow
= SW_SHOWNORMAL
;
234 // ---------------------------------------------------------------------------
236 // ---------------------------------------------------------------------------
238 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
240 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
241 EVT_IDLE(wxApp::OnIdle
)
242 EVT_END_SESSION(wxApp::OnEndSession
)
243 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
246 // class to ensure that wxAppBase::CleanUp() is called if our Initialize()
248 class wxCallBaseCleanup
251 wxCallBaseCleanup(wxApp
*app
) : m_app(app
) { }
252 ~wxCallBaseCleanup() { if ( m_app
) m_app
->wxAppBase::CleanUp(); }
254 void Dismiss() { m_app
= NULL
; }
261 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
263 if ( !wxAppBase::Initialize(argc
, argv
) )
266 // ensure that base cleanup is done if we return too early
267 wxCallBaseCleanup
callBaseCleanup(this);
269 // the first thing to do is to check if we're trying to run an Unicode
270 // program under Win9x w/o MSLU emulation layer - if so, abort right now
271 // as it has no chance to work
272 #if wxUSE_UNICODE && !wxUSE_UNICODE_MSLU
273 if ( wxGetOsVersion() != wxWINDOWS_NT
)
275 // note that we can use MessageBoxW() as it's implemented even under
276 // Win9x - OTOH, we can't use wxGetTranslation() because the file APIs
277 // used by wxLocale are not
281 _T("This program uses Unicode and requires Windows NT/2000/XP.\nProgram aborted."),
282 _T("wxWindows Fatal Error"),
288 #endif // wxUSE_UNICODE && !wxUSE_UNICODE_MSLU
290 wxBuffer
= new wxChar
[1500]; // FIXME
292 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
293 InitCommonControls();
296 #if wxUSE_OLE || wxUSE_DRAG_AND_DROP
299 // for OLE, enlarge message queue to be as large as possible
301 while (!SetMessageQueue(iMsg
) && (iMsg
-= 8))
306 // we need to initialize OLE library
307 if ( FAILED(::OleInitialize(NULL
)) )
308 wxLogError(_("Cannot initialize OLE"));
314 if (!Ctl3dRegister(wxhInstance
))
315 wxLogError(wxT("Cannot register CTL3D"));
317 Ctl3dAutoSubclass(wxhInstance
);
318 #endif // wxUSE_CTL3D
320 RegisterWindowClasses();
322 #ifndef __WXMICROWIN__
323 // Create the brush for disabling bitmap buttons
326 lb
.lbStyle
= BS_PATTERN
;
328 lb
.lbHatch
= (int)LoadBitmap( wxhInstance
, wxT("wxDISABLE_BUTTON_BITMAP") );
331 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
);
332 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
);
334 //else: wxWindows resources are probably not linked in
341 wxWinHandleHash
= new wxWinHashTable(wxKEY_INTEGER
, 100);
343 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
344 // PLEASE DO NOT ALTER THIS.
345 #if defined(__VISUALC__) && defined(__WIN16__) && !defined(WXMAKINGDLL)
346 extern char wxDummyChar
;
347 if (wxDummyChar
) wxDummyChar
++;
350 #ifndef __WXMICROWIN__
351 wxSetKeyboardHook(TRUE
);
354 callBaseCleanup
.Dismiss();
359 // ---------------------------------------------------------------------------
360 // RegisterWindowClasses
361 // ---------------------------------------------------------------------------
363 // TODO we should only register classes really used by the app. For this it
364 // would be enough to just delay the class registration until an attempt
365 // to create a window of this class is made.
366 bool wxApp::RegisterWindowClasses()
369 wxZeroMemory(wndclass
);
371 // for each class we register one with CS_(V|H)REDRAW style and one
372 // without for windows created with wxNO_FULL_REDRAW_ON_REPAINT flag
373 static const long styleNormal
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
374 static const long styleNoRedraw
= CS_DBLCLKS
;
376 // the fields which are common to all classes
377 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
378 wndclass
.hInstance
= wxhInstance
;
379 wndclass
.hCursor
= ::LoadCursor((HINSTANCE
)NULL
, IDC_ARROW
);
381 // Register the frame window class.
382 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+ 1);
383 wndclass
.lpszClassName
= wxCanvasClassName
;
384 wndclass
.style
= styleNormal
;
386 if ( !RegisterClass(&wndclass
) )
388 wxLogLastError(wxT("RegisterClass(frame)"));
392 wndclass
.lpszClassName
= wxCanvasClassNameNR
;
393 wndclass
.style
= styleNoRedraw
;
395 if ( !RegisterClass(&wndclass
) )
397 wxLogLastError(wxT("RegisterClass(no redraw frame)"));
400 // Register the MDI frame window class.
401 wndclass
.hbrBackground
= (HBRUSH
)NULL
; // paint MDI frame ourselves
402 wndclass
.lpszClassName
= wxMDIFrameClassName
;
403 wndclass
.style
= styleNormal
;
405 if ( !RegisterClass(&wndclass
) )
407 wxLogLastError(wxT("RegisterClass(MDI parent)"));
410 // "no redraw" MDI frame
411 wndclass
.lpszClassName
= wxMDIFrameClassNameNoRedraw
;
412 wndclass
.style
= styleNoRedraw
;
414 if ( !RegisterClass(&wndclass
) )
416 wxLogLastError(wxT("RegisterClass(no redraw MDI parent frame)"));
419 // Register the MDI child frame window class.
420 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
421 wndclass
.lpszClassName
= wxMDIChildFrameClassName
;
422 wndclass
.style
= styleNormal
;
424 if ( !RegisterClass(&wndclass
) )
426 wxLogLastError(wxT("RegisterClass(MDI child)"));
429 // "no redraw" MDI child frame
430 wndclass
.lpszClassName
= wxMDIChildFrameClassNameNoRedraw
;
431 wndclass
.style
= styleNoRedraw
;
433 if ( !RegisterClass(&wndclass
) )
435 wxLogLastError(wxT("RegisterClass(no redraw MDI child)"));
441 // ---------------------------------------------------------------------------
442 // UnregisterWindowClasses
443 // ---------------------------------------------------------------------------
445 bool wxApp::UnregisterWindowClasses()
449 #ifndef __WXMICROWIN__
450 // MDI frame window class.
451 if ( !::UnregisterClass(wxMDIFrameClassName
, wxhInstance
) )
453 wxLogLastError(wxT("UnregisterClass(MDI parent)"));
458 // "no redraw" MDI frame
459 if ( !::UnregisterClass(wxMDIFrameClassNameNoRedraw
, wxhInstance
) )
461 wxLogLastError(wxT("UnregisterClass(no redraw MDI parent frame)"));
466 // MDI child frame window class.
467 if ( !::UnregisterClass(wxMDIChildFrameClassName
, wxhInstance
) )
469 wxLogLastError(wxT("UnregisterClass(MDI child)"));
474 // "no redraw" MDI child frame
475 if ( !::UnregisterClass(wxMDIChildFrameClassNameNoRedraw
, wxhInstance
) )
477 wxLogLastError(wxT("UnregisterClass(no redraw MDI child)"));
483 if ( !::UnregisterClass(wxCanvasClassName
, wxhInstance
) )
485 wxLogLastError(wxT("UnregisterClass(canvas)"));
490 if ( !::UnregisterClass(wxCanvasClassNameNR
, wxhInstance
) )
492 wxLogLastError(wxT("UnregisterClass(no redraw canvas)"));
496 #endif // __WXMICROWIN__
501 void wxApp::CleanUp()
506 #ifndef __WXMICROWIN__
507 wxSetKeyboardHook(FALSE
);
514 if ( wxDisableButtonBrush
)
515 ::DeleteObject( wxDisableButtonBrush
);
521 // for an EXE the classes are unregistered when it terminates but DLL may
522 // be loaded several times (load/unload/load) into the same process in
523 // which case the registration will fail after the first time if we don't
524 // unregister the classes now
525 UnregisterWindowClasses();
528 Ctl3dUnregister(wxhInstance
);
531 delete wxWinHandleHash
;
532 wxWinHandleHash
= NULL
;
534 wxAppBase::CleanUp();
537 // ----------------------------------------------------------------------------
539 // ----------------------------------------------------------------------------
543 m_printMode
= wxPRINT_WINDOWS
;
548 // our cmd line arguments are allocated inside wxEntry(HINSTANCE), they
549 // don't come from main(), so we have to free them
553 // m_argv elements were allocated by wxStrdup()
557 // but m_argv itself -- using new[]
561 bool wxApp::Initialized()
568 #else // Assume initialized if DLL (no way of telling)
574 * Get and process a message, returning FALSE if WM_QUIT
575 * received (and also set the flag telling the app to exit the main loop)
578 bool wxApp::DoMessage()
580 BOOL rc
= ::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0);
590 // should never happen, but let's test for it nevertheless
591 wxLogLastError(wxT("GetMessage"));
596 wxASSERT_MSG( wxThread::IsMain(),
597 wxT("only the main thread can process Windows messages") );
599 static bool s_hadGuiLock
= TRUE
;
600 static wxMsgArray s_aSavedMessages
;
602 // if a secondary thread owns is doing GUI calls, save all messages for
603 // later processing - we can't process them right now because it will
604 // lead to recursive library calls (and we're not reentrant)
605 if ( !wxGuiOwnedByMainThread() )
607 s_hadGuiLock
= FALSE
;
609 // leave out WM_COMMAND messages: too dangerous, sometimes
610 // the message will be processed twice
611 if ( !wxIsWaitingForThread() ||
612 s_currentMsg
.message
!= WM_COMMAND
)
614 s_aSavedMessages
.Add(s_currentMsg
);
621 // have we just regained the GUI lock? if so, post all of the saved
624 // FIXME of course, it's not _exactly_ the same as processing the
625 // messages normally - expect some things to break...
630 size_t count
= s_aSavedMessages
.GetCount();
631 for ( size_t n
= 0; n
< count
; n
++ )
633 MSG
& msg
= s_aSavedMessages
[n
];
635 DoMessage((WXMSG
*)&msg
);
638 s_aSavedMessages
.Empty();
641 #endif // wxUSE_THREADS
643 // Process the message
644 DoMessage((WXMSG
*)&s_currentMsg
);
650 void wxApp::DoMessage(WXMSG
*pMsg
)
652 if ( !ProcessMessage(pMsg
) )
654 ::TranslateMessage((MSG
*)pMsg
);
655 ::DispatchMessage((MSG
*)pMsg
);
660 * Keep trying to process messages until WM_QUIT
663 * If there are messages to be processed, they will all be
664 * processed and OnIdle will not be called.
665 * When there are no more messages, OnIdle is called.
666 * If OnIdle requests more time,
667 * it will be repeatedly called so long as there are no pending messages.
668 * A 'feature' of this is that once OnIdle has decided that no more processing
669 * is required, then it won't get processing time until further messages
670 * are processed (it'll sit in DoMessage).
673 int wxApp::MainLoop()
677 while ( m_keepGoing
)
680 wxMutexGuiLeaveOrEnter();
681 #endif // wxUSE_THREADS
683 while ( !Pending() && ProcessIdle() )
686 // a message came or no more idle processing to do
690 return s_currentMsg
.wParam
;
693 // Returns TRUE if more time is needed.
694 bool wxApp::ProcessIdle()
697 event
.SetEventObject(this);
700 return event
.MoreRequested();
703 void wxApp::ExitMainLoop()
705 // this will set m_keepGoing to FALSE a bit later
706 ::PostQuitMessage(0);
709 bool wxApp::Pending()
711 return ::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0;
714 void wxApp::Dispatch()
720 * Give all windows a chance to preprocess
721 * the message. Some may have accelerator tables, or have
725 bool wxApp::ProcessMessage(WXMSG
*wxmsg
)
727 MSG
*msg
= (MSG
*)wxmsg
;
728 HWND hwnd
= msg
->hwnd
;
729 wxWindow
*wndThis
= wxGetWindowFromHWND((WXHWND
)hwnd
);
731 // this may happen if the event occured in a standard modeless dialog (the
732 // only example of which I know of is the find/replace dialog) - then call
733 // IsDialogMessage() to make TAB navigation in it work
736 // we need to find the dialog containing this control as
737 // IsDialogMessage() just eats all the messages (i.e. returns TRUE for
738 // them) if we call it for the control itself
739 while ( hwnd
&& ::GetWindowLong(hwnd
, GWL_STYLE
) & WS_CHILD
)
741 hwnd
= ::GetParent(hwnd
);
744 return hwnd
&& ::IsDialogMessage(hwnd
, msg
) != 0;
748 // we must relay WM_MOUSEMOVE events to the tooltip ctrl if we want it to
749 // popup the tooltip bubbles
750 if ( (msg
->message
== WM_MOUSEMOVE
) )
752 wxToolTip
*tt
= wndThis
->GetToolTip();
755 tt
->RelayEvent(wxmsg
);
758 #endif // wxUSE_TOOLTIPS
760 // allow the window to prevent certain messages from being
761 // translated/processed (this is currently used by wxTextCtrl to always
762 // grab Ctrl-C/V/X, even if they are also accelerators in some parent)
763 if ( !wndThis
->MSWShouldPreProcessMessage(wxmsg
) )
768 // try translations first: the accelerators override everything
771 for ( wnd
= wndThis
; wnd
; wnd
= wnd
->GetParent() )
773 if ( wnd
->MSWTranslateMessage(wxmsg
))
776 // stop at first top level window, i.e. don't try to process the key
777 // strokes originating in a dialog using the accelerators of the parent
778 // frame - this doesn't make much sense
779 if ( wnd
->IsTopLevel() )
783 // now try the other hooks (kbd navigation is handled here): we start from
784 // wndThis->GetParent() because wndThis->MSWProcessMessage() was already
786 for ( wnd
= wndThis
->GetParent(); wnd
; wnd
= wnd
->GetParent() )
788 if ( wnd
->MSWProcessMessage(wxmsg
) )
792 // no special preprocessing for this message, dispatch it normally
796 // this is a temporary hack and will be replaced by using wxEventLoop in the
799 // it is needed to allow other event loops (currently only one: the modal
800 // dialog one) to reset the OnIdle() semaphore because otherwise OnIdle()
801 // wouldn't do anything while a modal dialog shown from OnIdle() call is shown.
802 bool wxIsInOnIdleFlag
= FALSE
;
804 void wxApp::OnIdle(wxIdleEvent
& event
)
806 // Avoid recursion (via ProcessEvent default case)
807 if ( wxIsInOnIdleFlag
)
810 wxIsInOnIdleFlag
= TRUE
;
812 // If there are pending events, we must process them: pending events
813 // are either events to the threads other than main or events posted
814 // with wxPostEvent() functions
815 // GRG: I have moved this here so that all pending events are processed
816 // before starting to delete any objects. This behaves better (in
817 // particular, wrt wxPostEvent) and is coherent with wxGTK's current
818 // behaviour. Changed Feb/2000 before 2.1.14
819 ProcessPendingEvents();
821 // 'Garbage' collection of windows deleted with Close().
822 DeletePendingObjects();
825 // flush the logged messages if any
826 wxLog::FlushActive();
829 #if wxUSE_DC_CACHEING
830 // automated DC cache management: clear the cached DCs and bitmap
831 // if it's likely that the app has finished with them, that is, we
832 // get an idle event and we're not dragging anything.
833 if (!::GetKeyState(MK_LBUTTON
) && !::GetKeyState(MK_MBUTTON
) && !::GetKeyState(MK_RBUTTON
))
835 #endif // wxUSE_DC_CACHEING
837 // Send OnIdle events to all windows
838 if ( SendIdleEvents() )
840 // SendIdleEvents() returns TRUE if at least one window requested more
842 event
.RequestMore(TRUE
);
845 wxIsInOnIdleFlag
= FALSE
;
848 // Send idle event to all top-level windows
849 bool wxApp::SendIdleEvents()
851 bool needMore
= FALSE
;
853 wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
856 wxWindow
* win
= node
->GetData();
857 if (SendIdleEvents(win
))
859 node
= node
->GetNext();
865 // Send idle event to window and all subwindows
866 bool wxApp::SendIdleEvents(wxWindow
* win
)
869 event
.SetEventObject(win
);
870 win
->GetEventHandler()->ProcessEvent(event
);
872 bool needMore
= event
.MoreRequested();
874 wxWindowList::Node
*node
= win
->GetChildren().GetFirst();
877 wxWindow
*win
= node
->GetData();
878 if (SendIdleEvents(win
))
881 node
= node
->GetNext();
887 void wxApp::WakeUpIdle()
889 // Send the top window a dummy message so idle handler processing will
890 // start up again. Doing it this way ensures that the idle handler
891 // wakes up in the right thread (see also wxWakeUpMainThread() which does
892 // the same for the main app thread only)
893 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
896 if ( !::PostMessage(GetHwndOf(topWindow
), WM_NULL
, 0, 0) )
898 // should never happen
899 wxLogLastError(wxT("PostMessage(WM_NULL)"));
904 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
907 GetTopWindow()->Close(TRUE
);
910 // Default behaviour: close the application with prompts. The
911 // user can veto the close, and therefore the end session.
912 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
916 if (!GetTopWindow()->Close(!event
.CanVeto()))
921 typedef struct _WXADllVersionInfo
924 DWORD dwMajorVersion
; // Major version
925 DWORD dwMinorVersion
; // Minor version
926 DWORD dwBuildNumber
; // Build number
927 DWORD dwPlatformID
; // DLLVER_PLATFORM_*
930 typedef HRESULT (CALLBACK
* WXADLLGETVERSIONPROC
)(WXADLLVERSIONINFO
*);
933 int wxApp::GetComCtl32Version()
935 #ifdef __WXMICROWIN__
939 static int s_verComCtl32
= -1;
941 wxCRIT_SECT_DECLARE(csComCtl32
);
942 wxCRIT_SECT_LOCKER(lock
, csComCtl32
);
944 if ( s_verComCtl32
== -1 )
946 // initally assume no comctl32.dll at all
950 HMODULE hModuleComCtl32
= ::GetModuleHandle(wxT("COMCTL32"));
951 BOOL bFreeComCtl32
= FALSE
;
954 hModuleComCtl32
= ::LoadLibrary(wxT("COMCTL32.DLL")) ;
957 bFreeComCtl32
= TRUE
;
961 // if so, then we can check for the version
962 if ( hModuleComCtl32
)
964 // try to use DllGetVersion() if available in _headers_
965 WXADLLGETVERSIONPROC pfnDllGetVersion
= (WXADLLGETVERSIONPROC
)
966 ::GetProcAddress(hModuleComCtl32
, "DllGetVersion");
967 if ( pfnDllGetVersion
)
969 WXADLLVERSIONINFO dvi
;
970 dvi
.cbSize
= sizeof(dvi
);
972 HRESULT hr
= (*pfnDllGetVersion
)(&dvi
);
975 wxLogApiError(_T("DllGetVersion"), hr
);
979 // this is incompatible with _WIN32_IE values, but
980 // compatible with the other values returned by
981 // GetComCtl32Version()
982 s_verComCtl32
= 100*dvi
.dwMajorVersion
+
986 // DllGetVersion() unavailable either during compile or
987 // run-time, try to guess the version otherwise
988 if ( !s_verComCtl32
)
990 // InitCommonControlsEx is unique to 4.70 and later
991 FARPROC theProc
= ::GetProcAddress
994 "InitCommonControlsEx"
999 // not found, must be 4.00
1000 s_verComCtl32
= 400;
1004 // many symbols appeared in comctl32 4.71, could use
1005 // any of them except may be DllInstall
1006 theProc
= ::GetProcAddress
1013 // not found, must be 4.70
1014 s_verComCtl32
= 470;
1018 // found, must be 4.71
1019 s_verComCtl32
= 471;
1027 ::FreeLibrary(hModuleComCtl32
) ;
1031 return s_verComCtl32
;
1035 // Yield to incoming messages
1037 bool wxApp::Yield(bool onlyIfNeeded
)
1040 static bool s_inYield
= FALSE
;
1043 // disable log flushing from here because a call to wxYield() shouldn't
1044 // normally result in message boxes popping up &c
1050 if ( !onlyIfNeeded
)
1052 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1060 // we don't want to process WM_QUIT from here - it should be processed in
1061 // the main event loop in order to stop it
1063 while ( PeekMessage(&msg
, (HWND
)0, 0, 0, PM_NOREMOVE
) &&
1064 msg
.message
!= WM_QUIT
)
1067 wxMutexGuiLeaveOrEnter();
1068 #endif // wxUSE_THREADS
1070 if ( !wxTheApp
->DoMessage() )
1074 // if there are pending events, we must process them.
1075 ProcessPendingEvents();
1078 // let the logs be flashed again