The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

GUI APIs - How is it basically done


I'm currently going deeper into Win32 programming. To become a broader overview of GUI concepts, I want to know how it is done on the different GUI systems, related to the basic naked API without any extended framework (like MFC) and without going too deep into the details. I'm programming in plain C, BTW.

To explain what I mean, I will describe the basic structure of a single-threaded Win32 application:

The GUI part is made by rectangular screen areas, the windows. Any single element, the main window, controls, buttons, edit fields, etc. is a separate window on its own.

Associated with any of these windows is a specific window procedure. If an action happens (keyboard, mouse, redraw necessary) which is related to the specific window, the associated procedure is called. The action is denoted by a message number, the necessary parameters are given through the procedure's arguments. The procedure must differentiate between the different messages, usually resulting in a big switch(Message) statement. Unhandled messages are simply given to a default procedure.

Associated with the main window is a single message queue where all messages for the main window and all the child windows are going into. This message queue must be read out in the application's main loop.

Thus the general structure of the main action loop looks like this:

  case WM_CREATE:
  case WM_PAINT:
  case WM_DESTROY:

  return DefaultProc(Message);


while (NotQuit)
  Message = NextMessageFromQueue()
    --> Will identify and call related WindowProc()

There is only the one single thread of execution, i.e. the WindowProc won't be called out of nothing with an OS-created thread while the main thread is in another WindowProc. All calls will happen while DispatchMessage is called, though the WindowProc can directly and recursively be called anytime out of this main thread.


So far, this is the information I'm searching for. How is the main action loop done on other systems? WinFX, KDE, Gnome, X-Windows, MacOS, whatever there is. I want to find out where the similarities and where the differences are.
Friday, August 05, 2005
KDE, Gnome and other window managers/desktop environments all run using a X Windows main loop. Gnome uses the GTK toolkit (visit for a tutorial, reference docs and such) while KDE uses Qt (visit for info).
Johan Thelin Send private email
Sunday, August 07, 2005
X11, on which KDE/Gnome are built, looks basically the same if you are using XLib. You call XNextEvent and give it a display and an event pointer to fill, and it... I forget what it does when there isn't an event. Oh well.

An architecture difference, though, is that XLib is a thin library that just prepares messages to be sent over a Unix or network socket to the server. You don't have to use XLib, but in reality almost everything does.

Quick tutorial on the subject by yours truly:
Jesse Millikan
Monday, August 08, 2005
Why not take a look at the wxWidgets source code:
Jussi Jumppanen
Monday, August 08, 2005

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz