program Project2;
uses
Winapi.Windows,
Vcl.Forms,
Unit1
in '
Unit1.pas'
{Form1};
{$R *.res}
type
THiddenHelper =
class
class procedure ActiveFormChange(Sender: TObject);
end;
class procedure THiddenHelper.ActiveFormChange(Sender: TObject);
var
B: Boolean;
begin
B := True;
if (Application.MainFormHandle <> 0)
and IsWindowVisible(Application.MainFormHandle)
and (GetWindowLong(Application.MainFormHandle, GWL_EXSTYLE)
and WS_EX_APPWINDOW <> 0)
then
B := False;
if not B
and Assigned(Screen.ActiveCustomForm)
and Screen.ActiveCustomForm.HandleAllocated
and IsWindowVisible(Screen.ActiveCustomForm.Handle)
and (GetWindowLong(Screen.ActiveCustomForm.Handle, GWL_EXSTYLE)
and WS_EX_APPWINDOW <> 0)
then
B := False;
for var i := Screen.CustomFormCount - 1
downto 0
do
if not B
and Screen.CustomForms[i].HandleAllocated
and IsWindowVisible(Screen.CustomForms[i].Handle)
and (GetWindowLong(Screen.CustomForms[i].Handle, GWL_EXSTYLE)
and WS_EX_APPWINDOW <> 0)
then
B := False;
//Application.MainFormOnTaskBar := B; // False entfernt WS_EX_TOOLWINDOW von der MainForm, was nicht erwünscht ist
if (GetWindowLong(Application.Handle, GWL_EXSTYLE)
and WS_EX_TOOLWINDOW <> 0) <> B
then begin
SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE)
or WS_EX_TOOLWINDOW);
ShowWindow(Application.Handle, SW_SHOWMINNOACTIVE);
end else begin
SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE)
and not WS_EX_TOOLWINDOW);
ShowWindow(Application.Handle, SW_HIDE);
end;
end;
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Screen.OnActiveFormChange := THiddenHelper.ActiveFormChange;
SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE)
or WS_EX_TOOLWINDOW);
ShowWindow(Application.Handle, SW_SHOWMINNOACTIVE);
//Application.ProcessMessages;
Application.CreateForm(TForm1, Form1);
THiddenHelper.ActiveFormChange(
nil);
//Application.MainFormOnTaskbar := True;
Application.Run;
end.