I have a form with a bsNone Bordestyle, with transparency. To show icon on the Task Bar, I added the following code in the create procedure:
procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong(Handle, GWL_EXSTYLE, WS_EX_APPWINDOW);
end;
With this, the icon is displayed but transparency does not work. Any suggestions? Thanks.
Window styles, extended and standard, are sets of bit flags. You have set the WS_EX_APPWINDOW
extended style, but cleared all other extended styles. What you meant to do was to use bitwise OR to combine the WS_EX_APPWINDOW
extended style with the existing extended styles.
ExStyle := GetWindowLong(Form.Handle, GWL_EXSTYLE);
SetWindowLong(Form.Handle, GWL_EXSTYLE, ExStyle or WS_EX_APPWINDOW);
However, calling SetWindowLong
is the wrong way to do this. Delphi windows may be re-created and when they are, the styles are re-applied. So the right place for the code is in an overridden CreateParams
method.
procedure TMyForm.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
end;
However, setting WS_EX_APPWINDOW
is usually the wrong way to put a button onto the taskbar. So long as the window is unowned it will have a button on the taskbar. You can achieve that by setting MainFormOnTaskbar
to True
, or by setting WndParent
to 0 in CreateParams
.