Microsoft KB Archive/143074

= How to Highlight a Menu Option or Menu Item Programmatically =

Article ID: 143074

Article Last Modified on 9/30/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition

-



This article was previously published under Q143074



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.

  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   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}"   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  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. In the Cleanup code, type:

DO CALLMENU

 Save and generate the menu.</li>  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 </li> Run the MAINMENU program.</li></ol>

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:

110909 How to Highlight a Menu Bar and Popup Programmatically

Additional query words: VFoxWin bar

Keywords: kbcode KB143074

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.