我们也可以仿照一个。
新建一个窗口
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShlObj, ActiveX, ComObj, ExtCtrls, StdCtrls, ImgList;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
FTaskBarList: ITaskbarList4;
btnIcon : TIcon;
Fbtns: array [0 .. 2] of TThumbButton;
protected
procedure WndProc(var Message: TMessage); override;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
begin
ZeroMemory(@Fbtns, SizeOf(TThumbButton) * length(Fbtns));
for I := Low(Fbtns) to High(Fbtns) do
begin
Fbtns[I].dwMask := THB_ICON or THB_TOOLTIP or THB_FLAGS;
Fbtns[i].hIcon := btnIcon.Handle;
Fbtns[I].dwFlags := THBF_ENABLED;
Fbtns[I].iId := I;
Fbtns[I].szTip := 'ABCD';
end;
// 这里什么图也没给,出现的按钮都是没有图标的
FTaskBarList.ThumbBarAddButtons(Handle, length(Fbtns), @Fbtns);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FTaskBarList := CreateComObject(CLSID_TaskbarList) as ITaskbarList4;
FTaskBarList.HrInit();
btnIcon := TIcon.Create;
btnIcon.LoadFromFile('c:\AquaValue2.ico');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
btnIcon.Free;
end;
procedure TForm1.WndProc(var Message: TMessage);
begin
inherited;
case Message.Msg of
WM_COMMAND:
begin
case HiWord(Message.WParam) of
THBN_CLICKED:
begin
ShowMessage(Format('你按了按钮[id=%d]', [LoWord(Message.WParam)]));
end;
end;
end;
end;
end;
end.