怎样加自己的菜单到DELPHI的主菜单中(50分)

  • 主题发起人 主题发起人 yyanghhong
  • 开始时间 开始时间
Y

yyanghhong

Unregistered / Unconfirmed
GUEST, unregistred user!
我见一些控件, 象DOA, Asp express, 可加自己的菜单到DELPHI的主菜单中, 供程序员用,
谁知怎样作的
 
使用Delphi的Open Tools API,到/Borland/Delphi5/Source/Toolsapi的目录下看看源码,再到
/Borland/Delphi5/Demos/ToolsAPI看看他们的Demo,如果理解了一切OK
 
To hwave:
Thanks your suggestion, I knew how to use Tools API add submenu to delphi main menu, but i don't
know how to add menu to delphi main menu, here is a sample about how to add submenu
to delphi, if you know, could you tell me

unit SubhaExp;

interface

uses Windows,Menus,ExtCtrls,SysUtils,Forms,ToolsApi;

Type
TSubhaMenu = Class

Private
FMainMenu : TMainMenu;
FFileMenu : TMenuItem;
FGiriMenu : TMenuItem;
Procedure OnMenuItemClick(Sender : TObject);

Public
Procedure AddMenuItem;
Procedure RemoveMenuItem;

End;

Var FSubhaMenu : TSubhaMenu;

Procedure Register;

implementation

Procedure TSubhaMenu.AddMenuItem;
Var i : Integer;
Begin

FMainMenu := (BorlandIDEServices As INTAServices).MainMenu;
For i := 0 to FMainMenu.Items.Count - 1 Do
Begin
If AnsiSameCaption(FmainMenu.items.Caption, 'File') Then
Begin
FFileMenu := FMainMenu.items;
Break;
End;
End;

FGiriMenu := TMenuItem.Create(FFileMenu);
FGiriMenu.Caption := 'Subha IDE Services';
FGiriMenu.OnClick := OnMenuItemClick;

For i := 0 to FFileMenu.count - 1 Do
Begin
If FFileMenu.Items.isLine Then
Begin
FFileMenu.Insert(i,FGiriMenu);
Break;
End;
End;

End;

Procedure TSubhaMenu.RemoveMenuItem;
Var i : Integer;
Begin
For i := 0 to FFileMenu.Count - 1 Do
Begin
If AnsiSameCaption(FFileMenu.Items.Caption,'Subha IDE Services') Then
Begin
FFileMenu.Remove(FFileMenu.items);
Break;
End;
End;
End;

Procedure TSubhaMenu.OnMenuItemClick(Sender : TObject);
Begin
Application.MessageBox(PChar('This Is only a Simple Example' +
' to Work With Delphi IDE ' + #13#10 + ' For Further Details On This Contact' +
#13#10#13#10 + ' Subha@botree.co.in'),PChar('Message From Subha'),MB_OK);
End;

Procedure Register;
Begin
FSubhaMenu.AddMenuItem;
Application.MessageBox('Subha Narayanan Has Hacked Your ' +
' Delphi Environment !!! ' + #13#10 +
' See You Soon With Lot More Goodies !!! ' +
#13#10 + ' CopyRight (c) 2001, Subha Narayanan. ',
' Welcome To Delphi ',MB_SYSTEMMODAL);
End;

Initialization
FSubhaMenu := TSubhaMenu.Create;

Finalization
FSubhaMenu.RemoveMenuItem;
FSubhaMenu.Free;

end.
 
主菜单和子菜单都是TMenuitem类,你能加子菜单,当然也就能加子菜单了,这两者根本没什么区别啊
你要是想看例子,就去www.gexperts.org去看Gexperts的源码吧
 
to hubdog
thanks, I get
FGExpertsMenu := TMenuItem.Create(nil);
FGExpertsMenu.Caption := 'GE&xperts'; // do not localize
FGExpertsMenu.Name := 'GExperts'; // do not localize

// Insert GExperts drop down menu.
{$IFDEF GX_UseNativeToolsApi}
MainMenu := (BorlandIDEServices as INTAServices).MainMenu;
{$ELSE}
MainMenu := Application.MainForm.Menu;
{$ENDIF GX_UseNativeToolsApi}
Assert(Assigned(MainMenu), 'MainMenu component not found');
MainMenu.Items.Insert(MainMenu.Items.Count - 2, FGExpertsMenu);
 
多人接受答案了。
 
后退
顶部