views:

2136

answers:

3

Hi,

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(Handle, SW_HIDE);
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW );
ShowWindow(Handle, SW_SHOW);

The above code is called in the FormCreate method.

+3  A: 

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.

stukelly
A: 

Also tested to no avail.

I believe the form button that is appearing is the Application's hidden main form, not one of the Delphi forms I have created.

Have tried pretty much everything I can think of and the taskbar button still appears. If you use SW_MINIMIZE the task bar button dissappears, but the form is just minimized, then once you maximize it then goes back onto the taskbar.

James
Have you removed the code from the FromCreate event? I have tested the above code with Delphi 2009 on Windows 2000 and XP
stukelly
This is not an answer. Rather than doing this, you should edit your question, or use the comment feature if you have sufficient rep.
Argalatyr
So you think the code shouldn't be called in the FormCreate event?
James
What are you trying to achieve in the FormCreate event? You can set the BorderStyle of your Form at design time. http://tinyurl.com/c34ysu
stukelly
+4  A: 

Hi one of my collegues found the resolution to this question.

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.

James
Thanks for posting your solution back on stack overflow. I thought you wanted to hide the taskbar button and the main form.
stukelly