Hide the Main Form in a Delphi 2009 Application

前端 未结 2 1067
不知归路
不知归路 2020-12-09 13:04

The following code works fine in Delphi 7. However, in Delphi 2009 the form does remain hidden but the button on the taskbar is now appearing.

ShowWindow(Han         


        
相关标签:
2条回答
  • 2020-12-09 13:45

    Turns out the reason we were seeing the Application window on the taskbar was a simple setting similar to stukelly's answer but not quite.

    To get the main form to appear on the task bar and hide the application menu you apply:

    Application.MainFormOnTaskbar := True;
    Application.ShowMainForm := False;
    

    No code behind the form create or anything required.

    0 讨论(0)
  • 2020-12-09 13:59

    You need to set the ShowMainForm and MainFormOnTaskBar properties to False before the form is created.

    Open your project source and set MainFormOnTaskBar and ShowMainForm to False, before the form is created.

    Application.Initialize;
    Application.MainFormOnTaskbar := false;
    Application.ShowMainForm := false;
    Application.CreateForm(TForm1, Form1);
    

    Then on your main form add the following code to the FormActivate and FormShow events.

    procedure TForm1.FormActivate(Sender: TObject);
    begin
     // hide taskbar button
     ShowWindow(Application.Handle, SW_HIDE);
    end;
    procedure TForm1.FormShow(Sender: TObject);
    begin
     // hide taskbar button
     ShowWindow(Application.Handle, SW_HIDE);
    end;
    

    I have tested with Dephi 2007 and 2009. Additional information is available here.

    0 讨论(0)
提交回复
热议问题