Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Minimizing a form



Permlink Replies: 9 - Last Post: Sep 14, 2017 3:12 PM Last Post By: Remy Lebeau (Te...
Lars Groennegaard

Posts: 82
Registered: 5/12/01
Minimizing a form
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 30, 2016 5:52 AM
Hi All,
I have an application where a button on a main form opens another form.
When the user chooses to minimize that form (pressing "-"-icon upper
right) then the form does not minimize just as any other form. Instead
it shrinks to the three windows-icons and appears in lower left corner.
The form is a big complicated thing with lots of controls and a lot of
lapels and panels that are created in runtime.
I should like to have the form react to minimize as any other form, that
is appear as another icon on the process line.
I have no doubt that it is something that I do myself to the form, but I
cannot locate what.
I run XE2 on Win10
Please advise.
Robert Triest

Posts: 687
Registered: 3/24/05
Re: Minimizing a form
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 30, 2016 7:08 AM   in response to: Lars Groennegaard in response to: Lars Groennegaard
Not sure, did you try:

Application.MainFormOnTaskbar := True;
http://docwiki.embarcadero.com/Libraries/Seattle/en/Vcl.Forms.TApplication.MainFormOnTaskBar
Lars Groennegaard

Posts: 82
Registered: 5/12/01
Re: Minimizing a form
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 30, 2016 7:32 AM   in response to: Robert Triest in response to: Robert Triest
It was in my application .dpr file already.
I suppose it influences the Main form only. My problem is a secondary form.

Den 30-11-2016 kl. 16:08 skrev Robert Triest:
Not sure, did you try:

Application.MainFormOnTaskbar := True;
http://docwiki.embarcadero.com/Libraries/Seattle/en/Vcl.Forms.TApplication.MainFormOnTaskBar
Robert Triest

Posts: 687
Registered: 3/24/05
Re: Minimizing a form
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 30, 2016 8:26 AM   in response to: Lars Groennegaard in response to: Lars Groennegaard
For main form only, I think so too but also try: (to be sure..)

Application.MainFormOnTaskbar := False;
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Minimizing a form
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 30, 2016 9:18 AM   in response to: Lars Groennegaard in response to: Lars Groennegaard
Lars wrote:

I should like to have the form react to minimize as any other form,
that is appear as another icon on the process line.

Secondary Forms are not displayed on the Taskbar by default. If Application.MainFormOnTaskbar
is true then only the MainForm appears on the Taskbar, otherwise the TApplication
window appears instead. If you want a secondary Form to appear on the Taskbar,
you have to override its CreateParams() method to force it manually:

procedure TMyForm.CreateParams(Params: TCreateParams);
begin
  inherited;
  with Params do
  begin
    ExStyle := ExStyle or WS_EX_APPWINDOW;
    WndParent := GetDesktopWindow;
  end;
end;


--
Remy Lebeau (TeamB)
Lars Groennegaard

Posts: 82
Registered: 5/12/01
Re: Minimizing a form
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 30, 2016 9:33 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hi Remy
I added the procedure, and got the following warning and error:
[DCC Warning] KalenderF.pas(128): W1010 Method 'CreateParams' hides
virtual method of base type 'TCustomForm'
[DCC Error] KalenderF.pas(167): E2008 Incompatible types

My procedure implementation is
  procedure TFullKalenderForm.CreateParams(Params: TCreateParams);
begin
   inherited;
   with Params do
   begin
     ExStyle := ExStyle or WS_EX_APPWINDOW;
     WndParent := GetDesktopWindow;
   end;
end;


I interface it in the FullKalenderForm's public section

TFullKalenderForm is Tform
  TFullKalenderForm = class(TForm)


Once I get this to compile, I wonder how is the procedure going to be
executed?. Do I need to call it somewhere?

Den 30-11-2016 kl. 18:18 skrev Remy Lebeau (TeamB):

Lars wrote:

I should like to have the form react to minimize as any other form,
that is appear as another icon on the process line.

Secondary Forms are not displayed on the Taskbar by default. If Application.MainFormOnTaskbar
is true then only the MainForm appears on the Taskbar, otherwise the TApplication
window appears instead. If you want a secondary Form to appear on the Taskbar,
you have to override its CreateParams() method to force it manually:

procedure TMyForm.CreateParams(Params: TCreateParams);
begin
   inherited;
   with Params do
   begin
     ExStyle := ExStyle or WS_EX_APPWINDOW;
     WndParent := GetDesktopWindow;
   end;
end;

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Minimizing a form
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 30, 2016 9:39 AM   in response to: Lars Groennegaard in response to: Lars Groennegaard
Lars wrote:

I added the procedure, and got the following warning and error:

[DCC Warning] KalenderF.pas(128): W1010 Method 'CreateParams'
hides virtual method of base type 'TCustomForm'

[DCC Error] KalenderF.pas(167): E2008 Incompatible types

Sorry, typo on my part. It should be like this instead:

type
  TFullKalenderForm = class(TForm)
    ...
  protected
    procedure CreateParams(var Params: TCreateParams); override;
    ...
  end;
 
...
 
procedure TFullKalenderForm.CreateParams(var Params: TCreateParams);
begin
  inherited;
  with Params do
  begin
    ExStyle := ExStyle or WS_EX_APPWINDOW;
    WndParent := GetDesktopWindow;
  end;
end;


Once I get this to compile, I wonder how is the procedure going to be
executed?

It is a virtual method, it is called automatically whenever the TForm's window
is being (re)created.

Do I need to call it somewhere?

No. The VCL calls it for you.

--
Remy Lebeau (TeamB)
Lars Groennegaard

Posts: 82
Registered: 5/12/01
Re: Minimizing a form
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 30, 2016 11:43 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hi Remy
As always,fantastic service

Den 30-11-2016 kl. 18:39 skrev Remy Lebeau (TeamB):
Lars wrote:

I added the procedure, and got the following warning and error:

[DCC Warning] KalenderF.pas(128): W1010 Method 'CreateParams'
hides virtual method of base type 'TCustomForm'

[DCC Error] KalenderF.pas(167): E2008 Incompatible types

Sorry, typo on my part. It should be like this instead:

type
   TFullKalenderForm = class(TForm)
     ...
   protected
     procedure CreateParams(var Params: TCreateParams); override;
     ...
   end;
 
...
 
procedure TFullKalenderForm.CreateParams(var Params: TCreateParams);
begin
   inherited;
   with Params do
   begin
     ExStyle := ExStyle or WS_EX_APPWINDOW;
     WndParent := GetDesktopWindow;
   end;
end;


Once I get this to compile, I wonder how is the procedure going to be
executed?

It is a virtual method, it is called automatically whenever the TForm's window
is being (re)created.

Do I need to call it somewhere?

No. The VCL calls it for you.
Tony Nasca

Posts: 2
Registered: 11/25/07
Re: Minimizing a form
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 13, 2017 8:06 PM   in response to: Lars Groennegaard in response to: Lars Groennegaard
I am still coding in D5 so I needed to make it dynamic for XE10 Only

I created a FormWin10.pas in both D5 and XE10 app folder which creates a new TformA see below

Then in all the subequent forms I added ", FormWin10" to the uses section

Then where the form is created I call the new TFormA

Tformname = class(TFormA)

so when the TformA is called, it passes on the new parameter

ExStyle := ExStyle or WS_EX_APPWINDOW; //stacks up windows on make icon. //very cool.

unit FormWin10;

interface

uses
{$ifnDef ver130} //Xe10
System.SysUtils,
System.Classes,
Vcl.Controls,
Vcl.Forms,
Winapi.Windows;

{$Else} //D5
SysUtils,
Classes,
Controls,
Forms;
{$EndIf}

type

TFormA = class(TForm) //created a new form TformA = TForm

//only runs in XE10
{$ifnDef ver130}procedure CreateParams(var Params: TCreateParams);override;{$EndIf}
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
end;

{$ifnDef ver130}procedure Register;{$EndIf}

implementation

{$ifnDef ver130}
procedure Register;
begin
RegisterComponents('DoveNet', [TFormA]);
end;
{$EndIf}

{ TFormA }

{$ifnDef ver130}
procedure TFormA.CreateParams(var Params: TCreateParams);
begin
inherited;
with Params do
begin
ExStyle := ExStyle or WS_EX_APPWINDOW; //stacks up windows on make icon. //very cool.
//WndParent := GetDesktopWindow; //removed because it brought main form forward above calling form.
end;
end;
{$EndIf}

end.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Minimizing a form
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 14, 2017 3:12 PM   in response to: Tony Nasca in response to: Tony Nasca
Tony Nasca wrote:

{$ifnDef ver130} //Xe10

Testing VERxxx values doesn't scale very well when you deal with
multiple versions, or upgrade to newer versions. You really should be
using {$IF CompilerVersion >= ...} or {$IF RTLVersion >= ...} instead.
But {$IF} doesn't exist in Delphi 5 (it was added in Delphi 6), so you
can {$IFDEF CONDITIONALEXPRESSIONS} instead (which specifies supports
for {$IF}), eg:

uses
  {$IFDEF CONDITIONALEXPRESSIONS}
  // D6 and later
  ...
  {$ELSE}
  // D5 and earlier
  ...
  {$ELSE}
;


However, in this particular example, a better option is to simply not
{$IFDEF} your 'uses' clause at all:

uses
  SysUtils,
  Classes,
  Controls,
  Forms,
  Windows;


Just make sure 'System', 'Vcl', and 'Winapi' are specified in the "Unit
scope names" field in the Project Options of your Delphi 10 project
(they should be by default in a VCL project).

//only runs in XE10
{$ifnDef ver130}
procedure CreateParams(var Params: TCreateParams);override;
{$EndIf}

Again, don't use VERxxx:

type
  TFormA = class(TForm)  //created a new form TformA = TForm
  {$IFDEF CONDITIONALEXPRESSIONS}
  //only runs in D6+
  protected
    procedure CreateParams(var Params: TCreateParams);override;
  {$ENDIF}
  end;


procedure Register;
begin
RegisterComponents('DoveNet', [TFormA]);
end;

Why are you registering a custom TForm as a design-time component?

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02