Search code examples
windowsdelphimenuitem

The location of the main menu items


The "Help" menu item in the Total commander is right-aligned. How is it done?

Example


Solution

  • Ah, vibrations from another millenium ;). It is doable, as follows, but I don't really see any advantage.

    procedure TForm33.FormCreate(Sender: TObject);
    begin
      ModifyMenu(MainMenu1.Handle,
                 MainMenu1.Items.Count -1,
                 MF_BYPOSITION or MF_RIGHTJUSTIFY, // MF_HELP = MF_RIGHTJUSTIFY = $4000
                 MainMenu1.Items[MainMenu1.Items.Count-1].Command,
                 '&Help' );
    end;
    

    enter image description here

    You may want to read the documentation and consider the following note:

    Note The ModifyMenu function has been superseded by the SetMenuItemInfo function. You can still use ModifyMenu, however, if you do not need any of the extended features of SetMenuItemInfo.


    Edit: In a comment you linked to an image where the "Help" item had been painted on the gradient menu bar with a non-gradient white background. Based on your image, I believe you are using Windows 7, so I fired up an old W7 machine and tested the same code with Delphi XE7 and the result is as follows:

    enter image description here

    I really don't know how I could possibly help you further, if you can't help me reproduce the problem.


    Edit2: Thanks to comment by Remy Lebeau I made a correction to the fourth parameter. It was a real blunder from my side not to update that code from my old repositories.

    The undocumented MF_HELP has the same value as the also undocumented MF_RIGHTJUSTIFY ( both are $4000 ). The latter indicates better the purpose, so I changed to that.