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"
27 #include "wx/evtloop.h"
29 // ============================================================================
30 // wxMSWEventLoopBase implementation
31 // ============================================================================
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 wxMSWEventLoopBase::wxMSWEventLoopBase()
43 // ----------------------------------------------------------------------------
44 // wxEventLoop message processing dispatching
45 // ----------------------------------------------------------------------------
47 bool wxMSWEventLoopBase::Pending() const
50 return ::PeekMessage(&msg
, 0, 0, 0, PM_NOREMOVE
) != 0;
53 bool wxMSWEventLoopBase::GetNextMessage(WXMSG
* msg
)
55 const BOOL rc
= ::GetMessage(msg
, NULL
, 0, 0);
65 // should never happen, but let's test for it nevertheless
66 wxLogLastError(wxT("GetMessage"));
68 // still break from the loop
75 int wxMSWEventLoopBase::GetNextMessageTimeout(WXMSG
*msg
, unsigned long timeout
)
77 // MsgWaitForMultipleObjects() won't notice any input which was already
78 // examined (e.g. using PeekMessage()) but not yet removed from the queue
79 // so we need to remove any immediately messages manually
81 // NB: using MsgWaitForMultipleObjectsEx() could simplify the code here but
82 // it is not available in very old Windows versions
83 if ( !::PeekMessage(msg
, 0, 0, 0, PM_REMOVE
) )
85 // we use this function just in order to not block longer than the
86 // given timeout, so we don't pass any handles to it at all
87 DWORD rc
= ::MsgWaitForMultipleObjects
98 wxLogDebug("unexpected MsgWaitForMultipleObjects() return "
106 if ( !::PeekMessage(msg
, 0, 0, 0, PM_REMOVE
) )
108 // somehow it may happen that MsgWaitForMultipleObjects()
109 // returns true but there are no messages -- just treat it
110 // the same as timeout then
117 return msg
->message
!= WM_QUIT
;
120 // ============================================================================
121 // wxConsoleEventLoop implementation
122 // ============================================================================
124 #if wxUSE_CONSOLE_EVENTLOOP
126 void wxConsoleEventLoop::WakeUp()
129 wxWakeUpMainThread();
133 void wxConsoleEventLoop::ProcessMessage(WXMSG
*msg
)
135 ::DispatchMessage(msg
);
138 bool wxConsoleEventLoop::Dispatch()
141 if ( !GetNextMessage(&msg
) )
144 ProcessMessage(&msg
);
146 return !m_shouldExit
;
149 int wxConsoleEventLoop::DispatchTimeout(unsigned long timeout
)
152 int rc
= GetNextMessageTimeout(&msg
, timeout
);
156 ProcessMessage(&msg
);
158 return !m_shouldExit
;
161 #endif // wxUSE_CONSOLE_EVENTLOOP