GTK equivalent of PeekMessage() ?

273 views
Skip to first unread message

DavidA

unread,
Aug 11, 2009, 4:08:39 AM8/11/09
to wx-users
Hi

I have written a small wxWidgets app that uses Microsoft Windows'
PeekMessage function. My message loop is:

MSG msg;
while (PeekMessage( &msg, (HWND)0, 0, 0, PM_REMOVE ))
{
if (!eventLoop->PreProcessMessage(&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}



I want the app to also run under Linux but am aware that PeekMessage
is a Windows function. How would I write a similar cooperative tasking
loop for GTK please?

BR

David

Iulian-Nicu Șerbănoiu

unread,
Aug 11, 2009, 6:27:20 AM8/11/09
to wx-u...@googlegroups.com
This is *not* related to wx.

See the mailing list for gtk development.

http://developer.gnome.org/doc/GGAD/sec-mainloop.html
http://library.gnome.org/devel/gtk-tutorial/2.13/x1792.html

Hope those 2 links help,

Iulian
--
Iulian Şerbănoiu
MinVG - http://minvg.sourceforge.net

DavidA

unread,
Aug 11, 2009, 9:03:28 AM8/11/09
to wx-users
Hi Iulian

Thanks for the links. It looks like:

while(gtk_events_pending()) {
gtk_main_iteration();

will do what I want.

So my code will call PeekMessage() in Win32 and the above GTK code in
Linux. Which #define macro should I use to choose between these
calls? I.e. how does the compiler know which platform is targeted?

BR

David

Iulian-Nicu Șerbănoiu

unread,
Aug 12, 2009, 4:22:29 AM8/12/09
to wx-u...@googlegroups.com
Hi,

I think you are complicating things a little. I believe what you try
to achieve is easily doable with the Idle event in a cross platform
fashion.
For this you only need wxWidgets.

See: http://docs.wxwidgets.org/stable/wx_wxidleevent.html

I hope you'll make the right choice.

If you still want to use some macros to distinguish between platforms
I guess you could use the _Windows/_WIN32 macro. See compiler
documentation for more details about defined macros.

Good luck,

Iulian

PS: It is better to say what you try to achieve rather than going to
deep into low-level details. Usually there is a simpler solution...
Reply all
Reply to author
Forward
0 new messages