Program and form minimizing

I am using Delphi 3, and I have a project that has a Main form and a Sub form.  The Main form has a button, which displays (ShowModal) the second form.

What I would like is for the main form to disappear when the sub form opens. The following appears to do just that successfully...

      Form2 := TForm2.Create(Application);
      Form1.Visible := False;
      try
            Form2.ShowModal;
      finally
            Form2.Free;
      end;


The problem comes when Form2 is minimized via the title bar.  What happens is that Form2 becomes a minimized rectangular bar, and hovers over top of the Win98 taskbar rather than melding with the initial taskbar button for the application.  In other words, when Form1 appears, a taskbar button is placed on the Win98 taskbar.  When Form2 is displayed, Form1 disappears...so far, so good.  But when I minimize Form2, I know have the original taskbar button for the application, PLUS I have a minimized title bar on top of the Win98 taskbar (BAD).

How can I make the Form2 disappear, and keep the original taskbar button for the application?  Then to restore Form2, all I'd have to do is click on associated task button on the Win98 taskbar.
Monroe406Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
hi,
you need to make unit2 look like this to minimize to taskbar:

type
  TForm2 = class(TForm)
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
     procedure CreateParams(var Params : TCreateParams); override;
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses Unit1;

{$R *.DFM}

Procedure TForm2.CreateParams (Var Params : TCreateParams);
Begin
  inherited CreateParams(Params); { call the inherited first }
  with Params do exStyle := exStyle or WS_EX_APPWINDOW; { Set the extended style
  for iconising to the taskbar}
End;
 


procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
form1.visible := true;
end;

end.


Regards Barry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
intheCommented:
better example:

unit1:


unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation
 uses unit2;
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
Form2 : Tform;
begin
Form2 := TForm2.Create(Application);
Form1.Visible := False;
ShowWindow(Application.Handle, SW_HIDE);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
  GetWindowLong(Application.Handle, GWL_EXSTYLE)
    or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);
try
Form2.ShowModal;
finally
Form2.Free;
end;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
ShowWindow(Application.Handle, SW_RESTORE);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
GetWindowLong(Application.Handle, GWL_EXSTYLE)and  WS_EX_APPWINDOW);
end;

end.






unit2:


unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
     procedure CreateParams(var Params : TCreateParams); override;
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses Unit1;

{$R *.DFM}

Procedure TForm2.CreateParams (Var Params : TCreateParams);
Begin
  inherited CreateParams(Params); { call the inherited first }
  with Params do exStyle := exStyle or WS_EX_APPWINDOW; { Set the extended style
  for iconising to the taskbar}
End;
 


procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
form1.visible := true;
end;

end.
0
Monroe406Author Commented:
Works like a charm!

Much thanks.
0
intheCommented:
no probs ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.