Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window message procedures in Linux vs Windows

In Windows when you create a window, you must define a (c++)

LRESULT CALLBACK message_proc(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam);

to handle all the messages sent from the OS to the window, like keypresses and such.

Im looking to do some reading on how the same system works in Linux. Maybe it is because I fall a bit short on the terminology but I fail to find anything on this through google (although Im sure there must be plenty!).

  • Is it still just one single C function that handles all the communication?
  • Does the function definition differ on different WMs (Gnome, KDE) or is it handled on a lower level in the OS?

Edit: Ive looked into tools like QT and WxWidgets, but those frameworks seems to be geared more towards developing GUI extensive applications. Im rather looking for a way to create a basic window (restrict resize, borders/decorations) for my OGL graphics and retrieve input on more than one platform. And according to my initial research, this kind of function is the only way to retrieve that input.

What would be the best route? Reading up, learning and then use QT or WxWidgets? Or learning how the systems work and implement those few basic features I want myself?

like image 615
Mizipzor Avatar asked Feb 08 '09 15:02

Mizipzor


People also ask

What are the parameters of a window procedure?

A window procedure is a function that has four parameters and returns a signed value. The parameters consist of a window handle, a UINT message identifier, and two message parameters declared with the WPARAM and LPARAM data types. For more information, see WindowProc.

What is the difference between windows and Linux commands?

There is a PowerShell and a command prompt in windows as well where we may execute the commands easily. But Windows and Linux have commands with the same name as well.

Why choose Linux over Microsoft Windows?

In many ways, Linux beats its competitor, Microsoft. The open-source solutions are known for their stability, security and speed. However, to benefit from these advantages, you have to take a closer look at the operating system. Getting started is not particularly easy with any of the current Linux distributions.

Is it possible to call a window procedure recursively?

Because it is possible to call a window procedure recursively, it is important to minimize the number of local variables that it uses. When processing individual messages, an application should call functions outside the window procedure to avoid excessive use of local variables, possibly causing the stack to overflow during deep recursion.


1 Answers

Well at the very basic level you have the X Window protocol http://en.wikipedia.org/wiki/X_Window_System_core_protocol, which we can be pretty complex to handle if you want to do any application. Next on the stack there's Xlib http://en.wikipedia.org/wiki/Xlib which is a "convenient" wrapper around the X protocol, but still is complex for "real life" applications. It's on top of Xlib that most other frameworks are built, trying to simplify application development. The most know are: Xt, Gtk, Qt, etc.

Like in window you have a "event loop", and if you want you can implement on top of it a GetMessage/DispachMessage metaphor to mimic the windows behavior. That way you may have a WNDPROC, but natively X doesn't provide such thing.

Before reinventing the wheel is preferable to take a look at similar applications, what they are using.

If you need something simple you can try SDL http://www.libsdl.org/, which is a cross platform library to aimed to develop games/simple applications. Another alternative is Allegro game library http://www.talula.demon.co.uk/allegro/.

like image 184
Ismael Avatar answered Oct 04 '22 10:10

Ismael