我想实现程序最小化后不显示在下面的状态栏,而是作为一个图标显示在右下角。各位大虾帮我解答一下,多谢拉。

解决方案 »

  1.   

    uses
      ...,ShellAPI.const WM_NOTIFYICON=WM_USER+1;implementation
    type
     TMainForm = class(TForm)
     ......
     private
       IconData:TNotifyIconData;   procedure AddIcon;
       procedure RemoveIcon;
       procedure windowhide;
       procedure windowshow;
       procedure OnNotifyicon(var Message:Tmessage);Message WM_NOTIFYICON;procedure TMainForm.OnNotifyicon(var Message: Tmessage);
    var
     mypoint:Tpoint;
    begin
    if Message.LParam = WM_RBUTTONDOWN then
       begin
         GetCursorPos(mypoint);
         setforegroundwindow(application.Handle);
         application.ProcessMessages;
         PopupMenuTry.popup(mypoint.x,mypoint.y);
       end
       else if Message.LParam = WM_LBUTTONDBLCLK THEN
       Begin
           WindowShow;
       end;end;
    procedure TMainForm.windowshow;
    begin
     self.Show;
     self.WindowState:=wsNormal;
     Application.ShowHint := True;
     self.RemoveIcon;
    end;procedure TMainForm.windowhide;
    begin self.WindowState:=wsMinimized;
     self.Hide;
     Application.HideHint;
     self.addicon;
    end;
    procedure TMainForm.RemoveIcon;
    begin
     shell_notifyicon(NIM_DELETE,@ICONDATA);
    end;
    procedure TMainForm.AddIcon;
    begin
     IconData.cbSize:=sizeof(IconData);
     IconData.Wnd:=handle;
     IconData.uID:=1000;
     IconData.uFlags:=NIF_MESSAGE+NIF_ICON+NIF_TIP;
     IconData.uCallbackMessage:=WM_USER+1;
     IconData.hIcon:=application.icon.Handle;
     IconData.szTip:='Happy';
     Shell_NotifyIcon(NIM_ADD,@IconData);
    end;
      

  2.   

    给你一个例子
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls, Grids,DateUtils, ExtCtrls, Buttons,IniFiles,
      Menus, DB, DBTables,shellapi, ADODB, DBGrids;
    const MY_MESSAGE = WM_USER + 100;
    type
      TForm1 = class(TForm)
        Timer1: TTimer;
        ADOConnection1: TADOConnection;
        ADOQuery1: TADOQuery;
        Panel1: TPanel;
        Panel2: TPanel;
        DataSource1: TDataSource;
        DBGrid1: TDBGrid;
        Button1: TButton;
        Timer2: TTimer;
        ADOQuery2: TADOQuery;
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormPaint(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        procedure FormShow(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure Timer2Timer(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure OnIconNotify(var Message: TMessage);message MY_MESSAGE;
      end;
    const
      screenwidth:longint=1024;
      screenheight:longint=768;
    var
      Form1: TForm1;implementationuses Unit2, Unit3;{$R *.dfm}{ TForm1 }
    //点击右下角图标,退出程序
    procedure TForm1.OnIconNotify(var Message: TMessage);
    var
      busy:boolean;
    begin
      busy:=false;
      if not Busy then
        begin
          Busy:=true;
          if Message.LParam=WM_LBUTTONDBLCLK then//判断是否时左键双击
            begin
            if Application.MessageBox('你确定要退出该程序吗?','退出',MB_YESNO)=IDYES then
              Close
            else
              form1.WindowState:=wsNormal;
            end;
          Busy := false;
        end;
    end;
    //退出程序时,释放小图标
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    var
      nid:TNotifyIconData;
    begin
      nid.cbSize := sizeof(nid); // nid变量的字节数
      nid.cbSize := sizeof(nid); // nid变量的字节数
      nid.uID:=1; //内部标识,与加入小图标时的数一致
      nid.Wnd := Handle; //主窗口句柄
      Shell_NotifyIcon(NIM_DELETE,@nid); //去掉小图标
      Shell_NotifyIcon(NIM_DELETE,@nid); //去掉小图标
    end;
    //程序运行时隐藏窗体
    procedure TForm1.FormPaint(Sender: TObject);
    begin
      form1.Hide;
    end;//创建小图标
    procedure TForm1.FormCreate(Sender: TObject);
    var
      scaled:boolean;
      oldformwidth:integer;
      nid:TNotifyIconData;
      newhintfont:tfont;
    begin
      Scaled:=TRUE;
      if(Screen.width <> ScreenWidth)then
        begin
          OldFormWidth:=Width;
          Height:=longint(Height)*longint(Screen.Height)DIV ScreenHeight;
          Width:=longint(Width)*longint(Screen.Width)DIV ScreenWidth;
          ScaleBy(Screen.Width,ScreenWidth);
          Font.Size:=(Width DIV OldFormWidth)*Font.Size;
        end;
      nid.cbSize:=sizeof(nid); // nid变量的字节数
      nid.Wnd:=Handle; // 主窗口句柄
      nid.uID:=1; // 内部标识,可设为任意数
      nid.hIcon:=Application.Icon.Handle; // 要加入的图标句柄,可任意指?
      nid.hIcon:=Application.Icon.Handle; // 要加入的图标句柄,可任意指?
      nid.szTip:='表格管理过程控制信息监控'; // 提示字符串
      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;
      {将程序的窗口样式设为TOOL窗口,可避免在任务条上出现}
      SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
      application.HintColor:=clred;
      application.HintHidePause:=5000;
      application.HintPause:=0;
      application.HintShortPause:=100;
      newhintfont:=tfont.Create;
      newhintfont.Name:='楷体-GB2312';
      newhintfont.Color:=clwhite;
      newhintfont.Size:=10;
      form1.Timer1.Enabled:=false;
      form1.Timer2.Enabled:=false;
    end;end.
      

  3.   

    要不想写代码可以下载一个trayicon控件:)
      

  4.   

    rxlib中有一个控件,带源程序