Microsoft Knowledge Base Email Alertz

KBAlertz.com: (89739) - The Menu functions (AppendMenu(), CheckMenuItem(), CreateMenu(), CreatePopupMenu(), DeleteMenu(), DestroyMenu(), GetMenu(), GetMenuItemID(), GetMenuString(), GetSubMenu(), GetSystemMenu(), HiliteMenuItem(), InsertMenu(), LoadMenuIndirect(),...

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **


Community Site



We Send hundreds of thousands of emails using ASP.NET Email


ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 89739 - Last Review: July 11, 2005 - Revision: 1.2

INFO: Reasons for Failure of Menu Functions

This article was previously published under Q89739

SUMMARY

The Menu functions (AppendMenu(), CheckMenuItem(), CreateMenu(), CreatePopupMenu(), DeleteMenu(), DestroyMenu(), GetMenu(), GetMenuItemID(), GetMenuString(), GetSubMenu(), GetSystemMenu(), HiliteMenuItem(), InsertMenu(), LoadMenuIndirect(), ModifyMenu(), RemoveMenu(), SetMenu(), SetMenuItemBitmaps(), and TrackPopupMenu()) can fail for several reasons. Different functions return different values to indicate failure. Read the documentation for information about each function. This article combines the causes of failure for all functions and provides a resolution or explanation. A list of affected functions follows each cause. The causes are:
  1. Invalid hWnd parameter.
  2. Invalid hMenu parameter.
  3. The menu item is not found.
  4. No space left in User's heap to hold a string or to hold an internal data structure for owner draw menu items or to create a menu or to create a window for TrackPopupMenu().
  5. There are no items in the menu.
  6. The menu resource could not be found (FindResource()) or loaded (LoadResource()) or locked (LockResource()) in memory.
  7. TrackPopupMenu() is called while another popup menu is being tracked in the system.
  8. The hMenu that has been passed to TrackPopupMenu() has been deleted.
  9. MENUITEMTEMPLATEHEADER's versionNumber field is non-zero.

MORE INFORMATION

Cause 1: Invalid hWnd parameter.

Resolution 1: Validate the hWnd parameter using IsWindow(). Make sure that hWnd is not a child window.

NOTE: Resolution 1 does not apply to TrackPoupuMenu().

Explanation 1: In Windows, menus are always associated with a window. Child windows cannot have menu bars.

Affected Functions: All functions that take hWnd as a parameter except for TrackPoupuMenu().

Cause 2: Invalid hMenu parameter.

Resolution 2: Validate hMenu with IsMenu().

Affected Functions: All functions that take hMenu as a parameter.

Cause 3: The menu item is not found.

Resolution 3: If the menu item is referred to BY_POSITION, make sure that the index is lesser than the number of items. If the menu item is referred to BY_COMMAND, an application has to devise its own method of validating it.

Explanation 3: Menu items are numbered consecutively starting from 0. Remember that separator items are also counted.

Affected Functions: All functions that refer to a menu item.

Cause 4: No space left in User's heap to hold a string or to hold an internal data structure for owner draw menu items or to create a menu.

Resolution 4: Remember to delete all menus and other objects that have been created by the application when they are not needed any more. If you suspect that objects left undeleted by other applications are wasting valuable system resources, restart Windows.

Explanation 4: In Windows 3.0, menus and menu items were allocated space from User's heap. In Windows 3.1, they are allocated space from a separate heap. This heap is for the exclusive use of menus and menu items.

Affected Functions: AppendMenu(), Insertmenu(), ModifyMenu(), CreateMenu(), CreatePopupMenu(), LoadMenu(), LoadMenuIndirect(), TrackPopupMenu(), GetSystemMenu() (when fRevert = FALSE).

Cause 5: There are no items in the menu.

Resolution 5: Use GetMenuItemCount() to make sure the menu is not empty.

Explanation 5: Nothing to be deleted or removed.

Affected Functions : RemoveMenu(), DeleteMenu().

Cause 6: The menu resource could not be found (FindResource()) or loaded (LoadResource()) or locked (LockResource()) in memory.

Resolution 6: Ensure that the menu resource exists and that the hInst parameter refers to the correct hInstance. Try increasing the number of file handles using SetHandleCount() and increasing available global memory by closing some applications. For more information about the causes of failure of resource functions, query this Knowledge Base on the following keywords:
failure and LoadResource and FindResource and LockResource.
Explanation 6: Finding, loading, and locking a resource involves use of file handles, global memory, and the hInstance that has the menu resource.

Affected Functions: LoadMenu(), LoadMenuIndirect()

Cause 7. TrackPopupMenu() is called while another popup menu is being tracked in the system.

Explanation 7: Only one popup menu can be tracked in the system at any given time.

Affected Function: TrackPopupMenu()

Cause 8. The hMenu that has been passed to TrackPopupMenu() has been deleted. The debug mode of Windows 3.1 sends the following message:

"Menu destroyed unexpectedly by WM_INITMENUPOPUP"


Explanation 8: Windows sends a WM_INITMENUPOPUP to the application and expects the menu to not be destroyed.

Affected Function: TrackPopupMenu()

Cause 9. MENUITEMTEMPLATEHEADER 's versionNumber field is non-zero.

Explanation 9: In Windows 3.0 and 3.1, this field should always be 0.

Affected Function: LoadMenuIndirect()

APPLIES TO
  • Microsoft Platform Software Development Kit-January 2000 Edition
  • Microsoft Windows Software Development Kit 3.1
Keywords: 
kbinfo kbmenu kbresource KB89739
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please