2013-02-11 179 views
13

我想從Windows 7任務欄隱藏應用程序。如何在Windows 7中隱藏任務欄中的應用程序?

我想在屏幕邊緣做一些東西,當用戶點擊它時會做某些事情,但我不希望它顯示在任務欄中,因爲它是我想要的東西留在後臺。

我想在下面的帖子中的說明,但它並沒有在我的應用程序中工作:

How to hide a taskbar entry but keep the window form

然後我試圖在一個新的空VCL窗體應用程序,它仍然沒有工作。我尋找其他的解決方案,但他們都像在鏈接文章中一樣做。

有什麼改變,這使得在Windows 7中不可能?還是有什麼你可以想到的,這可以防止它的工作?

+0

什麼是你Application.MainFormOnTaskBar屬性的值? – jachguate 2013-02-11 16:56:31

+2

僅供參考殼牌的AppBar API是爲此設計的http://msdn.microsoft.com/en-gb/library/windows/desktop/cc144177(v=vs.85).aspx/ http://stackoverflow.com/questions/75785/How-do-you-do-appbar-docking-to-screen-edge-like-winamp-in-wpf – 2013-02-11 18:48:33

+0

Application.MainFormOnTaskBar默認爲true。當我將它設置爲false時,我在任務欄中獲得2個條目。一個用於exe本身,另一個用於主窗口。 – Marks 2013-02-12 08:18:47

回答

6

嘗試使用this article描述一個取巧的辦法:

設置MainFormOnTaskBar爲False在你的項目文件。然後嘗試從主窗體的OnShowOnActivate事件處理程序中隱藏應用程序窗口。因此,您的項目可能看起來像如下:

Project1.dpr:

program Project1; 

uses 
    Forms, 
    Unit1 in 'Unit1.pas' {Form1}; 

{$R *.res} 

begin 
    Application.Initialize; 
    Application.MainFormOnTaskbar := False; 
    Application.CreateForm(TForm1, Form1); 
    Application.Run; 
end. 

Unit1.pas:

unit Unit1; 

interface 

uses 
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
    Dialogs; 

type 
    TForm1 = class(TForm) 
    procedure FormShow(Sender: TObject); 
    procedure FormActivate(Sender: TObject); 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    end; 

var 
    Form1: TForm1; 

implementation 

{$R *.dfm} 

procedure TForm1.FormShow(Sender: TObject); 
begin 
    ShowWindow(Application.Handle, SW_HIDE); 
end; 

procedure TForm1.FormActivate(Sender: TObject); 
begin 
    ShowWindow(Application.Handle, SW_HIDE); 
end; 

end. 
9

您可以覆蓋主窗體的CreateParam到刪除強制任務欄按鈕(WS_EX_APPWINDOW)和通過應用程序窗口另外使擁有。這是做殼的要求放置窗口的任務欄按鈕。從「Managing Taskbar Buttons」:

[..]爲了確保窗口按鈕被放置在任務欄上,創建具有WS_EX_APPWINDOW擴展樣式的無主 窗口。 [..]

樣品:

type 
    TForm1 = class(TForm) 
    protected 
    procedure CreateParams(var Params: TCreateParams); override; 
    end; 

procedure TForm1.CreateParams(var Params: TCreateParams); 
begin 
    inherited; 
    Params.ExStyle := Params.ExStyle and not WS_EX_APPWINDOW; 
    Params.WndParent := Application.Handle; 
end; 

不要更改其默認爲「真」的「應用程序」 MainFormOnTaskbar屬性的狀態,如果你使用這種方法。

您也可以刪除第二行(..WndParent:= ..),而不是在對象檢查器中將PopupMode的表格設置爲pmExplicit,以達到同樣的效果。


順便說一句,這裏是從同一主題的文檔報價爲解決TLama posted

爲了防止窗口和按鈕被放置在任務欄上,[...] 作爲替代,您可以創建一個隱藏窗口,並將此隱藏窗口作爲您可見窗口的所有者。

當您將MainFormOnTaskbar設置爲false時,VCL設計將主窗體歸於應用程序窗口。如果您隱藏了應用程序窗口,則需求已滿足。

-1

您的應用程序主窗體通常在dpr中創建,因此打開dpr並查找創建主窗體的行。

// add this line first 
// blank app title will prevent app from showing in the applications list in task manager 
Application.Title := ''; 

// this line is already in the dpr and creates the main form, the class will differ 
Application.CreateForm(TMainForm, Result); 

// make the main form invisible to windows taskbar/task switcher 
i := GetWindowLong(Application.Handle, GWL_EXSTYLE); 
SetWindowLong(Application.Handle, GWL_EXSTYLE, i OR WS_EX_TOOLWINDOW AND NOT WS_EX_APPWINDOW); 

我知道這適用於XP和7.我猜這也適用於8。這增加了工具窗口標誌,並刪除APPWINDOW標誌,所以我想,如果你不感興趣的工具窗口標誌,你可以離開了以下部分

i OR WS_EX_TOOLWINDOW 
+0

它不工作! – Ampere 2016-05-11 07:08:24

相關問題