5

I need to hide a Windows form from the taskbar but I can't use WS_EX_TOOLWINDOW because I need the system menu and min/max buttons on the form's title bar.

If I switch the form to a tool window at runtime the form skinning is stuffed up. From searching on the Web I see that VB has a ShowInTaskbar property and I'm wondering if this would do what I want, and whether it can be implemented in Delphi 2006. Also this project is a COM server and has no MainForm, etc.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794

7 Answers7

7

Thanks to Stu for putting me on to the answer so quickly. In my case I had to manually add the owning form's handle into the CreateParams, but that may not be necessary in other/normal cases.

procedure TfrmWord2Site.CreateParams(var Params:TCreateParams);
begin
  inherited CreateParams(Params);
  Params.WndParent := <your owner form>.Handle;
  Params.ExStyle := Params.ExStyle and not WS_EX_APPWINDOW;
end;
6

There's an interesting discussion of this exact problem here (from a VB6 persepective).

The most relevant bit from your question's perspective is:

"When you create a window, the taskbar examines the window's extended style to see if either the WS_EX_APPWINDOW (&H40000) or WS_EX_TOOLWINDOW (&H80) style is turned on. If WS_EX_APPWINDOW is turned on, the taskbar shows a button for the window, and if WS_EX_ TOOLWINDOW is turned on, the taskbar does not show a button for the window. A window should never have both of these extended styles. If the window doesn't have either of these styles, the taskbar decides to create a button if the window is unowned and does not create a button if the window is owned."

Incidentally, you use the GetWindow API function with the GW_OWNER flag to determine whether a window is owned.

Stu Mackellar
  • 11,510
  • 1
  • 38
  • 59
  • Thanks Stu. You have shown me the problem. Even though I'm turning off both those options, the taskbar button is still showing because the form doesn't have an owner from Windows point of view. This is complicated because it is a COM plugin. –  Nov 04 '08 at 13:23
1

With thanks to http://www.scalabium.com/faq/dct0096.htm.

procedure TForm1.FormCreate(Sender: TObject);
begin
  ShowWindow(Application.Handle, SW_HIDE);
  SetWindowLong(Application.Handle, GWL_EXSTYLE,
    GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
  ShowWindow(Application.Handle, SW_SHOW);
end;

I tested it and it worked with Delphi2006. And windows menu and min/max buttons are still visible.

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
  • 1
    Thanks, but I was already using this code. In my question I pointed out that I didn't want to use WS_EX_TOOLWINDOW. Great to have such a quick response though :) –  Nov 04 '08 at 13:25
1

in Delphi XE (2010) this works perfectly: you shoud edit main form,

program prog;  

uses
Forms,
Unit1 in 'Unit1.pas' {Form1};

begin
Application.Initialize;

// this value is set to "true", but you shoud set it "false"
Application.MainFormOnTaskbar := false;

Application.CreateForm(TForm1, Form1);
Application.Run;
end.

(for this main form search in "modeling view" window)

after this, go to unit1.pas, your main forms unit and "OnShow" event of form1 do:

procedure TForm1.FormShow(Sender: TObject);

begin

ShowWindow(Application.Handle, SW_HIDE);

end;

this will help, i had the same problem, searched whole net but without resolt

besKa88
  • 19
  • 3
0

I'm looking a piece of code to integrate a Textbox to the Windows Taskbar.

I plan to create a toolbar I can't to ' integrate it to the taskbar.

Thank you for your help pj

Mohamad Shiralizadeh
  • 8,329
  • 6
  • 58
  • 93
0

Solved my problems in this area by BordersStyle bsDialog/bsToolWindow (but then I did not need the min/max...). But I wonder why you should want to combine these attributes.. Won't it confuse the 'normal' user?

-1

One way to do this in C# is:

ShowWindow(_window, SWHide);

int style = GetWindowLong(_window, GWL_EXSTYLE);
style |= WS_EX_TOOLWINDOW;
SetWindowLong(_window, GWL_EXSTYLE, style);

ShowWindow(_window, SWShow);
Synetech
  • 9,643
  • 9
  • 64
  • 96