如何隐藏程序,就是任务栏上没有程序,系统右下角的托盘上有显示程序图标

解决方案 »

  1.   

    你搜一下[托盘编程],很多此类信息;
    const
      WM_NID = WM_USER + 200;type
      ...
      private
        { Private declarations }
        NotifyIcon: TNotifyIconData;
        procedure IconOnClick(var Msg: TMessage); message WM_NID;
        procedure AddIcon;
        procedure DelIcon;
        procedure WMSYSCOMMAND(var Msg: TMessage); message WM_SYSCOMMAND;
        procedure OnMinimize(Sender: TObject);
    ...
    implementationprocedure TfrmIcon.FormCreate(Sender: TObject);
    begin
      Application.OnMinimize := OnMinimize;
    end;procedure TfrmIcon.AddIcon;
    begin
      with NotifyIcon do
      begin
        cbSize := SizeOf(TNotifyIconData);
        Wnd := self.Handle;
        uID := 1;
        uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
        uCallBackMessage := WM_NID;
        hIcon := Application.Icon.Handle;
        szTip := '我的托盘窗体';
      end;
      Application.Minimize;
      ShowWindow(Application.Handle, SW_HIDE);
      self.Hide;  
      Shell_NotifyIcon(NIM_ADD, @NotifyIcon);
    end;procedure TfrmIcon.DelIcon;
    begin
      ShowWindow(Application.Handle, SW_SHOW);
        Application.Restore;
      self.Show;        
      SetForegroundWindow(Self.Handle);  
      Shell_NotifyIcon(NIM_DELETE, @NotifyIcon); 
    end;procedure TfrmIcon.OnMinimize(Sender: TObject);
    begin
      AddIcon;
    end;procedure TfrmIcon.IconOnClick(var Msg: TMessage);
    var
      mp: TPoint;
    begin
      if Msg.LParam = WM_LBUTTONDBLCLK then
        DelIcon
      else if Msg.LParam = WM_RBUTTONUP then
      begin
        GetCursorPos(mp);
        pmMain.Popup(mp.X, mp.Y);
      end
      else
        Inherited;
    end;procedure TfrmIcon.WMSYSCOMMAND(var Msg: TMessage);
    begin
      if Msg.WParam = SC_MINIMIZE then
        AddIcon
      else
        Inherited;
    end;procedure TfrmIcon.pmOpenClick(Sender: TObject);
    begin
      DelIcon;
    end;procedure TfrmIcon.pmExitClick(Sender: TObject);
    begin
      Close();
    end;procedure TfrmIcon.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      Shell_NotifyIcon(NIM_DELETE, @NotifyIcon);
    end;
      

  2.   

    大哥,这里好多人都帮助了我,但是我的delphi水平实在不行啊,下面是vb中的方法,你参考吧!
    Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Const SW_HIDE = 0
     Const GW_OWNER = 4Private Sub Command1_Click()
      Dim rc As Long
      Dim OwnerhWnd As Long  Me.Visible = False '使窗体不可见
      '从任务管理器应用程序列表中隐藏
      OwnerhWnd = GetWindow(Me.hwnd, GW_OWNER)
      rc = ShowWindow(OwnerhWnd, SW_HIDE)End Sub
      

  3.   

    CSDN上有很多这样的贴子, 你搜一下看,
      

  4.   

    前面的不出现在任务栏
    可以用
    SetWindowLong(Form1.handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
    托盘编程则麻烦一些
    有相关帖子
    可以搜一下~
      

  5.   

    uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
    这里的  NIF_ICON,NIF_MESSAGE,  NIF_TIP是什么?
    我在编译的时候  报错
    Undeclared identifier:'NIM_ICON'
    Undeclared identifier:'NIM_MESSAGE'
    怎么回事啊
      

  6.   

    这是个托盘的示例,你参考一下:
     
    unit  Unit1;  
     
    interface  
     
    uses  
       Windows,  Messages,  SysUtils,  Classes,  Graphics,  Controls,  Forms,  Dialogs, Menus,shellapi;  const  
           WM_TrayMessage=WM_User+100;                 //这句是你要加的
    type  
       TForm1  =  class(TForm)  
           MainMenu1:  TMainMenu;  
           N11:  TMenuItem;  
           N21:  TMenuItem;  
           N22:  TMenuItem;  
           N23:  TMenuItem;  
           N24:  TMenuItem;  
           N31:  TMenuItem;  
           N32:  TMenuItem;  
           PopupMenu1:  TPopupMenu;  
           er1:  TMenuItem;  
           rer1:  TMenuItem;  
           rer2:  TMenuItem;  
           procedure  FormCreate(Sender:  TObject);  
           procedure  FormDestroy(Sender:  TObject);  
           procedure  N21Click(Sender:  TObject);  
           procedure  rer1Click(Sender:  TObject);  
           procedure  FormMouseMove(Sender:  TObject;  Shift:  TShiftState;  X,  
               Y:  Integer);  
       protected  
               procedure  AppMinimized(Sender:  TObject);  
               procedure  WMTrayMessage(var  msg:TMessage);message  WM_TrayMessage;  
     
       private  
           {  Private  declarations  }  
       public  
           {  Public  declarations  }  
       end;  
     
    var  
       Form1:  TForm1;  
           NID:TNotifyIconData;  
     
    implementation  
     
    {$R  *.DFM}  
     
    {  TForm1  }  
     
    procedure  TForm1.AppMinimized(Sender:  TObject);  
    begin  
     NID.cbSize:=SizeOf(TNotifyIconData);  
       NID.hIcon:=Application.Icon.Handle;  
       NID.szTip:=  '工程一  ';  
       NID.uCallbackMessage:=WM_TrayMessage;  
       NID.uFlags:=NIF_ICON  or  NIF_MESSAGE  or  NIF_TIP;           //这句是你要改的
       NID.uID:=0;  
       NID.Wnd:=Handle;  
       Shell_NotifyIcon(NIM_ADD,@NID);  
       ShowWindow(Application.Handle,SW_Hide);  
     
    end;  
     
    procedure  TForm1.WMTrayMessage(var  msg:  TMessage);  
     var  
       p:TPoint;  
    begin  
       if  msg.LParam=WM_LButtonDown  then  
           begin  
               ShowWindow(Application.Handle,SW_Show);  
               Application.Restore;  
           end  
       else  if  msg.LParam=WM_RButtonDown  then  
           begin  
               GetCursorPos(p);  
               PopupMenu1.Popup(p.x,p.y);  
           end;  
    end;  
     
     
     
    procedure  TForm1.FormCreate(Sender:  TObject);  
    //var  Owner  :  HWnd;  
    begin  
     //Owner:=GetWindow(Handle,GW_OWNER);  
     //  ShowWindow(Owner,SW_HIDE);  
     
    Application.OnMinimize:=AppMinimized;  
       AppMinimized(nil);  
     
    end;  
      

  7.   

    你提示的那两个地方,我都加了。可是还是有问题。
    还是说  
    Undeclared identifier:'NIM_ICON'
    Undeclared identifier:'NIM_MESSAGE'
    Undeclared identifier:'NIF_TIP'
    是不是调用这三个参数要加什么东西啊
      

  8.   

    我把我的源码贴出来。
    大家帮忙看看吧unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, shellapi;
      
    const WM_NID=WM_USER+1000;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    procedure WMNID(var msg:TMessage); message WM_NID; //这里message报错
    var
      Form1: TForm1;
      Extendedstyle:integer;
      NotifyIcon:TNotifyIconData;
    implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
    Extendedstyle := GetWindowLong (Application.Handle, GWL_EXstyle);
    SetWindowLong(Application.Handle, GWL_EXstyle, Extendedstyle OR WS_EX_TOOLWINDOW
    AND NOT WS_EX_APPWINDOW);    //用于隐藏任务栏上的程序      With NotifyIcon do
          begin
            cbSize:=SizeOf(TNotifyIconData);
            Wnd:=Handle;
            uID:=1;
        uFlags:=NIM_ICON or NIM_MESSAGE or NIM_TIP;  //这里的三个参数也报错,说是                                               //Undeclared identifier
            uCallBackMessage:=WM_NID;
            hIcon:=Application.Icon.Handle;
            szTip:='我是老大';
          end;
        Shell_NotifyIcon(NIM_ADD,@NotifyIcon);
    end;procedure WMNID(var msg:TMessage); message WM_NID; //这里的message也有问题
    begin
       case msg.LParam of
          WM_LBUTTONUp: Form1.Visible:=not Form1.Visible;
          WM_RBUTTONUP: ShowMessage('right');
       End;
    End;
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
      Shell_NotifyIcon(NIM_DELETE,@NotifyIcon);
    end;end.