如何讓delphi窗體顯示在任務欄上?就是點擊系統菜單縮小按鈕,窗體顯示在任務欄上?

解决方案 »

  1.   

    你好我也姓吴,给段代码让你参考一下
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, shellAPI, Menus, unit2;const my_message=wm_user+88;type
      TForm1 = class(TForm)
        PopupMenu1: TPopupMenu;
        N1232131: TMenuItem;
        N2131231: TMenuItem;
        N2131: TMenuItem;
        N231231: TMenuItem;
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormPaint(Sender: TObject);
        procedure N1232131Click(Sender: TObject);
      private
        { Private declarations }
        procedure on_icon_notify(var message:TMessage);
        message my_message;
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      heng,zong:integer;implementation{$R *.dfm}procedure TForm1.on_icon_notify(var message:TMessage);
    var
    busy:Boolean;
    pt:TPoint;
    begin
    busy:=False;
      if not busy then
        begin
          busy:=True;
            if message.LParam=wm_lbuttondown then
              if Application.MessageBox('are you sure?','exit',MB_YESNO)=IDyes then close;
            if message.LParam=wm_rbuttondown then
            begin
              GetCursorPos(pt);
              self.PopupMenu1.Popup(pt.x,pt.y);
            end;
            busy:=False;
        end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    var
    nid:TNotifyIconData;
    begin
      nid.cbSize:=SIZEOF(nid);
      nid.Wnd:=Handle;
      nid.uID:=1;
      nid.hIcon:=Application.Icon.Handle;
      nid.szTip:='this is a test application!';
      nid.uCallbackMessage:=my_message;
      nid.uFlags:=NIF_ICON or NIF_TIP or NIF_MESSAGE;
      if not Shell_NotifyIcon(NIM_ADD,@nid) then
        begin
          showmessage('Failed!');
          Application.Terminate;
        end;
      SetWindowLong(application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
    end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    var
    nid:TNotifyIconData;
    begin
      nid.cbSize:=SIZEOF(nid);
      nid.uID:=1;
      nid.Wnd:=Handle;
      Shell_NotifyIcon(NIM_DELETE,@nid);
    end;procedure TForm1.FormPaint(Sender: TObject);
    begin
    Hide;
    end;procedure TForm1.N1232131Click(Sender: TObject);
    begin
      form2.Show;
    end;end.
      

  2.   

    http://www.tonixsoft.com/index.php?mmenu_id=3&smenu_id=0005