How to Highlight a Menu Option or Menu Item Programmatically

Last reviewed: January 30, 1996
Article ID: Q143074
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, versions 3.0 and 3.0b

SUMMARY

Upon startup of an application, you may want to have a specific menu or menu option highlighted by default so that the user need only press the ENTER key to carry out the associated command. This article presents a simple way to do it.

MORE INFORMATION

This method, which depends on the KEYBOARD command, can be used with either FoxPro for Windows or Visual FoxPro.

  1. Create a program, name it MAINMENU, and put the following code in it:

    SET SYSMENU OFF DO testmenu.mpr READ EVENTS SET SYSMENU TO DEFAULT

  2. Create another program, name it CALLMENU, and put the following code in it:

    Keyboard "{F10}" Keyboard "{Rightarrow}" Keyboard "{Enter}" Keyboard "{dnarrow}" Keyboard "{dnarrow}" Keyboard "{dnarrow}"

  3. Create a new menu named testmenu, and give it the following structure and prompts:

       Prompt         Command
       -----------------------------------
       QUIT           CLEAR EVENTS
       FORMS          Submenu
         |
         +---Form 1   Wait Window "Form 1"
         +---Form 2   DO FORM FORM2
    
    

  4. In Visual FoxPro, on the View menu, choose General Options, and select Cleanup. In FoxPro for Windows, on the Menu menu, choose General options, and select Cleanup.

  5. In the Cleanup code, type:

    DO CALLMENU

  6. Save and generate the menu.

  7. Create a new form, name it FORM2, and place a command button on it. Put the following code in the command button's Click event:

    THISFORM.RELEASE DO CALLMENU

  8. Run the MAINMENU program.

This should cause the menu prompt 'Form 2' to be highlighted. Pressing the ENTER runs the form, and clicking the command button closes the form and cycles the menu back to the 'Form 2' prompt.

This method can be called an unlimited number of times without running into the 'Do nesting too deep' error message you may encounter if you use the ACTIVATE MENU command. The other significant advantage is that the use of the KEYBOARD command allows you to drill down to a specific menu option (in this case, Form 2). The disadvantage to this method is that there is a flicker as the keyboard commands are executed.

For information about how to do this with FoxPro 2.x, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q110909
   TITLE     : How to Highlight a Menu Bar and Popup Programmatically


Additional reference words: 3.00 3.00b VFoxWin bar
KBCategory: kbprg kbhowto kbcode
KBSubcategory: FxprgGeneral


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.