Forum > macOS / Mac OS X

Add a menu item to the application menu

(1/2) > >>

havezet:
This is probably a newbie question so my apologies if I overlooked the obvious.

How can I add a menu item to the application menu in MacOS? So I mean the menu titled after the application that appears at the far left, directly next to the apple menu when my application is running. I'd like to include an About menu entry there as is common in MacOS applications.

Thank you

Phil:
If you're doing cross-platform development and already have an About menu item elsewhere (e.g., on Help menu as in Windows), here's example code from this project:

http://wiki.lazarus.freepascal.org/THtmlPort

In main form declaration:

{$IFDEF LCLCarbon}
    AppMenu : TMenuItem;
{$ENDIF}

In FormCreate handler:

{$IFDEF LCLCarbon}
  AppMenu := TMenuItem.Create(Self);  //Application menu
  AppMenu.Caption := #$EF#$A3#$BF;  //Unicode Apple logo char
  MainMenu1.Items.Insert(0, AppMenu);
  MainMenu1.Items.Remove(About1);  //Remove About as separate menu
  AppMenu.Add(About1);  //Add About as item in application menu
{$ENDIF}


I'm preparing an article on this and other things that need to be done specially on Mac with Lazarus.

Thanks.

-Phil

havezet:
Thanks Phil. Works like a charm!

kamischi:
My code snippet for the about menu:

http://developer.berlios.de/snippet/detail.php?type=snippet&id=100054

Have fun.

Mischi

Phil:
http://developer.berlios.de/snippet/detail.php?type=snippet&id=100054

1. You could use VK_OEM_COMMA instead of $BC to make it clearer.

2. Preferences item normally does not have an ellipsis.

3. About item should include bundle name (app name).

Thanks.

-Phil

Navigation

[0] Message Index

[#] Next page

Go to full version