如题

解决方案 »

  1.   

    全部如下   //当然用个Systray控件更好。功能更多。
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,shellapi;{自定义消息,当小图标捕捉到鼠标事件时Windows向回调函数发送此消息}
    const MY_MESSAGE = WM_USER + 100;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormPaint(Sender: TObject);
      private
        procedure OnIconNotify(var Message: TMessage);
                      message MY_MESSAGE;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.OnIconNotify(var Message: TMessage);
    var
     Busy: Boolean;
    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;
          {哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈}            
        Busy := false;
      end;end;procedure TForm1.FormCreate(Sender: TObject);
    var
      nid: TNotifyIconData;
    begin
      nid.cbSize := sizeof(nid); // nid变量的字节数
      nid.Wnd := Handle; // 主窗口句柄
      nid.uID :=1; // 内部标识,可设为任意数
      nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?
      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;{将程序的窗口样式设为TOOL窗口,可避免在任务条上出现}  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变量的字节数
      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
      Hide;
    end;end.
      

  2.   

    {将程序的窗口样式设为TOOL窗口,可避免在任务条上出现}
    怎么设?我怎么没找到??
      

  3.   

    SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);/此语句
      

  4.   

    用trayicon控件或者
    ***************************
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,shellapi, Menus, ImgList, XPMenu, ExtCtrls;const
      WM_BARICON=WM_USER+200;
    type
      TForm1 = class(TForm)
        XPMenu1: TXPMenu;
        ImageList1: TImageList;
        PopupMenu1: TPopupMenu;
        a1: TMenuItem;
        b1: TMenuItem;
        N1: TMenuItem;
        N2: TMenuItem;
        N3: TMenuItem;
        N4: TMenuItem;
        N5: TMenuItem;
        N6: TMenuItem;
        N7: TMenuItem;
        N8: TMenuItem;
        procedure N5Click(Sender: TObject);
        procedure a1Click(Sender: TObject);
      private
        { Private declarations }  procedure WMSysCommand(var Message: TMessage); message WM_SYSCOMMAND;
      procedure WMBarIcon(var Message:TMessage);message WM_BARICON; public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure TForm1.WMSysCommand(var Message:TMessage);
    var
      lpData:PNotifyIconData;
    begin
    if Message.WParam = SC_ICON then
      begin
      //如果用户最小化窗口则将窗口 隐藏并在任务栏上添加图标
      lpData := new(PNotifyIconDataA);
      lpData.cbSize := 88;
      //SizeOf(PNotifyIconDataA);
      lpData.Wnd := Form1.Handle;
      lpData.hIcon := Form1.Icon.Handle;
      lpData.uCallbackMessage := WM_BARICON;
      lpData.uID :=0;
      lpData.szTip := 'Samples';
      lpData.uFlags := NIF_ICON  or NIF_MESSAGE or NIF_TIP;
      Shell_NotifyIcon(NIM_ADD,lpData);
      dispose(lpData);
      Form1.Visible := False;
      end
    else
      begin
      //如果是其它的SystemCommand消息则调用系统缺省处理函数处理之。
      DefWindowProc(Form1.Handle,Message.Msg,Message.WParam,Message.LParam);
      end;
    //
    end;
    procedure Tform1.WMBarIcon(var Message:TMessage);
    var
      lpData:PNotifyIconData;
    begin
    if (Message.LParam = WM_LBUTTONDOWN) then
        begin
        //如果用户点击任务栏图标则将图标删除并回复窗口。
        lpData := new(PNotifyIconDataA);
        lpData.cbSize := 88; //SizeOf(PNotifyIconDataA);
        lpData.Wnd := Form1.Handle;
        lpData.hIcon := Form1.Icon.Handle;
        lpData.uCallbackMessage := WM_BARICON;
        lpData.uID :=0;
        lpData.szTip := 'Samples';
        lpData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
        Shell_NotifyIcon(NIM_DELETE,lpData);
        dispose(lpData);
        Form1.Visible := True;
        end
    else
    if (Message.LParam = WM_rBUTTONDOWN) then
        begin
          popupmenu1.Popup(mouse.CursorPos.X ,mouse.CursorPos.Y);
        end;end;
    procedure TForm1.N5Click(Sender: TObject);
    begin
      close;
      
    end;procedure TForm1.a1Click(Sender: TObject);
    begin
      form1.Show ;
      
    end;end.
    end.
      

  5.   

    1、比较懒的人一定劝你用控件,好像也的确有一大把一大把!但是我一个也没有用过,不过你要想用的话搜索一下,估计结果一定让你满意!2、自己做,其实实现这个效果并不难。只需要了解TrayIconData的数据结构即可。让它不显示在任务栏,就更简单了。API---------ShowWindow(form1.handle,SW_SHOWHIDE);这个问题估计CSDN上回答了n的n次方过了~!!
      

  6.   

    Undeclared identifier: 'PNotifyIconData'
      

  7.   

    ShowWindow(form1.handle,SW_hide);
    showwindow(form1.handle,sw_hide)'
    这样就可以了,一定要两个呦!!
    这个功能我已经实现了!!
      

  8.   

    如果你还没解决,我来献献丑。
    你留下EMAIL,我给你trayicon控件的源码和DEMO。