Right align main menu items #128

In most applications all (top level) menu items are aligned at the left side of the menu bar. I'm sure you have seen applications with at least one item aligned on the right side. In most cases this was the "Help" menu item.

  1. Add a TMainMenu component to a form (Form1)
  2. Add several (top level) menu items (with sub items)
  3. Have a menu item named "HelpMenuItem"
  4. Use the code below in the form's OnCreate event.
procedure TForm1.FormCreate(Sender: TObject) ;
  mii: TMenuItemInfo;
  MainMenu: hMenu;
  Buffer: array[0..79] of Char;
  MainMenu := Self.Menu.Handle;

  //GET Help Menu Item Info
  mii.cbSize := SizeOf(mii) ;
  mii.fMask := MIIM_TYPE;
  mii.dwTypeData := Buffer;
  mii.cch := SizeOf(Buffer) ;
  GetMenuItemInfo(MainMenu, HelpMenuItem.Command, false, mii) ;

  //SET Help Menu Item Info
  mii.fType := mii.fType or MFT_RIGHTJUSTIFY;
  SetMenuItemInfo(MainMenu, HelpMenuItem.Command, false, mii) ;
Author: Shlomo Abuisak
Contributor: Shlomo Abuisak
Added: 2009/11/05
Last updated: 2009/11/05