Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.131 Beiträge
 
Delphi 12 Athens
 
#5

AW: Application.MainFormOnTaskbar wird ignoriert (10.4)

  Alt 9. Aug 2020, 21:03
Delphi-Quellcode:
Application.Initialize;
Application.MainFormOnTaskbar := False;
Application.CreateForm(TForm1, Form1);
Application.Run;
Wie gesagt, alleine das funktioniert schon garnicht.


Wenn man nur den ExStyle und Visible ändert, sollte es keine Probleme geben, aber im SetMainFormOnTaskbar wird auch ein Recreate der HWND der MainForm angestoßen.
Totaler Schwachsinn (kein Wunder, wenn es da Probleme geben kann), außerdem wird im TApplication.CreateForm nochmals dran rumgepfuscht.

Drum sieht es aktuell so aus,
aber so lange ich nicht rausbekomm, wie man eine unsichtbare Form/HWND dazu bringt dennoch ihren TaskButton darzustellen, hab ich ein kleines Problemchen.
Delphi-Quellcode:
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.
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu ( 9. Aug 2020 um 22:10 Uhr)
  Mit Zitat antworten Zitat