Microsoft KB Archive/89218

= Microsoft Knowledge Base =

WMenu / WMenuX May Fail if Focus Is on Button or Scroll Bar
Last reviewed: October 19, 1994

Article ID: Q89218

The information in this article applies to:


 * Microsoft Test for Windows, version 1.0

SYMPTOMS
WMenu is a procedure in TESTCTRL.DLL that can be used to activate a menu or menu item in your application, based on the menu's caption.

If the focus is set to a button or scroll bar, WMenu may incorrectly fail to activate the requested menu. If the focus is on a button, WMenu may generate an unexpected &quot;click&quot; on the button. (This click is not actually a mouse event, but the button is activated as if it had been clicked.) The WMenuX procedure, which activates a menu based on its index, may fail in the same way as WMenu.

Additionally, because all of the FastTest menu procedures make use of the WMenu procedure, they may fail with the same results.

RESOLUTION
Ensure that the application being tested has an active menu at the time the WMenu / WMenuEx routine is called.

STATUS
Microsoft has confirmed this to be a bug in Microsoft Test version 1.0 for Windows. This bug was corrected in Microsoft Test version 2.0 for Windows.

MORE INFORMATION
To work around this problem, ensure that your application has an active menu (that is, pulled down) before you invoke WMenu / WMenuX (or a FastTest menu procedure). Once a menu is activated, WMenu operates correctly until you return to a state where all menus of the current window are closed and the focus is on a button or scroll bar again.

The following example demonstrates one method of activating a menu in the current window and then calling WMenu:

'$Define W_MENU '$Include: 'MSTEST.INC'

Declare Sub ActivateMenu RUN &quot;notepad.exe&quot;, NOWAIT

ActivateMenu

WMenu &quot;&File&quot;   ' Substitute desired menu name. WMenu &quot;&Open&quot;   ' Substitute desired menu item name or remove.

'********************************************************************* ' ActivateMenu &quot;pulls down&quot; the first menu of the active window. ' This procedure assumes that the first top level menu will have an ' access key (that is, its caption contains an ampersand, such as &quot;&File&quot;. '********************************************************************* Sub ActivateMenu Static  menuTitle$ = MenuText(1)  accessKey$ = Mid$(menuTitle$, InStr(menuTitle$, &quot;&&quot;) + 1, 1)  DoKeys &quot;%&quot; + accessKey$ End Sub