• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

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.
0
Monroe406
Asked:
Monroe406
  • 3
1 Solution
 
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
 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now