線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:3052
推到 Plurk!
推到 Facebook!

加一個選單項目到delphi中

 
flyup
資深會員


發表:280
回覆:508
積分:385
註冊:2002-04-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-02-24 01:47:58 IP:61.216.xxx.xxx 未訂閱
unit MenuItem;    // 加一個選單項目到delphi中
// Edit the PopupMenu1 component using Delphi's normal
// menu editor. The wizard moves all the menu items from the
// popup menu to Delphi's menu bar. When the wizard is freed,
// it destroys the data module. The data module still owns the
// menu item components, so it frees them automatically.    interface    uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ToolsAPI, Menus;    type
  TWizardDataModule = class(TDataModule)
    PopupMenu1: TPopupMenu;
    Test1: TMenuItem;
    procedure Test1Click(Sender: TObject);
    procedure WizardDataModuleCreate(Sender: TObject);
    procedure WizardDataModuleDestroy(Sender: TObject);
  private
{ Private declarations }
  public
{ Public declarations }
  end;    var
  WizardDataModule: TWizardDataModule;    procedure Register;    implementation    {$R *.DFM}    type
  TWizard = class(TInterfacedObject, IOTAWizard, IOTANotifier)
  public
    procedure AfterSave;
    procedure BeforeSave;
    procedure Destroyed;
    procedure Execute;
    procedure Modified;
    function GetState: TWizardState;        function GetIDString: string;
    function GetName: string;        constructor Create;
    destructor Destroy; override;
  end;    procedure Register;
begin
  RegisterPackageWizard(TWizard.Create);
end;    procedure TWizardDataModule.Test1Click(Sender: TObject);
begin
  ShowMessage('Test menu item!');
end;    procedure TWizardDataModule.WizardDataModuleDestroy(Sender: TObject);
begin
  WizardDataModule := nil;
end;    procedure TWizardDataModule.WizardDataModuleCreate(Sender: TObject);
var
  EditMenu: TMenuItem;
  InsertPosition: Integer;
  Item: TMenuItem;
  I: Integer;
begin
  EditMenu := (BorlandIDEServices as INTAServices).MainMenu.Items[1];    // Move all the items from PopupMenu1 to the Edit menu,
// right after SelectAll.    // Start by finding where to insert the new item.
  InsertPosition := EditMenu.Count; // default is at end of menu
  for I := 0 to EditMenu.Count - 1 do
    if CompareText(EditMenu[I].Name, 'EditSelectAll') = 0 then
    begin
      InsertPosition := I;
      Break;
    end;      for I := PopupMenu1.Items.Count - 1 downto 0 do
  begin
// Remove the item from the popup menu.
    Item := PopupMenu1.Items[I];
    PopupMenu1.Items.Delete(I);
// Then add it to Delphi's menu.
    EditMenu.Insert(InsertPosition, Item);
  end;
end;    { TWizard }    constructor TWizard.Create;
begin
  WizardDataModule := TWizardDataModule.Create(nil);
end;    destructor TWizard.Destroy;
begin
  WizardDataModule.Free;
end;    function TWizard.GetIDString: string;
begin
  Result := 'Tempest Software.Menu Item Example Wizard';
end;    function TWizard.GetName: string;
begin
  Result := 'Menu Item Example';
end;    // The following are stubs that Delphi never calls.    procedure TWizard.AfterSave;
begin
end;    procedure TWizard.BeforeSave;
begin
end;    procedure TWizard.Destroyed;
begin
end;    procedure TWizard.Execute;
begin
end;    function TWizard.GetState: TWizardState;
begin
  Result := [];
end;    procedure TWizard.Modified;
begin
end;    end.    
問題..希望不是最後才發生!建議一次問完!
系統時間:2017-07-22 2:46:30
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!