Using Menus and Dialogs in SDI and MDI Fortran Windows Applications

This section describes the following topics:

Creating the Menu

When you create a new SDI or MDI application using the Fortran Windows AppWizard, a default menu bar is created for you. The default menu bar contains many of the menu entries that are common to Windows applications. You can modify the default menu, or create a new menu, by using the Menu Editor, which is one of the Developer Studio Resource Editors.

To create a new menu resource (menu bar):

  1. Click Resource from the Insert menu
  2. Select Menu as the resource type

The menu bar consists of multiple menu names, where each menu name contains one or more items. You can use the Menu Editor to create submenus (select the pop-up property).

To edit an existing menu:

  1. Select the ResourceView
  2. Expand the Menu item in the list of resource types
  3. Double click on the menu mame

For more information about the menu resource editor, see the Visual C++ User's Guide section on Resource Editors.

Using the Menu

To use a menu bar in your Fortran application, you must load the menu resource and use it when creating the main window of the application. Code to do this is created automatically by the Fortran Windows AppWizard. The code that loads the menu resource is:

 ghMenu = LoadMenu(hInstance, LOC(lpszMenuName))

The returned menu handle is then used in the call to CreatWindowEx:

 ghwndMain = CreateWindowEx( 0, lpszClassName,         &
                                lpszAppName,               &
                                INT(WS_OVERLAPPEDWINDOW),  &
                                CW_USEDEFAULT,             &
                                0,                         &
                                CW_USEDEFAULT,             &
                                0,                         &
                                NULL,                      &
                                ghMenu,                    &
                                hInstance,                 &
                                NULL                       &
                              )

Handling Menu Messages

Windows sends a WM_COMMAND message to the main window when the user selects an item from the menu. The wParam parameter to the WM_COMMAND message contains:

For example, the following code from the main window procedure generated by the Fortran Windows AppWizard handles the WM_COMMAND messages from the File menu Exit item and the Help menu About item:

 ! WM_COMMAND: user command
    case (WM_COMMAND)
     select case ( IAND(wParam, 16#ffff ) )
 
        case (IDM_EXIT)
            ret = SendMessage( hWnd, WM_CLOSE, 0, 0 )
             MainWndProc = 0
             return
  
         case (IDM_ABOUT)
             lpszName = "AboutDlg"C
             ret = DialogBoxParam(ghInstance,LOC(lpszName),hWnd,& 
               LOC(AboutDlgProc), 0)
             MainWndProc = 0
             return
	 
	 ...

For advanced techniques with using menus, refer to the online Platform SDK section on User Interface Services, for subsections: Windows User Interface, Resources, Menus.

Using Dialogs in an SDI or MDI Application

An Fortran Windows SDI or MDI application that uses dialogs has the choice of using:

For any particular dialog box, you should use either the Visual Fortran Dialog routines or the native Win32 dialog box APIs. For example, if you create a dialog box using Win32 APIs, you cannot use the Visual Fortran dialog routines to work with that dialog box.

You should Note, for example, that the code generated by the Fortran Windows AppWizard uses the native Win32 APIs to display the About dialog box.

For more information: