PRB: TrackPopupMenu() on LoadMenuIndirect() Menu Causes UAE

ID Number: Q75254

3.00

WINDOWS

Summary:

SYMPTOMS

When LoadMenuIndirect() is used to create a menu from a menu

template and the menu handle is passed to TrackPopupMenu(), Windows

reports an unrecoverable application error (UAE).

CAUSE

The menu handle returned from LoadMenuIndirect() does not point to

a menu with the MF_POPUP bit set.

RESOLUTION

The following code fragment demonstrates the correct procedure to

"wrap" the menu created by LoadMenuIndirect() inside another menu.

This procedure sets the MF_POPUP bit properly.

hMenu1 = LoadMenuIndirect(lpMenuTemplate);

hMenuDummy = CreateMenu();

InsertMenu(hMenuDummy, 0, MF_POPUP, hMenu1, NULL);

hMenuToUse = GetSubMenu(hMenuDummy, 0);

Use hMenuToUse when TrackPopupMenu() is called. The values of

hMenu1 and hMenuToUse should be the same.

When the menu is no longer required, call DestroyMenu() to remove

hMenuDummy. This call will also destroy hMenu1 and free the

resources it used.