Thread: Menu Item Caption - /a for right aligned Accelerator?

  1. #1
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278

    Menu Item Caption - \a for right aligned Accelerator?

    I know that the tab character (\t) jumps the menu caption text into the next 'column', so all accelerators line up in the menu, but I heard that \a is supposed to right align any text that follows it, and this is not the case on my machine (MSVC++ 6.0, WinXP)... I know this is not a big deal, and some programs leave the accelerators left aligned in the menus, but WinXP definitely allows right alignment, as MSVC++ does this itself in its own menus.

    What is the proper escape sequence for right alignment within the menu captions, if it is not \a?

    Note: I have tried all the letters a..z watching the sample display in realtime, but have not compiled every one, so there remains a possibility that the realtime sample display is incorrect.
    Also: I have checked the resource file, and the resource editor is properly storing the \a sequence in it, so this is not the problem.

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Cut and Past:

    Code:
    MENUITEMINFO Structure
    
    --------------------------------------------------------------------------------
    
    The MENUITEMINFO structure contains information about a menu item. 
    
    Syntax
    
    typedef struct tagMENUITEMINFO {
      UINT    cbSize; 
      UINT    fMask; 
      UINT    fType; 
      UINT    fState; 
      UINT    wID; 
      HMENU   hSubMenu; 
      HBITMAP hbmpChecked; 
      HBITMAP hbmpUnchecked; 
      ULONG_PTR dwItemData; 
      LPTSTR  dwTypeData; 
      UINT    cch; 
      HBITMAP hbmpItem;
    } MENUITEMINFO, *LPMENUITEMINFO; 
    
    Members
    
    cbSize
    Size of structure, in bytes. The caller must set this to sizeof(MENUITEMINFO). 
    fMask
    Members to retrieve or set. This member can be one or more of these values. 
    MIIM_BITMAP
    Microsoft® Windows® 98/Windows Millennium Edition (Windows Me), Windows 2000/Windows XP: Retrieves or sets the hbmpItem member.
    MIIM_CHECKMARKS
    Retrieves or sets the hbmpChecked and hbmpUnchecked members.
    MIIM_DATA
    Retrieves or sets the dwItemData member.
    MIIM_FTYPE
    Windows 98/Windows Me, Windows 2000/Windows XP: Retrieves or sets the fType member.
    MIIM_ID
    Retrieves or sets the wID member.
    MIIM_STATE
    Retrieves or sets the fState member.
    MIIM_STRING
    Windows 98/Windows Me, Windows 2000/Windows XP: Retrieves or sets the dwTypeData member.
    MIIM_SUBMENU
    Retrieves or sets the hSubMenu member.
    MIIM_TYPE
    Retrieves or sets the fType and dwTypeData members. Windows 98/Me, Windows 2000/XP: MIIM_TYPE is replaced by MIIM_BITMAP, MIIM_FTYPE, and MIIM_STRING.
    fType
    Menu item type. This member can be one or more of the following values.
    The MFT_BITMAP, MFT_SEPARATOR, and MFT_STRING values cannot be combined with one another. Set fMask to MIIM_TYPE to use fType.
    
    Windows 98/Me and Windows 2000/XP: fType is used only if fMask has a value of MIIM_FTYPE. 
    
    MFT_BITMAP
    Displays the menu item using a bitmap. The low-order word of the dwTypeData member is the bitmap handle, and the cch member is ignored.
    Windows 98/Me, Windows 2000/XP: MFT_BITMAP is replaced by MIIM_BITMAP and hbmpItem. 
    
    MFT_MENUBARBREAK
    Places the menu item on a new line (for a menu bar) or in a new column (for a drop-down menu, submenu, or shortcut menu). For a drop-down menu, submenu, or shortcut menu, a vertical line separates the new column from the old.
    MFT_MENUBREAK
    Places the menu item on a new line (for a menu bar) or in a new column (for a drop-down menu, submenu, or shortcut menu). For a drop-down menu, submenu, or shortcut menu, the columns are not separated by a vertical line.
    MFT_OWNERDRAW
    Assigns responsibility for drawing the menu item to the window that owns the menu. The window receives a WM_MEASUREITEM message before the menu is displayed for the first time, and a WM_DRAWITEM message whenever the appearance of the menu item must be updated. If this value is specified, the dwTypeData member contains an application-defined value.
    MFT_RADIOCHECK
    Displays selected menu items using a radio-button mark instead of a check mark if the hbmpChecked member is NULL.
    MFT_RIGHTJUSTIFY
    Right-justifies the menu item and any subsequent items. This value is valid only if the menu item is in a menu bar.
    MFT_RIGHTORDER
    Windows 95/98/Me, Windows 2000/XP: Specifies that menus cascade right-to-left (the default is left-to-right). This is used to support right-to-left languages, such as Arabic and Hebrew.
    MFT_SEPARATOR
    Specifies that the menu item is a separator. A menu item separator appears as a horizontal dividing line. The dwTypeData and cch members are ignored. This value is valid only in a drop-down menu, submenu, or shortcut menu.
    MFT_STRING
    Displays the menu item using a text string. The dwTypeData member is the pointer to a null-terminated string, and the cch member is the length of the string.
    Windows 98/Me, Windows 2000/XP: MFT_STRING is replaced by MIIM_STRING.
    
    fState
    Menu item state. This member can be one or more of these values. Set fMask to MIIM_STATE to use fState. 
    MFS_CHECKED
    Checks the menu item. For more information about selected menu items, see the hbmpChecked member.
    MFS_DEFAULT
    Specifies that the menu item is the default. A menu can contain only one default menu item, which is displayed in bold.
    MFS_DISABLED
    Disables the menu item and grays it so that it cannot be selected. This is equivalent to MFS_GRAYED.
    MFS_ENABLED
    Enables the menu item so that it can be selected. This is the default state.
    MFS_GRAYED
    Disables the menu item and grays it so that it cannot be selected. This is equivalent to MFS_DISABLED.
    MFS_HILITE
    Highlights the menu item.
    MFS_UNCHECKED
    Unchecks the menu item. For more information about clear menu items, see the hbmpChecked member.
    MFS_UNHILITE
    Removes the highlight from the menu item. This is the default state.
    wID
    Application-defined 16-bit value that identifies the menu item. Set fMask to MIIM_ID to use wID.
    hSubMenu
    Handle to the drop-down menu or submenu associated with the menu item. If the menu item is not an item that opens a drop-down menu or submenu, this member is NULL. Set fMask to MIIM_SUBMENU to use hSubMenu.
    hbmpChecked
    Handle to the bitmap to display next to the item if it is selected. If this member is NULL, a default bitmap is used. If the MFT_RADIOCHECK type value is specified, the default bitmap is a bullet. Otherwise, it is a check mark. Set fMask to MIIM_CHECKMARKS to use hbmpChecked.
    hbmpUnchecked
    Handle to the bitmap to display next to the item if it is not selected. If this member is NULL, no bitmap is used. Set fMask to MIIM_CHECKMARKS to use hbmpUnchecked. 
    dwItemData
    Application-defined value associated with the menu item. Set fMask to MIIM_DATA to use dwItemData.
    dwTypeData
    Content of the menu item. The meaning of this member depends on the value of fType and is used only if the MIIM_TYPE flag is set in the fMask member. 
    To retrieve a menu item of type MFT_STRING, first find the size of the string by setting the dwTypeData member of MENUITEMINFO to NULL and then calling GetMenuItemInfo. The value of cch+1 is the size needed. Then allocate a buffer of this size, place the pointer to the buffer in dwTypeData, increment cch, and call GetMenuItemInfo once again to fill the buffer with the string. If the retrieved menu item is of some other type, then GetMenuItemInfo sets the dwTypeData member to a value whose type is specified by the fType member. 
    
    When using with the SetMenuItemInfo function, this member should contain a value whose type is specified by the fType member. 
    
    Windows 98/Me and Windows 2000/XP: dwTypeData is used only if the MIIM_STRING flag is set in the fMask member. 
    
    cch
    Length of the menu item text, in TCHARs, when information is received about a menu item of the MFT_STRING type. However, cch is used only if the MIIM_TYPE flag is set in the fMask member and is zero otherwise. Also, cch is ignored when the content of a menu item is set by calling SetMenuItemInfo. 
    Note that, before calling GetMenuItemInfo, the application must set cch to the length of the buffer pointed to by the dwTypeData member. If the retrieved menu item is of type MFT_STRING (as indicated by the fType member), then GetMenuItemInfo changes cch to the length of the menu item text. If the retrieved menu item is of some other type, GetMenuItemInfo sets the cch field to zero. 
    
    Windows 98/Me, Windows 2000/XP:  The cch member is used when the MIIM_STRING flag is set in the fMask member. 
    
    hbmpItem
    Windows 98/Me, Windows 2000/XP: Handle to the bitmap to be displayed, or it can be one of the values in the following table. It is used when the MIIM_BITMAP flag is set in the fMask member. 
    HBMMENU_CALLBACK
    A bitmap that is drawn by the window that owns the menu. The application must process the WM_MEASUREITEM and WM_DRAWITEM messages.
    HBMMENU_MBAR_CLOSE
    Close button for the menu bar.
    HBMMENU_MBAR_CLOSE_D
    Disabled close button for the menu bar.
    HBMMENU_MBAR_MINIMIZE
    Minimize button for the menu bar.
    HBMMENU_MBAR_MINIMIZE_D
    Disabled minimize button for the menu bar.
    HBMMENU_MBAR_RESTORE
    Restore button for the menu bar.
    HBMMENU_POPUP_CLOSE
    Close button for the submenu.
    HBMMENU_POPUP_MAXIMIZE
    Maximize button for the submenu.
    HBMMENU_POPUP_MINIMIZE
    Minimize button for the submenu.
    HBMMENU_POPUP_RESTORE
    Restore button for the submenu.
    HBMMENU_SYSTEM
    Windows icon or the icon of the window specified in dwItemData.
    Remarks
    
    A menu can display items using text or bitmaps, but not both.
    
    The MENUITEMINFO structure is used with the GetMenuItemInfo, InsertMenuItem, and SetMenuItemInfo functions.
    
    Windows 98/Me and Windows 2000/XP:  The menu can display items using text, bitmaps, or both.
    
    Structure Information
    
    Header Declared in Winuser.h, include Windows.h 
    Minimum operating systems Windows 95, Windows NT 4.0 
    Unicode Implemented as Unicode and ANSI versions on Windows NT, Windows 2000, Windows XP 
    
    See Also
    
    Menus Overview, GetMenuItemInfo, InsertMenuItem, SetMenuItemInfo, WM_DRAWITEM, WM_MEASUREITEM
    This is from the platform sdk. (code tags were used since it looked nasty otherwise)

  3. #3
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    master5001, thanks for the reply. I have already looked in the Platform SDK, and searched MSDN online just in case my copy is not up to date. I could find nothing that states anything except for mentioning the \t tab character. In fact, the page you posted does not even say that much, so it is rather useless for my question - not that I do not appreciate your post, but it is annoying that this page does not explain what you would expect it to explain. Actually, the \t tab character is usually mentioned in the keyboard accelerators page, which makes sense, because this is when you would need to use it. Any references I have found lack any mentioning of a right alignment character.

    I can only assume that the source that stated the use of the \a character is incorrect (which would be Charles Petzold), since I cannot imagine MS dropping this - they always keep things as backwards compatible as possible. If it existed in the past, then it should not be so difficult to find references to it. Also, I can see that the right alignment feature still exist, as programs still use it (like I said, MSVC++ 6.0 uses the right alignment in its own menus). So, the option still exists somewhere - in some other form than placing \a in the menu caption.

    Does anyone have any information regarding this?

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> MSVC++ 6.0 uses the right alignment in its own menus

    I looked at my VC++ 6.0 Pro on XP menu's and the text of the menu item is left aligned, and the accelerator right aligned, so on the File menu for example...
    Code:
    New...       Ctrl+N
    Open...      Ctrl+O
    ... and if I use "New...\aCtrl+N" and "Open...\aCtrl+O" then I get just that. Am I missing something here, or is my VC++ behaving differently from yours?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    adrianxw, thanks for the reply. I cannot use "New...\aCtrl+N" to get the right alignment. My MSVC++ 6.0 is obviously behaving differently. One thing I do note is that if you repeat a \t or \a character, it shows as a square (a character that cannot be printed), whereas the first occurance does not. For the \t, it acts as a tab. For the \a, it doesn't do anything on my machine, but it does not show as a square - so it is obvious that it is meant to do something... it just is not doing it.

    One last note: This url: Associating a Menu Item with an Accelerator Key

    (argh, apparently the forum code cannot handle the URL, I will paste it as text here:
    msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_core_associating_a_menu_item_with_an_accelerator_ key.asp
    I can't help it, this forum is NOT cooperating. The URL above gets distorted if I include http at the start, since it attempts to change it into a URL, which cannot handle a URL of that type for some reason. Pasted as a single line of text (above), it automatically creates a CR right before the "_key.asp" section, and places a SPACE in front of "_core...", even though this is not what the code says in the page. You'll have to fix these errors to get the URL to work properly. Even a Google search link for the page does not work - the forum screws up every URL with something fancy in it. Please do a google for:
    msdn "Associating a Menu Item with an Accelerator Key"
    and it is the first result.
    )


    mentions "Following the menu caption, type the escape sequence for a tab (\t), so that all the menus accelerator keys are left-aligned", but does not mention anything about right alignment...

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Code:
    IDR_MENU1 MENU DISCARDABLE 
    BEGIN
        POPUP "Crap"
        BEGIN
            MENUITEM "Crap\aF1",                    ID_CRAP_CRAP1
            MENUITEM "Stupid Crap\aF2",             ID_CRAP_STUPIDCRAP
            MENUITEM "Really Daft Crap\aF3",        ID_CRAP_REALLYDAFTCRAP
    
            MENUITEM "Absolutely Damned Idiotic Crap\aF4", 
                                                    ID_CRAP_ABSOLUTELYDAMNEDIDIOTICCRAP
    
            MENUITEM "Short Crap\aF5",              ID_CRAP_SHORTCRAP
        END
    END
    Gives me this, i.e. like a VC++ menu, yours is different?...
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    I tried your code exactly as is, and it works perfectly! Looking at your code in comparison to my code, I could find only one difference - my code used the \t tab character in some menu items (within the same menu) at the same time I was attempting to use the \a character. Thus, the only logical solution is that they are to be used mutually exclusive of each other. I changed all of my menu items from \t to \a, and it all works fine...

    Thus the comment from Charles Petzold's Programming Windows, 5th Edition:

    "For items in popup menus, you can use the columnar tab character \t in the character string. Text following the \t is placed in a new column spaced far enough to the right to accommodate the longest text string in the first column of the popup. ...snip... A \a in the character string right-justifies the text that follows it."

    is incorrect. It implies that \a only right aligns text, and that you must use a tab character and \a at the same time. The true explanation is that \a acts as a tab, to place any words that follow it into the next column, but also right aligns this column. Whereas \t left aligns text.

    However... the tab for \a is not the same tab as \t. In other words, if some menu captions use \a and some use \t, they both do not move the text that follows it into the same tab (column). They actually refer to two different tabs (which is why when I tested \a, it didn't appear to work since all of the other accelerators in other menu items remained where they were in their own column, and another column was made for the sole \a which just happens to be exactly where it would be if \a were a space - so it appeared to be doing absolutely nothing!), and therefore all menu items must use one or the other. Or, if you wish to use both at the same time, you must use them in the same order. Take a look at this screen shot below from this code:

    Code:
    IDR_MENU1 MENU DISCARDABLE 
    BEGIN
        POPUP "Crap"
        BEGIN
            MENUITEM "Crap\aF1\tNext column",       ID_CRAP_CRAP1
            MENUITEM "StupidCrap2\aF2\tThis is the tab column", 
                                                    ID_CRAP_STUPIDCRAP
            MENUITEM "Crap3\aEscape A-Column",      ID_CRAP_REALLYDAFTCRAP
            MENUITEM "AbsolutelyDamnedIdioticCrap4\tUsing Only Tab Char", 
                                                    ID_CRAP_ABSOLUTELYDAMNEDIDIOTICCRAP
    
            MENUITEM "Short Crap\aUsing Only Escape-A", ID_CRAP_SHORTCRAP
            MENUITEM "MyOwnCrap6\aRight Alignment", ID_CRAP_MYOWNCRAP
            MENUITEM "More Crap\tUsing Tab First\aThen Escape-A", 
                                                    ID_CRAP_MORECRAP
            MENUITEM "Moving Everything Over A Litte Bit..........\aF6\tTabbed", 
                                                    ID_CRAP_MOVESTUFF
        END
    END
    I should note that the menu item that says 'using tab first' has that text only ONCE, and it shows up only once in the preview screen (resource editor), but it shows up twice in the actual running of the program. This bug doesn't really matter, since you are obviously NOT supposed to use \a and \t at the same time...

    This still leaves me to wonder why this isn't explained in the SDK or MSDN...

    Thanks for your help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Immediate programming help! Please!
    By xMEGANx in forum C++ Programming
    Replies: 6
    Last Post: 02-20-2008, 12:52 PM
  2. Retail Outlet Managment System - the 4th
    By Presidentofusa in forum C Programming
    Replies: 3
    Last Post: 11-10-2007, 10:44 PM
  3. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM