1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/evtloopconsole.cpp
3 // Purpose: wxConsoleEventLoop class for Windows
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/msw/wrapwin.h"
32 #include "wx/evtloop.h"
34 // ============================================================================
35 // wxMSWEventLoopBase implementation
36 // ============================================================================
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 wxMSWEventLoopBase::wxMSWEventLoopBase()
48 // ----------------------------------------------------------------------------
49 // wxEventLoop message processing dispatching
50 // ----------------------------------------------------------------------------
52 bool wxMSWEventLoopBase::Pending() const
55 return ::PeekMessage(&msg
, 0, 0, 0, PM_NOREMOVE
) != 0;
58 bool wxMSWEventLoopBase::GetNextMessage(WXMSG
* msg
)
60 const BOOL rc
= ::GetMessage(msg
, NULL
, 0, 0);
70 // should never happen, but let's test for it nevertheless
71 wxLogLastError(wxT("GetMessage"));
73 // still break from the loop
80 int wxMSWEventLoopBase::GetNextMessageTimeout(WXMSG
*msg
, unsigned long timeout
)
82 // MsgWaitForMultipleObjects() won't notice any input which was already
83 // examined (e.g. using PeekMessage()) but not yet removed from the queue
84 // so we need to remove any immediately messages manually
86 // NB: using MsgWaitForMultipleObjectsEx() could simplify the code here but
87 // it is not available in very old Windows versions
88 if ( !::PeekMessage(msg
, 0, 0, 0, PM_REMOVE
) )
90 // we use this function just in order to not block longer than the
91 // given timeout, so we don't pass any handles to it at all
92 DWORD rc
= ::MsgWaitForMultipleObjects
103 wxLogDebug("unexpected MsgWaitForMultipleObjects() return "
111 if ( !::PeekMessage(msg
, 0, 0, 0, PM_REMOVE
) )
113 // somehow it may happen that MsgWaitForMultipleObjects()
114 // returns true but there are no messages -- just treat it
115 // the same as timeout then
122 return msg
->message
!= WM_QUIT
;
125 // ============================================================================
126 // wxConsoleEventLoop implementation
127 // ============================================================================
129 #if wxUSE_CONSOLE_EVENTLOOP
131 void wxConsoleEventLoop::WakeUp()
134 wxWakeUpMainThread();
138 void wxConsoleEventLoop::ProcessMessage(WXMSG
*msg
)
140 ::DispatchMessage(msg
);
143 bool wxConsoleEventLoop::Dispatch()
146 if ( !GetNextMessage(&msg
) )
149 ProcessMessage(&msg
);
151 return !m_shouldExit
;
154 int wxConsoleEventLoop::DispatchTimeout(unsigned long timeout
)
157 int rc
= GetNextMessageTimeout(&msg
, timeout
);
161 ProcessMessage(&msg
);
163 return !m_shouldExit
;
166 #endif // wxUSE_CONSOLE_EVENTLOOP