Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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;

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.

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

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?

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

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top