showwindow(application.handle, sw_hide, 0,0)

解决方案 »

  1.   

    program DeskPop;uses
        Windows, Messages, ShellAPI, sysutils;{$R *.RES}
    //{$R ICONS.RES}const AppName = 'DeskTop Hide';var x: integer;
        tid: TNotifyIconData;
        WndClass: array[0..50] of char;procedure Panic (szMessage: PChar);
    begin
      if szMessage<>nil then MessageBox(0, szMessage, AppName, mb_ok);
      Halt(0);
    end;procedure HandleCommand(Wnd: hWnd; Cmd: Word);
    begin
      case Cmd of
        Ord('A'): MessageBox(0, 'Freeware [email protected] 1997', AppName, mb_ok);
        Ord('E'): PostMessage(Wnd, WM_Close, 0, 0);
      end;
    end;function DummyWindowProc(Wnd: hWnd; Msg, wParam: Word; lParam: LongInt): LongInt; stdcall;
    var TrayHandle: THandle;
        dc: hDC;
        pm: HMenu;
        pt: TPoint;
    begin
      DummyWindowProc := 0;
      StrPCopy(@WndClass[0], 'Progman');
      TrayHandle := FindWindow(@WndClass[0], nil);
      case Msg of
        WM_Create: begin//Program initialisation - just set up a tray icon
                     tid.cbSize           := sizeof(tid);
                     tid.Wnd              := Wnd;
                     tid.uID              := 1;
                     tid.uFlags           := nif_Message or nif_Icon or nif_Tip;
                     tid.uCallBackMessage := WM_User;
                     tid.hIcon            := LoadIcon(hInstance, 'MAINICON');
                     lstrcpy(tid.szTip,'Desktop is on');
                     Shell_NotifyIcon(nim_Add, @tid);
                   end;
        WM_Destroy: begin
                      Shell_NotifyIcon(nim_Delete, @tid);
                      PostQuitMessage(0);
                      ShowWindow(TrayHandle, SW_RESTORE);
                    end;
        WM_Command: begin// Command notification
                      HandleCommand(Wnd, LoWord(wParam));
                      Exit;
                    end;
        WM_User: // Had a tray notification - see what to do
                    if(lParam = WM_LButtonDown) then
                    begin
                      if x = 0 then
                      begin
                        ShowWindow(TrayHandle, SW_HIDE);
                        tid.hIcon := LoadIcon(hInstance, 'offICON');
                        lstrcpy(tid.szTip,'Desktop is off');
                        Shell_NotifyIcon(NIM_MODIFY, @tid);
                        x:=1
                      end else
                      begin
                        ShowWindow(TrayHandle, SW_RESTORE);
                        tid.hIcon := LoadIcon(hInstance, 'ONICON');
                        lstrcpy(tid.szTip,'Desktop is on');
                        Shell_NotifyIcon(NIM_MODIFY, @tid);
                        x:= 0;
                      end;
                    end else if (lParam = WM_RButtonDown) then
                    begin
                      GetCursorPos(pt);
                      pm := CreatePopupMenu;
                      AppendMenu(pm, 0, Ord('A'), 'About DeskTop Hide...');
                      AppendMenu(pm, mf_Separator, 0, Nil);
                      AppendMenu(pm, 0, Ord('E'), 'Exit DeskTop Hide');
                      SetForegroundWindow(Wnd);
                      dc := GetDC(0);
                      if TrackPopupMenu(pm, tpm_BottomAlign or tpm_RightAlign, pt.x,GetDeviceCaps(dc,HORZRES){pt.y}, 0, Wnd, Nil)
                      then SetForegroundWindow(Wnd);
                      DestroyMenu(pm);
                    end;
      end;
      DummyWindowProc := DefWindowProc(Wnd, Msg, wParam, lParam);
    end;procedure WinMain;
    var Wnd: hWnd;
        Msg: TMsg;
        WndClass: TWndClass;
    begin
      { Previous instance running ?  If so, exit }
      if FindWindow(AppName, nil) <> 0 then Panic(AppName + ' is already running.');  { Register the window class }
      FillChar(WndClass, sizeof(WndClass), 0);
      WndClass.lpfnWndProc := @DummyWindowProc;
      WndClass.hInstance := hInstance;
      WndClass.lpszClassName := AppName;
      RegisterClass(WndClass);  { Now create the dummy window }
      Wnd := CreateWindow(AppName, AppName, ws_OverlappedWindow,
                          cw_UseDefault, cw_UseDefault, cw_UseDefault, cw_UseDefault,
                          0, 0, hInstance, Nil);
      x:= 0;
      if Wnd <> 0 then
      begin
        ShowWindow(Wnd, sw_Hide);
        while GetMessage(Msg, 0, 0, 0) do
        begin
          TranslateMessage(Msg);
          DispatchMessage(Msg);
        end;
      end;
    end;begin
      WinMain;
    end.
    
      

  2.   

    :(
     quark(夸克) ,不懂也。
    我不是要编写最小的应用程序啊,我是说新建工程时,Delhpi自动提供的那个窗体,我没办法让它不出现在任务栏上。你能帮帮我吗?
      

  3.   

    用托盘吧,给你一个组件。
    见下代码:
    unit TrayIcon;interfaceUses Windows ,SysUtils ,Messages ,ShellAPI ,Classes,Graphics ,Forms ,Menus ,
          StdCtrls ,ExtCtrls ;
    Type
         ENotifyIconError = class(Exception);
         TTrayNotifyIcon = class (TComponent )
         private
               FDefaultIcon : THandle ;
               FIcon : TIcon ;
               FHideTask : Boolean ;
               FHint : String ;
               FIconVisible : Boolean ;
               FPopupMenu : TPopupMenu ;
               FOnClick : TNotifyEvent ;
               FOnDblClick : TNotifyEvent ;
               FNoShowClick : Boolean ;
               FTimer : TTimer ;
               Tnd : TNotifyIconData ;
               Procedure SetIcon ( Value : TIcon );
               procedure SetHideTask(Value : Boolean );
               procedure setHint(Value : String );
               Procedure SetIconVisible(Value : Boolean );
               procedure setpopupMenu(value : TpopupMenu);
               Procedure SendTrayMessage(Msg : DWORD ;Flags : UINT);
               Function  ActiveIconHandle : Thandle ;
               Procedure OnButtonTimer(Sender : TObject );
         Protected
               procedure Loaded ;override ;
               Procedure LoadDefaultIcon;Virtual ;
               procedure Notification(AComponent :TComponent ;Operation :TOperation);override ;
         public
               constructor Create(AOwner :TComponent );override ;
               destructor  Destroy ;override ;
         published
               property Icon : TIcon read FIcon write SetIcon ;
               property HideTask: boolean read FhideTask write SetHideTask default false ;
               property Hint: string read Fhint write setHint ;
               property IconVisible : Boolean read FIconVisible write setIconVisible default false ;
               property Popupmenu :TPopupmenu Read FPopupmenu write setPopupmenu;
               property Onclick : TNotifyEvent read FOnclick write FOnclick;
               property OnDBlclick : TNotifyEvent read FOndblclick write FOndblclick;
         end;procedure Register;
    implementation
        Type
         TIconManager = class
         Private
               FHWindow : HWnd ;
               Procedure TrayWndProc (Var Message :Tmessage);
         public
               constructor Create ;
               destructor Destroy ;override ;
               property    HWindow : HWnd Read FHWindow write FHWindow ;
         end;     var
             IconMgr : TIconManager ;
             DDGM_TRAYICON : Integer ;
    constructor TIconManager.Create ;
    begin
       FHWindow := ALLocateHWnd(TrayWndProc );
    end ;destructor TIconManager.Destroy ;
    begin
       if FHWindow <>0 then DeallocateHWnd(FHWindow);
       Inherited destroy ;
    end ;
    procedure TIconManager.TrayWndProc(var message : Tmessage);
    var
     pt: Tpoint ;
     TheIcon : TTrayNotifyIcon ;
    begin
       with message do
       begin
            if (Msg = DDGM_TRAYICON) then
            begin
              TheIcon := TTRayNotifyIcon (WParam);
              case lParam of
                   WM_LBUTTONDOWN:TheIcon.FTimer.Enabled := true ;
                   WM_LBUTTONDBLCLK :
                   begin
                      theIcon.FNoShowClick := true ;
                      if Assigned(TheIcon.FOnDblClick) then TheIcon.FOnDblClick (self);
                   end;
                   WM_RBUTTONDOWN :
                   begin
                       if Assigned(theiCON.FPopupMenu) THEN
                       begin
                          SetForeGroundWindow(IconMgr.hwindow);
                          GetCursorpos(pt);
                          TheIcon.FPopupMenu.Popup (pt.x,pt.y);
                          postMessage(IconMgr.Hwindow ,WM_USER,0,0);
                       end;
                   end;
            end ;
          end else
           REsult := DefWindowProc(FHWindow,Msg,Wparam,lparam);   end ;
    end ;
    {TTrayNotifyIcon}
    Constructor TTRayNotifyIcon.Create (Aowner : TComponent);
    begin
       Inherited Create(AOwner);
       FIcon := TIcon.Create ;
       Ftimer := ttimer.Create (self );
       with Ftimer do
       begin
          Enabled := true ;
          Interval := GetDoubleClickTime ;
          Ontimer := OnButtonTimer ;
       end ;
       {keep Default window Icon Handy..}
       LoadDefaulticon ;
    end;
    Destructor TTrayNotifyIcon.Destroy ;
    begin
       if FIconVisible then SetIconVisible(false );
       fIcon.Free ;
       Inherited Destroy ;
    end ;
    function TTrayNotifyIcon.ActiveIconHandle : Thandle ;
    begin
      if ( Ficon.Handle <>0) then
         Result :=FIcon.Handle
       else
        Result := FDefaultIcon ;
    end ;
    Procedure TTrayNotifyIcon.LoadDefaultIcon ;
    begin
      FDefaultIcon := loadIcon(0,IDI_WINLOGO);
    end;
    procedure TTrayNotifyIcon.Loaded ;
    begin
       Inherited Loaded ;
       if Ficonvisible then
           sendTRaymessage(NIM_ADD,NIF_MESSAge OR NIF_Icon or NIF_TIP);
    end ;
    procedure TTrayNotifyIcon.Notification (AComponent :TComponent ;Operation :TOperation);
    begin
        Inherited  Notification(AComponent,Operation );
        if (operation = OPRemove ) and (AComponent = PopupMenu ) then
         popupmenu := nil ;
    end ;
    procedure TTrayNotifyIcon.OnButtonTimer (sender : TObject );
    begin
         fTimer.Enabled := false ;
         if (not FNoshowclick) AND assigned(FOnclick) then
            Fonclick (self);
         Fnoshowclick := false ;
    end ;
    procedure TTrayNotifyIcon.SendTrayMessage(Msg : DWORD ;Flags : UINT);
    begin
       with Tnd do
       begin
           cbsize :=sizeof (tnd);
           StrPlcopy(szTip,pchar(Fhint),sizeof (sztip));
           UFlags := flags ;
           uID := UINT(self );
           Wnd:=Iconmgr.HWindow ;
           Ucallbackmessage:=DDGM_TRAYICON ;
           HICON := activeIconHandle ;
       end ;
       shell_Notifyicon(Msg,@Tnd);
    end ;
    procedure TTrayNotifyIcon.SetHideTask(Value : Boolean );
    const showarray : array[boolean] of integer =(sw_showNormal,sw_hide);
    begin
       if fhidetask <> value then
        begin
            fhidetask := value ;
            if not(csdesigning in componentstate) then
                showwindow(Application.handle,showArray[FHideTask]);
        end ;end ;
    procedure TTrayNotifyIcon.setHint(Value : String );
    begin
      if Fhint <>Value then
        begin
          Fhint := Value ;
          if FIconvisible then
             sendTrayMessage(NIM_MODIFY,NIF_TIP);
        end ;
    end ;
    procedure TTrayNotifyIcon.SetIcon(Value :  TIcon );
    begin
      ficon.Assign (Value);
      if FIconvisible then sendTrayMessage(NIM_MODIFY,NIF_ICON);
    end ;
    procedure TTrayNotifyIcon.setpopupMenu(value : TpopupMenu);begin
       FPOPupmenu :=Value ;
       if Value <> nil then Value.FreeNotification (self );
    end ;
    procedure  TTrayNotifyIcon.SetIconVisible(Value : Boolean );
    const
       MsgArray : Array [boolean] of DWORD = ( NIM_DELETE,NIM_ADD);
    begin
       if ficonvisible<>Value then
        begin
          ficonvisible :=Value ;
          sendtraymessage(msgarray[Value],NIF_MESSAGE or NIF_ICON or NIF_TIP);
        end ;end ;
    procedure Register;
    begin
      RegisterComponents('KNTEMP', [TTrayNotifyIcon]);
    end;
    const TrayMsgStr ='DDG.TrayNotifyIconMsg';initialization
        DDGM_TRAYICON := RegisterWindowMessage(TrayMsgStr);
        IconMgr := TiconManager.Create ;
    finalization
        Iconmgr.Free ;
    end.
      

  4.   

    SetWindowLong  (Application.Handle  ,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
      

  5.   

    用顶楼的方法就可以啊,放在Form的OnCreate事件里.或者ONSHOW事件
      

  6.   


      SetWindowLong    (Application.Handle    ,GWL_EXSTYLE,WS_EX_TOOLWINDOW); 
    我试了不行啊,milpas(我带着我的影子去流浪)你试这个可以吗?诶,我再回去看看好了。
      

  7.   

    procedure TForm_Main.FormCreate(Sender: TObject);
    begin
      SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW); 
    end;