我是德尔福学习者。我希望从任务栏和Alt + Tab隐藏我的Delphi应用程序。所以我定义了以下代码:
unit KoushikHalder01;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
TMainForm = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
procedure TMainForm.FormActivate(Sender: TObject);
begin
ShowWindow(Application.Handle, SW_HIDE);
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
ShowWindow(Application.Handle, SW_HIDE);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
ShowWindow(Application.Handle, SW_SHOW);
end;
procedure TMainForm.FormShow(Sender: TObject);
begin
ShowWindow(Application.Handle, SW_HIDE);
end;
end.
和
program KoushikHalder;
uses
Vcl.Forms,
KoushikHalder01 in 'KoushikHalder01.pas' {MainForm};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := false;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.
它仅适用于第一次。但是有一些问题如下:
答案 0 :(得分:1)
这将隐藏在任务栏中:
procedure TForm1.FormActivate(Sender: TObject);
begin
SetWindowLong(Handle, GWL_EXSTYLE,
GetWindowLong(Handle, GWL_EXSTYLE) or
WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);
ShowWindow(Application.Handle, SW_HIDE);
end;
在FormActivate事件中使用该代码......