Intel® Fortran Compiler with Windows-Based Applications
Use Menus and Dialogs in SDI and MDI Fortran Windowing Applications
Create the Menu
When you create a new Single Document Interface (SDI) or Multiple Document Interface (MDI) application, 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 Visual Studio* Resource Editors. The Resource Editor is not available with the Visual Studio Shell.
To create a new menu resource (menu bar):
From the Insert menu, select Resource.
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:
Double-click on the project's .RC file.
Expand the Menu item in the list of resource types.
Double click on the Menu name.
Use 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. The code to do this is created automatically by the Fortran Windowing 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 & )
Handle 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:
The low-order word specifies the identifier of the menu item.
The high-order word specifies either 0 if the message is from a menu item, or 1 if the message is the result of an accelerator key. It is usually not important to distinguish between these two cases, but you must be careful to compare against only the low-order word as in the example below.
For example, the following code from the main window procedure generated by the Fortran Windowing 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 ...
Using Dialogs in an SDI or MDI Application
A Fortran Windowing SDI or MDI application that uses dialogs has the choice of using:
Intel Fortran Dialog routines.
Native Windows APIs for creating dialog boxes.
For any particular dialog box, you should use either the Intel® Fortran Compiler Dialog routines or the native Windows dialog box APIs. For example, if you create a dialog box using Windows APIs, you cannot use the Intel® Fortran Compiler 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 Windows APIs to display the About dialog box.