Microsoft KB Archive/86690

= Microsoft Knowledge Base =

WMenuEnabled Returns True when Menu Item Does Not Exist
Last reviewed: October 19, 1994

Article ID: Q86690

The information in this article applies to:

- Microsoft Test for Windows, versions 1.0

SYMPTOMS
The TESTCTRL.DLL function WMenuEnabled incorrectly returns True (-1) when the menu item being examined does not exist. Similarly, the FastTest routines BMenuItemExists, XMenuItemNotEnabled, and XMenuItemEnabled may give the same incorrect results, because they depend on WMenuEnabled.

RESOLUTION
Use the TestBasic function below to verify whether a menu exists as well as if the menu is enabled or not.

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
Note that, after calling the WMenuEnabled function, WError does correctly return ERR_MENU_ITEM_NOT_FOUND (2) when the menu item does not exist.

Workaround
The following function, WMenuEnabled_new, can be called instead of the WMenuEnabled function to workaround this problem:

REM $DEFINE W_MENU REM $INCLUDE: 'MSTEST.INC' DECLARE FUNCTION WMenuEnabled_new%(s$)

FUNCTION WMenuEnabled_new%(s$) STATIC

i% = WMenuEnabled(s$) AND wError <> ERR_MENU_ITEM_NOT_FOUND WMenuEnabled_new = i% END FUNCTION

To apply this workaround to the FastTest functions, modify FTESTKEY.MST to replace all occurrences of WMenuEnabled with WMenuEnabled_new. Then add the code above to the beginning of FTESTKEY.MST.

As an alternative workaround, you can use functions that check whether a menu item is unavailable, such as WMenuGrayed, or you can use functions like WError or WerrorTrap that check if the menu item in question was found.

Steps to Reproduce Problem
 Launch the Test Driver.  In a new script, type the following code: REM $DEFINE W_MENU REM $INCLUDE: 'MSTEST.INC' Run &quot;Notepad.exe&quot;, Nowait WMenu &quot;File&quot; IF WMenuEnabled(&quot;Junk&quot;) then PAUSE &quot;True&quot; ELSE PAUSE &quot;False&quot; END IF  Start the script. The script displays &quot;True&quot; instead of &quot;False.&quot;