我用delphi在程序的标题栏上添加自己的菜单进去,运行后程序的标题栏上能显示添加后的菜单,但当我点击我添加进去的菜单后,菜单里的单击事件没有发生(菜单里已添加了单击事件)。这我有点不理解,望高手相助。添加菜单的代码如下:procedure TForm1.FormCreate(Sender: TObject);
var
  FSysMenu: HMENU;
begin
  FSysMenu := GetSystemMenu(Handle, False);//获得窗口系统菜单
  AppendMenu(FSysMenu, MF_POPUP or MF_STRING or MF_ENABLED,
    pmTitle.Handle, '标题栏测试');
end;代码在D2007和D2010试过,都没有产生事件。

解决方案 »

  1.   

    procedure   TForm1.SetNeum();   
      var   
          hd:HWnd;   
          sz:array[0..254]   of   char;   
      begin   
          hd:=GetWindow(Handle,GW_HWNDFIRST);   
          while   hd<>0   do   
              begin   
                  Appendmenu(GetSystemMenu(hd,false),MF_STRING,3,'我的菜单1');   
                  hd:=GetWindow(hd,GW_HWNDNEXT);   
              end;   
      end;
      

  2.   

    ls的代码貌似不起作用,我要的就是把popupmenu添加到程序标题栏里并能响应popupmenu里的事件,我现在就是存在无法响应popupmenu里面的事件的问题,继续等待
      

  3.   

    已经自己解决了,delphi不自动响应菜单事件,只能自己管理菜单事件了。现在散分,顶着都有机会得分,如果提出了比我更好的解决方法,分数全部奉上。明天结贴及给出我自己的方法。
      

  4.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Menus;type
      TForm1 = class(TForm)
        PopupMenu1: TPopupMenu;
        File11: TMenuItem;
        Exit11: TMenuItem;
        procedure Exit1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure Exit11Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure WMSysCommand(var Msg:TWMSysCommand);message WM_SysCommand;  end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.WMSysCommand (var Msg: TWMSysCommand);
    var
    Item:TMenuItem;
    begin
    Item := popupmenu1.FindItem (Msg.CmdType, fkCommand);
    if Item <> nil then
    Item.Click;
    inherited;
    end;
    procedure TForm1.Exit1Click(Sender: TObject);
    begin
    Close;
    end;procedure TForm1.FormCreate(Sender: TObject);
    var
    I:Integer;
    begin
    AppendMenu (GetSystemMenu (Handle, FALSE), MF_SEPARATOR, 0, '');
    with popupmenu1 do
    begin
    for I := 0 to Items.Count - 1 do
    AppendMenu(GetSystemMenu(self.Handle,FALSE),mf_Popup,
    Items[I].Handle,PAnsiChar(Items[I].Caption));
    end;
    end;
    procedure TForm1.Exit11Click(Sender: TObject);
    begin
    close;
    end;end.
    给你写好了,哎!!!!!
      

  5.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Menus;type
      TForm1 = class(TForm)
        PopupMenu1: TPopupMenu;
        procedure FormCreate(Sender: TObject);
        procedure Exit11Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure WMSysCommand(var Msg:TWMSysCommand);message WM_SysCommand;  end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.WMSysCommand (var Msg: TWMSysCommand);
    var
    Item:TMenuItem;
    begin
    Item := popupmenu1.FindItem (Msg.CmdType, fkCommand);
    if Item <> nil then
    Item.Click;
    inherited;
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    var
    I:Integer;
    begin
    AppendMenu (GetSystemMenu (Handle, FALSE), MF_SEPARATOR, 0, '');
    with popupmenu1 do
    begin
    for I := 0 to Items.Count - 1 do
    AppendMenu(GetSystemMenu(self.Handle,FALSE),mf_Popup,
    Items[I].Handle,PAnsiChar(Items[I].Caption));
    end;
    end;
    procedure TForm1.Exit11Click(Sender: TObject);
    begin
     close;
    end;end.猫咪,给你整理了一下
    猫咪,在不在了?
      

  6.   

    呵呵,海啸兄终于拿出来了,我的代码跟你差不多,都是用WM_SYSCOMMANDunit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Menus;type
      TForm1 = class(TForm)
        pmScreen: TPopupMenu;
        N1: TMenuItem;
        N2: TMenuItem;
        procedure FormCreate(Sender: TObject);
        procedure N1Click(Sender: TObject);
        procedure N2Click(Sender: TObject);
      private
        { Private declarations }
        procedure CheckMenu(var Msg: TMessage); message WM_SYSCOMMAND;//标题栏菜单
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.CheckMenu(var Msg: TMessage);
    var
      pm: TMenuItem;
    begin
      for pm in pmScreen.Items do
        if pm.Command = Msg.WParam then
        begin
          pm.Click;
          Exit;
        end;
      inherited;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      AppendMenu(GetSystemMenu(Handle, False), MF_POPUP or MF_STRING or MF_ENABLED,
        pmScreen.Handle, '标题栏选项');
    end;procedure TForm1.N1Click(Sender: TObject);
    begin
      ShowMessage('OK');
    end;procedure TForm1.N2Click(Sender: TObject);
    begin
      close;
    end;end.
    分数都给海啸兄吧。