Using Intel® Visual Fortran to Create and Build Windows*-Based Applications

ID 757211
Date 7/23/2021
Document Table of Contents
Give Feedback

Controlling Menus

You do not have to use the default QuickWin menus. You can eliminate and alter menus, menu item lists, menu titles or item titles. The QuickWin functions that control menus are described in the following sections:

Controlling the Initial Menu and Frame Window

You can change the initial appearance of an application's default frame window and menus by defining an INITIALSETTINGS function. If no user-defined INITIALSETTINGS function is supplied, QuickWin calls a predefined (default)INITIALSETTINGS routine that provides a default frame window and menu.

Your application does not call INITIALSETTINGS. If you supply the function in your project, QuickWin calls it automatically.

If you supply it, INITIALSETTINGS can call QuickWin functions that set the initial menus and the size and position of the frame window. Besides the menu functions, SETWSIZEQQ can be called from your INITIALSETTINGS function to adjust the frame window size and position before the window is first drawn.

The following is a sample of INITIALSETTINGS:

    LOGICAL result
    TYPE (qwinfo) qwi
 ! Set window frame size.
    qwi%x = 0
    qwi%y = 0
    qwi%w = 400
    qwi%h = 400
    qwi%type = QWIN$SET
    i = SetWSizeQQ( QWIN$FRAMEWINDOW, qwi )
 ! Create first menu called Games.
    result = APPENDMENUQQ(1, $MENUENABLED, '&Games'C, NUL )
 ! Add item called TicTacToe.
 ! Draw a separator bar.
 ! Add item called Exit.
 ! Add second menu called Help.
    result = APPENDMENUQQ(2, $MENUENABLED, '&Help'C, NUL )
    result = APPENDMENUQQ(2, $MENUENABLED, '&QuickWin Help'C, WININDEX)

QuickWin executes your INITIALSETTINGS function during initialization, before creating the frame window. When your function is done, control returns to QuickWin and it does the remaining initialization. The control then passes to the Fortran application.

You only need to include the code for an INITIALSETTINGS function in your project. If it is part of your project, you do not need to call your INITIALSETTINGS function.

The INITIALSETTINGS function can specify the position and size of the frame window and the contents of the menus. Because the INITIALSETTINGS function is executed before creating the frame window, it must not call any routines that require that frame window initialization be complete. For example, routines that refer to the child window in focus (such as SETWINDOWCINFIG) or a specific child window unit number (such as OPEN) should not be called from the INITIALSETTINGS function.

Your INITIALSETTINGS function should return .TRUE. if it succeeds, and .FALSE. otherwise. The QuickWin default function returns a value of .TRUE. only.

Note that default menus are created after INITIALSETTINGS has been called, and only if you do not create your own menus. Therefore, using DELETEMENUQQ, INSERTMENUQQ, APPENDMENUQQ, and the other menu configuration QuickWin functions while in INITIALSETTINGS affects your custom menus, not the default QuickWin menus.

Deleting, Inserting, and Appending Menu Items

Menus are defined from left to right, starting with 1 at the far left. Menu items are defined from top to bottom, starting with 0 at the top (the menu title itself). Within INITIALSETTINGS, if you supply it, you can delete, insert, and append menu items in custom menus. Outside INITIALSETTINGS, you can alter the default QuickWin menus as well as custom menus at any point in your application. (Default QuickWin menus are not created until after INITIALSETTINGS has run and only if you do not create custom menus.)

To delete a menu item, specify the menu number and item number in DELETEMENUQQ. To delete an entire menu, delete item 0 of that menu. For example:

  LOGICAL status
  status = DELETEMENUQQ(1, 2) ! Delete the second menu item from
                             ! menu 1 (the default FILE menu).
  status = DELETEMENUQQ(5, 0) ! Delete menu 5 (the default Windows
                             ! menu).

INSERTMENUQQ inserts a menu item or menu and registers its callback routine. QuickWin supplies several standard callback routines such as WINEXIT to terminate a program, WININDEX to list QuickWin Help, and WINCOPY which copies the contents of the current window to the Clipboard. A list of available callbacks is given in the Language Reference for INSERTMENUQQ and APPENDMENUQQ.

Often, you will supply your own callback routines to perform a particular action when a user selects something from one of your menus.

In general, you should not assign the same callback routine to more than one menu item because a menu item's state might not be properly updated when you change it (put a check mark next to it, gray it out, or disable, or enable it). You cannot insert a menu item or menu beyond the existing number; for example, inserting item 7 when 5 and 6 have not been defined yet. To insert an entire menu, specify menu item 0. The new menu can take any position among or immediately after existing menus.

If you specify a menu position occupied by an existing menu, the existing menu and any menus to the right of the one you add are shifted right and their menu numbers are incremented.

For example, the following code inserts a fifth menu item called Position into menu 5 (the default Windows menu):

  LOGICAL status
  status = INSERTMENUQQ (5, 5, $MENUCHECKED, 'Position'C, WINPRINT)

The next code example inserts a new menu called My List into menu position 3. The menu currently in position 3 and any menus to the right (the default menus View, State, Windows, and Help) are shifted right one position:

  LOGICAL status

You can append a menu item with . The item is added to the bottom of the menu list. If there is no item yet for the menu, your appended item is treated as the top-level menu item, and the string you assign to it appears on the menu bar.

The QuickWin menu routines like INSERTMENUQQ and APPENDMENUQQ let you to create a single level of menu items beneath a menu name. You cannot create submenus with the QuickWin project type.

The following code uses APPENDMENUQQ to append the menu item called Cascade Windows to the first menu (the default File menu):

  LOGICAL status
  status = APPENDMENUQQ(1, $MENUCHECKED, 'Cascade Windows'C,   &

The $MENUCHECKED flag in the example puts a check mark next to the menu item. To remove the check mark, you can set the flag to $MENUUNCHECKED in the MODIFYMENUFLAGSQQ function. Some predefined routines (such as WINSTATUS) take care of updating their own check marks. However, if the routine is registered to more than one menu item, the check marks might not be properly updated. See APPENDMENUQQ or INSERTMENUQQ in the Language Reference for the list of callback routines and other flags.

Modifying Menu Items

MODIFYMENUSTRINGQQ can modify the string identifier of a menu item, MODIFYMENUROUTINEQQ can modify the callback routine called when the item is selected, and MODIFYMENUFLAGSQQ can modify a menu item's state (such as enabled, grayed out, checked, and so on).

The following example code uses MODIFYMENUSTRINGQQ to modify the menu string for the fourth item in the first menu (the File menu by default) to Tile Windows, it uses MODIFYMENUROUTINEQQ to change the callback routine called if the item is selected to WINTILE, and uses MODIFYMENUFLAGSQQ to put a check mark next to the menu item:

  status = MODIFYMENUSTRINGQQ( 1, 4, 'Tile Windows'C)

Creating a Menu List of Available Child Windows

By default, the Windows menu contains a list of all open child windows in your QuickWin applications. SETWINDOWMENUQQ changes the menu which lists the currently open child windows to the menu you specify. The list of child window names is appended to the end of the menu you choose and deleted from any other menu that previously contained it. For example:

  LOGICAL status
 ! Append list of open child windows to menu 1 (the default File menu)

Simulating Menu Selections

CLICKMENUQQ simulates the effect of clicking or selecting a menu command from the Window menu. The QuickWin application behaves as though the user had clicked or selected the command. The following code fragment simulates the effect of selecting the Tile item from the Window menu:

  INTEGER status

Items from the Window menu can be specified in CLICKMENUQQ. Other predefined routines such as WINFULLSCREEN and WINSIZETOFIT (see the callback subroutine names listed in APPENDMENUQQ) can be invoked by calling CLICKMENUQQ with an argument containing the LOC intrinsic function before the callback routine name. For example, the following program calls WINSIZETOFIT:

! Some of the callback subroutine names listed in APPENDMENUQQ may not
! work or be useful in this context, but they will be "called."
! Run the program and note how the scroll bars disappear
     use IFQWIN
     integer result
     character*1 ch
     print *,'type a character'
     read(*,*) ch
     result = clickmenuqq(loc(WINSIZETOFIT))
     print *,'type a character'
     read(*,*) ch