PFC Guide Titlebar
HomeFAQLinksPFCMAGExtensionsDownloadWhat's NewSearch

Message Router FAQ

Table of Contents

  1. When the window first opens I am unable to print the datawindow.
  2. How do I use the message router from outside of the menu?
  3. How do I override the message router sequence?

What is the purpose of the message router

The main purpose of the message router is to provide a way to communicate between menus and windows.

The message router determines which window or control should receive the message ( user event ). The message router is implemented in two steps. First a menu function - of_sendmessage(), determines which window will route the message further control. Next the pfc_MessageRouter event on the window routes the message to the appropriate control.

The first step for an SDI application is simple. The of_sendmessage function tries to call the message router on the parent window. The next step leads to exit whether the window message router successfully executes the event or not.

For an MDI application the step 1 algorithm is slightly more complicated. If there is an active sheet then the message router is executed on the active sheet, otherwise it is executed on the MDI frame. If the pfc_MessageRouter is unable to find the message target control, pfc_MessageRouter is executed on the MDI frame window as well.


Step 2 is the pfc_messagerouter event. The event is created on w_master and therefore exists on every PFC window. This sequence is very important and if you are new to PFC you must memorize it.

First pfc_MessageRouter attempts to execute the event on the window itself. If that fails the message router attempts to trigger the specified event on the active control or control which currently has focus. Finally if this step fails the message router will attempt to trigger the event on the last active datawindow. Last active datawindow is the datawindow which had focus prior to the event execution.


To summarize all of the above we can simplify a little. In a most general case with an MDI application and an open sheet the message router event sequence is as follows:

  1. Active Sheet
  2. Active Control
  3. Last Active Datawindow
  4. MDI Frame
Back to Top

When the window first opens I am unable to print the datawindow.

The print menu item uses the of_sendmessage("pfc_print") function to trigger the pfc_print event on the datawindow. The message router checks to see if the event exists on the active control, which may be a datawindow, or the last active datawindow. When the window first opens the datawindow may not have focus. In that case the datawindow does not meet the message router criteria of the active control or the last active datawindow. As a result the pfc_print message will not be triggered. This applies to other datawindow events as well.

The solution to this problem is to set focus to the datawindow in the open or pfc_postopen events.

Back to Top

How do I use the message router from outside of the menu?

From within the menu the message router can be accessed by calling the of_sendmessage function, but how can it be accessed from a command button, user object function or a window event? In that case the menu function may be called through the menuid window property.

gnv_app.of_getframe().menuid.dynamic of_sendmessage("ue_dostuff")

If you prefer not to use the Dynamic calls you can cast the menuid into a variable of the m_frame type:

m_frame lm_frame
lm_frame = gnv_app.of_getframe().menuid

You can use the menuid on other windows as well.

Back to Top

How do I override the message router sequence?

If you understand the path of the message router sequence it will be obvious how to change the event flow.

As an example lets say there is a window with two datawindows, dw_detail used to display the data and dw_navigate to provide a way to search and navigate though the first datawindow. In this case it does not make sense to ever print the navigation datawindow. When the user selects a print menu item, no matter which datawindow has focus they would like to print the dw_detail.

As you may know the message router will try to execute the event on the active sheet before the datawindow. By declaring a pfc_print event on the window you can make sure that this event will execute instead of pfc_print on the active datawindow. Adding the code to print the dw_detail to this event will resolve our problem.

Back to Top

Contributed by PFCGuide staff, except where noted otherwise.
PFCGuide is sponsored by Dynamic Technology Group
The information provided is for advice only and not to be considered a contract or a liability against Dynamic Technology Group.

Last revised: February 15, 2004 03:58 AM.