simple_message_pump Member Reference


simple_message_pump()

simple_message_pump

constructor, public

The constructor is unsurprising.


~simple_message_pump()

simple_message_pump

destructor, public

The destructor is unsurprising.


bool report_error (const classics::exception&)

simple_message_pump

virtual, protected

This is called when pumpit catches an exception. The default implementation calls exception::show. Since the behavior of show can be customized on an application-wide basis, you probably don’t need to override this function to provide for display and/or logging of the error.

However, this function will return true to indicate a fatal error. If it returns false, the pumpit function will re-enter the mainloop. If it is fatal, then pumpit returns, just like it would if a WM_QUIT message had been posted.

So, you can override this function to take special cleanup action or indicate which errors are fatal. The default implementation always returns false (non-fatal).


int mainloop()

simple_message_pump

virtual, protected

This is the canonocal logic of the message pump. It looks aproximatly like this:

MSG msg;
while ( GetMessage(msg) ) {
if (msg.hwnd == 0)  thread_message (msg);
else {
   if (!pre_translate (msg)) {  // check IsDialog,  TranslateAccelerator
      if (!translate_key_even(msg))  // Win32 TranslateMessage
         DispatchMessage(msg);
         }
      }
   }
return (msg.wParam);

Override this if you need to customize this beyond the point provided for by the virtual functions provided for the individual steps.


bool pre_translate (MSG&)

simple_message_pump

virtual, protected

This implements the Tomahawk mechanism for having windows know how to pre-translate their own messages, instead of the main loop having to be aware of every modeless dialog box and accelerator table in the application.

It works by sending a WM_TOMAHAWK pre_translate_message to the target window. If that does not return a code stating that it was handled, it tries the parent window. It continues checking enclosing windows until it is handled or it runs out of windows to try.

This will ensure that any window within a dialog box will have the proper dialog box pre-translation done, and any child of a main application window will have accelerators performed if the accelerator key handling is done by the main window.

You can customize the handling by overriding this function. For example, you may want the “scope” of accelerator keys to be different, or you can handle modal dialog boxes that are not hooked by Tomahawk, or there may be other kinds of pre-translation needed by your program.


int pumpit() throw()

simple_message_pump

public

This calls mainloop, and adds error handling. The mainloop is broken out separatly so it can be replaced, while still keeping the error handling code in place.

This is the function you call to run the message pump. It returns with the wParam from the WM_QUIT message.


void thread_message (MSG&)

simple_message_pump

virtual, protected

This is called for all messages that have 0 for the window handle. None of the regular processing is done on these messages (see mainloop). The base implementation does nothing. You need to implement it to know about the thread messages you are expecting.

A “thread message” is caused by a call to the Win32 functionPostThreadMessage.


bool translate_key_event (MSG&)

simple_message_pump

virtual, protected

This calls the Win32 function TranslateMessage. Override this if you want to do something different than normal at this stage of processing.