Link to home
Start Free TrialLog in
Avatar of StTwister
StTwister

asked on

Hidding Form

Hi experts,

Ihave a problem hidding my form. If I set the form's visible property on the object inspector to false, when i run the program, i still can see the form. I also tried to set the form's visible property to false in the FormCreate procedure, but it doesn't work either. However, it works if i hide the form from the FormClose procedure and set Action to caNone.

Hope u can help me.

Thanks.

PS: i am using delphi4 and windows XP
Avatar of Kunfufaresi
Kunfufaresi

Hello,

there arse some ways you can use
1) From Project menu choose Options and remove auto-create of form2

2) if you want to hide main form then you could use
Application.Minimize
Avatar of StTwister

ASKER

removing the auto-create doesn't hide the form, it simply doesn't create it, so i can't actually use that form.

Application.Minimize only minimizes the form, it doesn't hide it.
you can use

SendMessage(Form1.handle, WM_SYSCOMMAND, SW_HIDE);

I think that is the correct function and right parameters. I am not on a windows machine at the minute, so I'll check to see if the params are correct then ill post another reply.

hopefully though, the above is the correct params
The procedure has one missing parameter, but it still doesn't matter, as i already tried with ShowWindow(Form1.Handle, SW_Hide), which does exactly the same thing. I also noticed that i can hide the form from any other procedure except FormCreate. For example i can hide it if i push a button or with a timer, but it doesn't respond in the FormCreate procedure.

Thanks.
Hello,

in formCreate the form is not yet created but in the process of being created so you will get a runtime error obviously. I remember using timer too. however if you put  form1.hide; in onPaint event of the form it will get hidden just after creation.

procedure TForm1.FormPaint(Sender: TObject);
begin
 form1.hide;
end;

hopefully this helps
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure OnCreateForm(var Msg : TMessage); message WM_SHOWWINDOW;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

{ TForm1 }

procedure TForm1.OnCreateForm(var Msg: TMessage);
begin
  // here the form is shown
  if Self <> Application.MainForm then
    // this is not the main form and we can hide it
    Self.Hide;
end;

end.
in both the situations, the form is hidden, but it still apears for a very short amount of time. i want the form not to apear at all.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Kunfufaresi
Kunfufaresi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The form still apears, but this time it disapears much more faster. It probably didn't happen to your computer beacause you're not running on win xp, or u don't have delphi 4

Thanks.
Sorry, i was wrong, your ideea works just fine.

Thanks.