Microsoft KB Archive/253308

From BetaArchive Wiki
Knowledge Base


BUG: MFT_RIGHTORDER Doesn't Work as Expected for Nonresource Menus

Article ID: 253308

Article Last Modified on 11/1/2006



APPLIES TO

  • Microsoft Platform Software Development Kit-January 2000 Edition, when used with:
    • Microsoft Windows 98 Standard Edition
    • Microsoft Windows NT 4.0



This article was previously published under Q253308

SYMPTOMS

The MFT_RIGHTORDER style doesn't work as expected (to cause the submenu to cascade from right to left) when the menu is dynamically created; that is, when the menu is not loaded from the resource.

For example, a pop-up menu (for example, a menu that contains one submenu, "color", and one item in the drop-down menu, "red") is created dynamically, by using the MFT_RIGHTORDER style, in order for the submenu to drop down from right to left. Currently, because the menu is not loaded from the resource, the submenu still drops down from left to right, even though the MFT_RIGHTORDER style is used. See the following code (this code does not work correctly with MFT_RIGHTORDER):

HMENU hmenu,submenu;
MENUITEMINFO mni, mni2;
char szMenuText[30];
POINT pt;

submenu = CreateMenu();
mni2.fMask= MIIM_DATA|MIIM_TYPE;
mni2.fType = MFT_RIGHTJUSTIFY | MFT_RIGHTORDER | MFT_STRING;
        lstrcpy(szMenuText, "red");
mni2.dwTypeData = szMenuText;
mni2.cbSize = sizeof(MENUITEMINFO);
mni2.cch        = sizeof(szMenuText); 
InsertMenuItem(submenu, 0, TRUE, &mni2);

hmenu = CreatePopupMenu();
mni.fMask= MIIM_DATA|MIIM_TYPE|MIIM_SUBMENU;
mni.fType = MFT_RIGHTJUSTIFY | MFT_RIGHTORDER | MFT_STRING;
lstrcpy(szMenuText, "color");
mni.dwTypeData = szMenuText;
mni.cbSize = sizeof(MENUITEMINFO);
mni.cch        = sizeof(szMenuText); 
mni.hSubMenu = submenu;
InsertMenuItem(hmenu,0,TRUE,&mni);

pt.x = (long) LOWORD(lParam);       
pt.y = (long) HIWORD(lParam);
ClientToScreen(hWnd,&pt);

TrackPopupMenu(hmenu, TPM_RIGHTALIGN,pt.x,pt.y, 0, hWnd,NULL);
                

RESOLUTION

To use a right-to-left drop-down submenu, you must put the menu in the resource, and then load the menu at run time, as follows:

// The menu in the resource file resembles the following:
PopupMenu MENUEX DISCARDABLE 
BEGIN
    POPUP "MOO-Dummy Popup",                65535,
    MFT_STRING | MFT_RIGHTORDER | MFT_RIGHTJUSTIFY,MFS_ENABLED
    BEGIN
        POPUP "Fonts",                          65535,
        MFT_STRING | MFT_RIGHTORDER | MFT_RIGHTJUSTIFY,MFS_ENABLED
        BEGIN
            MENUITEM "Courier",                     IDM_FONT,
            MFT_STRING | MFT_RIGHTORDER | MFT_RIGHTJUSTIFY,MFS_ENABLED
            MENUITEM "Times Roman",                 IDM_FONT,
            MFT_STRING | MFT_RIGHTORDER | MFT_RIGHTJUSTIFY,MFS_ENABLED
            MENUITEM "Swiss",                       IDM_FONT,
            MFT_STRING | MFT_RIGHTORDER | MFT_RIGHTJUSTIFY,MFS_ENABLED
            MENUITEM "Helvetica",                   IDM_FONT,
            MFT_STRING | MFT_RIGHTORDER | MFT_RIGHTJUSTIFY,MFS_ENABLED
            MENUITEM "Old English",                 IDM_FONT,
            MFT_STRING | MFT_RIGHTORDER | MFT_RIGHTJUSTIFY,MFS_ENABLED
        END
        POPUP "Sizes",                          65535,
        MFT_STRING | MFT_RIGHTORDER | MFT_RIGHTJUSTIFY,MFS_ENABLED
        BEGIN
            MENUITEM "7",                           IDM_SIZE,MFT_STRING,
            MFS_ENABLED
            MENUITEM "8",                           IDM_SIZE,MFT_STRING,
            MFS_ENABLED
            MENUITEM "9",                           IDM_SIZE,MFT_STRING,
            MFS_ENABLED
            MENUITEM "10",                          IDM_SIZE,MFT_STRING,
            MFS_ENABLED
            MENUITEM "11",                          IDM_SIZE,MFT_STRING,
            MFS_ENABLED
            MENUITEM "12",                          IDM_SIZE,MFT_STRING,
            MFS_ENABLED
            MENUITEM "14",                          IDM_SIZE,MFT_STRING,
            MFS_ENABLED
        END
        POPUP "Styles",                         65535,
        MFT_STRING | MFT_RIGHTORDER | MFT_RIGHTJUSTIFY,MFS_ENABLED
        BEGIN
            MENUITEM "Bold",                        IDM_STYLE,MFT_STRING,
            MFS_ENABLED
            MENUITEM "Italic",                      IDM_STYLE,MFT_STRING,
            MFS_ENABLED
            MENUITEM "Strike Out",                  IDM_STYLE,MFT_STRING,
            MFS_ENABLED
            MENUITEM "Superscript",                 IDM_STYLE,MFT_STRING,
            MFS_ENABLED
            MENUITEM "Subscript",                   IDM_STYLE,MFT_STRING,
            MFS_ENABLED
        END
    END
END
                

The code to load that right-to-left pop-up menu would resemble the following:

    HMENU hMenu;
    HMENU hMenuTrackPopup;

    /* Get the menu for the popup from the resource file. */ 
    hMenu = LoadMenu (hInst, "PopupMenu");
    if (!hMenu)
        return;

    /* Get the first menu in it, which we will use for the call to
     * TrackPopup(). This could also have been created on the fly using
     * CreatePopupMenu and then we could have used InsertMenu() or
     * AppendMenu.
     */ 
    hMenuTrackPopup = GetSubMenu (hMenu, 0);

    /* Convert the mouse point to screen coordinates because that is what
     * TrackPopup expects.
     */ 
    ClientToScreen (hwnd, (LPPOINT)&point);

    /* Draw and track the "floating" pop-up menu. */ 
    TrackPopupMenu (hMenuTrackPopup, 0, point.x, point.y, 0, hwnd, NULL);

    /* Destroy the menu because we are done with it. */ 
    DestroyMenu (hMenu);
                

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

Keywords: kbbidi kbbug kblocalization kboswin2000fix kboswin98fix kbpending KB253308