藏/显示Windows任务栏
前面介绍了Windows API函数F i n d Wi n d o w的用法。下面还将通过函数F i n d Wi n d o w实现隐
藏和显示Wi n d o w s任务栏。
例程S16_26 该例程(运行结果界面如图1 6 - 4 4所示)对隐藏和显示Wi n d o w s任务栏进行了
说明。
参照图1 6 - 4 4定制窗体,添加按钮的O n C l i c k事件的处理过程如下:
procedure TForm1.Button1Click(Sender: TO b j e c t ) ;
v a r
WndHandle : THandle;
b e g i n
// 获取任务栏的窗口句柄
WndHandle := FindWi n d o w ( ' S h e l l _ TrayWnd', nil);
S h o w Window(WndHandle, SW_SHOW); // 显示任务栏
e n d ;
procedure TForm1.Button2Click(Sender: TO b j e c t ) ;
v a r
wndHandle : THandle;
b e g i n
WndHandle := FindWi n d o w ( ' S h e l l _ TrayWnd', nil);
S h o w Window(WndHandle, SW_HIDE); // 隐藏任务栏
e n d ;

解决方案 »

  1.   

    2。应用程序不出现在Windows的任务栏上
    如果希望应用程序,例如用于监控的程序,在运行后不在任务栏上出现,这时可以使用
    Windows API函数S e t Wi n d o w L o n g来实现。
    在上面的例程S 1 6 _ 2 6的基础上,添加窗体的O n C r e a t e事件的处理过程如下:
    procedure TForm1.FormCreate(Sender: TO b j e c t ) ;
    b e g i n
    // 使应用程序不出现在Wi n d o w s的任务栏上
    S e t Wi n d o w L o n g ( A p p l i c a t i o n . H a n d l e , G W L _ E X S T Y L E , W S _ E X _ TO O LW I N D O W ) ;
    e n d ;
    下载
    图16-44 例程S16_26运行结果界面
      

  2.   

    完整代码
    unit fshbx;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, shellapi,
      Menus, ExtCtrls;const WM_NOTIFYICON = WM_USER + 1;
    type
      Tserverfrom = class(TForm)
        PopupMenu1: TPopupMenu;
        about1: TMenuItem;
        exit1: TMenuItem;
        Timer1: TTimer;
        procedure exit1Click(Sender: TObject);
        procedure about1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure Timer1Timer(Sender: TObject);
      private
        check: string;
        Notifydata: Tnotifyicondata;
        procedure addicon;
        procedure removeicon;
        { Private declarations }
      protected
        procedure onnotifyicon(var message: TMessage); message WM_NOTIFYICON;
      public
        { Public declarations }
      end;
    var
      serverfrom: Tserverfrom;implementation{$R *.DFM}procedure Tserverfrom.addicon;
    begin
      notifydata.cbSize := sizeof(notifydata);
      with notifydata do
      begin
        wnd := handle;
        uid := 1;
        uflags := NIF_TIP or NIF_ICON or NIF_MESSAGE;
        hicon := application.Icon.Handle;
        sztip := '应用服务器';
        ucallbackmessage := WM_NOTIFYICON;
      end;
      shell_notifyicon(NIM_ADD, @notifydata);
    end;procedure Tserverfrom.removeicon;
    begin
      notifydata.uID := 1;
      shell_notifyicon(NIM_DELETE, @notifydata);
    end;procedure Tserverfrom.onnotifyicon(var message: Tmessage);
    var
      mousepos: Tpoint;
    begin
      if message.lparam = WM_LBUTTONDBLCLK then
        showmessage('不要乱动!');
      if message.lparam = WM_LBUTTONDBLCLK then
        showmessage('左键双击');
      if (message.lparam = WM_RBUTTONDBLCLK) then
      begin
        getcursorpos(mousepos);
        setforegroundwindow(application.handle);
        application.ProcessMessages;
        popupmenu1.Popup(mousepos.x, mousepos.y);
      end;
    end;procedure Tserverfrom.exit1Click(Sender: TObject);
    begin
      removeicon;
      close;
    end;procedure Tserverfrom.about1Click(Sender: TObject);
    begin
      showmessage('应用服务器');
    end;procedure Tserverfrom.FormCreate(Sender: TObject);
    begin
      addicon;
      showwindow(application.handle, SW_HIDE);
      Application.ShowMainForm := False;
      check :='-255';
    end;procedure Tserverfrom.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      removeicon;
    end;procedure Tserverfrom.Timer1Timer(Sender: TObject);
    begin
      removeicon;
      if check = '-255' then
      begin
        Application.Icon.LoadFromFile('D:\delphivcl\ico\ico\Funny\grrr!.ico');
        check :='0';
      end
      else
      begin
        Application.Icon.LoadFromFile('D:\delphivcl\ico\ico\Funny\mr remote.ico');
        check :='-255';
      end;
      addicon;
    end;end.
      

  3.   

    我知是以下函数,但没具体例子
    WINSHELLAPI BOOL WINAPI Shell_NotifyIcon(    DWORD dwMessage, // message identifier
        PNOTIFYICONDATA pnid // pointer to structure
       );
      

  4.   

    我知是以下函数,但没具体例子
    WINSHELLAPI BOOL WINAPI Shell_NotifyIcon(    DWORD dwMessage, // message identifier
        PNOTIFYICONDATA pnid // pointer to structure
       );
      

  5.   

    IconData: TNOTIFYICONDATA;  //定义图标变量//==================================================================
    // 名称:FillDataStructure
    // 说明:填写IconData的值以便显示不同的位图
    // 返回:无
    // 编程:,2001-05-18         //程序的托盘定义
    //==================================================================
    procedure TfrmSEND.FillDataStructure;
    begin
       with IconData do begin
          cbSize := sizeof(TNOTIFYICONDATA);
          wnd :=Self.Handle ;
          uID := 0; // is not passed in with message so make it 0
          uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
          hIcon := Self.Icon.Handle;
          StrPCopy(szTip,'NET SEND短信发送程序');//托盘图标标题
          uCallbackMessage := WM_TOOLTRAYICON;
       end;
    end;
    Shell_NotifyIcon(NIM_DELETE,@IconData);//删除托盘图标Shell_NotifyIcon(NIM_Add,@IconData);   //添加托盘图标
      

  6.   

    IconData: TNOTIFYICONDATA;  //定义图标变量//==================================================================
    // 名称:FillDataStructure
    // 说明:填写IconData的值以便显示不同的位图
    // 返回:无
    // 编程:,2001-05-18         //程序的托盘定义
    //==================================================================
    procedure TfrmSEND.FillDataStructure;
    begin
       with IconData do begin
          cbSize := sizeof(TNOTIFYICONDATA);
          wnd :=Self.Handle ;
          uID := 0; // is not passed in with message so make it 0
          uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
          hIcon := Self.Icon.Handle;
          StrPCopy(szTip,'NET SEND短信发送程序');//托盘图标标题
          uCallbackMessage := WM_TOOLTRAYICON;
       end;
    end;
    Shell_NotifyIcon(NIM_DELETE,@IconData);//删除托盘图标Shell_NotifyIcon(NIM_Add,@IconData);   //添加托盘图标
      

  7.   

    : luoweicaisd(笑三少) 
    你写的很正确
    能否问你最后个问题
    最小化时隐藏任务栏