1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/evtloopconsole.cpp
3 // Purpose: wxConsoleEventLoop class for Windows
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
28 #include "wx/msw/wrapwin.h"
31 #include "wx/evtloop.h"
33 // ============================================================================
34 // wxMSWEventLoopBase implementation
35 // ============================================================================
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 wxMSWEventLoopBase::wxMSWEventLoopBase()
47 // ----------------------------------------------------------------------------
48 // wxEventLoop message processing dispatching
49 // ----------------------------------------------------------------------------
51 bool wxMSWEventLoopBase::Pending() const
54 return ::PeekMessage(&msg
, 0, 0, 0, PM_NOREMOVE
) != 0;
57 bool wxMSWEventLoopBase::GetNextMessage(WXMSG
* msg
)
59 const BOOL rc
= ::GetMessage(msg
, NULL
, 0, 0);
69 // should never happen, but let's test for it nevertheless
70 wxLogLastError(wxT("GetMessage"));
72 // still break from the loop
79 int wxMSWEventLoopBase::GetNextMessageTimeout(WXMSG
*msg
, unsigned long timeout
)
81 // MsgWaitForMultipleObjects() won't notice any input which was already
82 // examined (e.g. using PeekMessage()) but not yet removed from the queue
83 // so we need to remove any immediately messages manually
85 // NB: using MsgWaitForMultipleObjectsEx() could simplify the code here but
86 // it is not available in very old Windows versions
87 if ( !::PeekMessage(msg
, 0, 0, 0, PM_REMOVE
) )
89 // we use this function just in order to not block longer than the
90 // given timeout, so we don't pass any handles to it at all
91 DWORD rc
= ::MsgWaitForMultipleObjects
102 wxLogDebug("unexpected MsgWaitForMultipleObjects() return "
110 if ( !::PeekMessage(msg
, 0, 0, 0, PM_REMOVE
) )
112 // somehow it may happen that MsgWaitForMultipleObjects()
113 // returns true but there are no messages -- just treat it
114 // the same as timeout then
121 return msg
->message
!= WM_QUIT
;
124 // ============================================================================
125 // wxConsoleEventLoop implementation
126 // ============================================================================
128 #if wxUSE_CONSOLE_EVENTLOOP
130 void wxConsoleEventLoop::WakeUp()
133 wxWakeUpMainThread();
137 void wxConsoleEventLoop::ProcessMessage(WXMSG
*msg
)
139 ::DispatchMessage(msg
);
142 bool wxConsoleEventLoop::Dispatch()
145 if ( !GetNextMessage(&msg
) )
148 ProcessMessage(&msg
);
150 return !m_shouldExit
;
153 int wxConsoleEventLoop::DispatchTimeout(unsigned long timeout
)
156 int rc
= GetNextMessageTimeout(&msg
, timeout
);
160 ProcessMessage(&msg
);
162 return !m_shouldExit
;
165 #endif // wxUSE_CONSOLE_EVENTLOOP