怎样让程序运行的时:
最小话时不显示在任务栏 而只显示在系统栏,也就是象QQ那样,最小话时只显示在右下角??
然后点图标右键显示某些功能?? 谢谢有例子更好!

解决方案 »

  1.   

    //制作托盘
    unit tp;
    interface
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, jpeg, ExtCtrls,ShellApi, Menus, StdCtrls;
    const
      ICON_ID  = 1;
      My_ICONEVENT = WM_USER + 1;
    type
      TMyTest = class(TForm)
        Image1: TImage;
        pop1: TPopupMenu;
        showform: TMenuItem;
        N1: TMenuItem;
        Memo1: TMemo;
        Button1: TButton;
        Timer1: TTimer;
        procedure FormCreate(Sender: TObject);
        procedure N1Click(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        procedure showformClick(Sender: TObject);
      private
        procedure InitIcon;
        procedure UnInstallIcon;
        procedure IConOnclick(var Myss:TMessage);message My_ICONEVENT;
        procedure WMSysCommand(var Sysss: TWMSysCommand);message WM_SYSCOMMAND;
      public
      end;
    var
      MyTest: TMyTest;
    implementation
    {$R *.dfm}
    procedure TMyTest.WMSysCommand(var Sysss: TWMSysCommand); //拦截系统消息
    begin
      with Sysss do
      begin
        if (CmdType and $FFF0 = SC_MINIMIZE) or (CmdType and $FFF0 = SC_CLOSE) then
        begin
          ShowWindow(MyTest.Handle,SW_HIDE);
          Exit;
        end;
        inherited;
      end;
    end;
    procedure TMyTest.ICononclick(var Myss:TMessage);
    var p: TPoint;
    begin
      if (Myss.lParam = WM_RBUTTONDOWN) or (Myss.lParam = WM_LBUTTONDBLCLK) then
      begin
        GetCursorPos(p);
        pop1.Popup(p.x,p.y);
      end;
    end;
    procedure TMyTest.InitIcon;
    Var MyNotify:TNotifyIconData;
    begin
      MyNotify.cbSize:=Sizeof(MyNotify);
      MyNotify.Wnd:=handle;
      MyNotify.uID := ICON_ID;
      MyNotify.uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
      MyNotify.uCallbackMessage:=My_ICONEVENT;
      MyNotify.hIcon :=Image1.Picture.Icon.Handle;
      MyNotify.szTip :='MyTest';
      Shell_NotifyIcon(NIM_ADD,@MyNotify);
    end;    
    procedure TMyTest.FormCreate(Sender: TObject);
    begin
      InitIcon;
      SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
      //设置应用程序状态栏目不显示
    end;
    procedure TMyTest.N1Click(Sender: TObject);
    begin
      close;
    end;
    procedure TMyTest.UnInstallIcon; //卸载图标
    var IconData: TNotifyIconData;
    begin
      IconData.cbSize := SizeOf(IconData);
      IconData.Wnd := Handle;
      IconData.uID := ICON_ID;
      Shell_NotifyIcon(NIM_DELETE,@IconData);
    end;
    procedure TMyTest.FormDestroy(Sender: TObject);
    begin
      UnInstallIcon;
    end;
    procedure TMyTest.Timer1Timer(Sender: TObject);
    begin
      Timer1.Enabled:=False;
      ShowWindow(MyTest.Handle,SW_HIDE);
    end;
    procedure TMyTest.showformClick(Sender: TObject);
    begin
      ShowWindow(MyTest.Handle,SW_SHOWNORMAL);
      SetForegroundWindow(application.handle);//激活应用程序为前台,此处可以省掉
    end;
    end.
    使应用程序在状态拦上不显示,只显示主窗体.
    postmessage(application.handle,GWL_EXSTYLE,WA_EX_TOOLWINDOW)

    SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);