Suppose you want to add the Cascade option to your menubar’s Window menu. This ability is not built-in, but it can be done easily through the Windows API. To cascade the windows, you send a message to the MDI client window. To get the MDI client window, use the Windows GetParent( ) function. The SendMessage( ) function is used to send the message. You add the following to the Header of your .MNU file:

if type("GetParent") # "FP"

   extern CHANDLE GetParent(CHANDLE) User32 

endif

 

if type("SendMessage") # "FP"

   extern CLONG SendMessage(CHANDLE, CUINT, CWORD, CLONG) User32 from "SendMessageA" 

endif

#define WM_MDICASCADE 0x0227

The .MNU file is executed when you assign the file to a form’s menuFile property, which includes the code in the Header. The two functions are prototyped with EXTERN. First, the TYPE( ) function is used to see if the function has already been EXTERNed. If so, there’s no need to do it again.

The GetParent( ) function is straightforward: it takes a window handle and returns the handle of the window’s parent. A form’s window handle is contained in its hWnd property. SendMessage( ) is a bit more complicated. It has both an A version and a W version. The W version does not work in Windows 95, so the A version is used. Note that the function name after the FROM is in quotes—it has to be a character or numeric expression—while the prototyped function name does not. SendMessage( ) takes a handle to the window, the message, and two parameters to the message. It returns a result value.

Finally, the #define preprocessor directive is used to define a manifest constant for the cascade message number. This #define may be found in the WINUSER.H file, one of the Windows header files in the \Include subdirectory.

Once all the setup is done, calling the function is easy. The onClick handler for the Cascade menu item is the codeblock:

{; SendMessage( GetParent( form.hWnd ), WM_MDICASCADE, 0, 0 )}

The manifest constant in the codeblock is replaced at compile-time. If you examine the codeblock, you will see the number, not the manifest constant.