Mega Code Archive
Modifying Contents of the Taskbar from Delphi application
Title: Modifying Contents of the Taskbar from Delphi application
Question: How to add my form to taskbar
Answer:
The ITaskbarList interface is used to control the taskbar. First of all we have to declare ITaskbarList interface in the project:
const
CLSID_TaskbarList: TGUID = '{56FDF344-FD6D-11d0-958A-006097C9A090}';
type
ITaskbarList = interface
['{56FDF342-FD6D-11d0-958A-006097C9A090}']
{ virtual HRESULT STDMETHODCALLTYPE HrInit( void) = 0;}
function HrInit: HResult; stdcall;
{ virtual HRESULT STDMETHODCALLTYPE AddTab(
/* [in] */ HWND hwnd) = 0; }
function AddTab(hwnd: Cardinal): HResult; stdcall;
{ virtual HRESULT STDMETHODCALLTYPE DeleteTab(
/* [in] */ HWND hwnd) = 0; }
function DeleteTab(hwnd: Cardinal): HResult; stdcall;
{ virtual HRESULT STDMETHODCALLTYPE ActivateTab(
/* [in] */ HWND hwnd) = 0; }
function ActivateTab(hwnd: Cardinal): HResult; stdcall;
{ virtual HRESULT STDMETHODCALLTYPE SetActiveAlt(
/* [in] */ HWND hwnd) = 0; }
function SetActiveAlt(hwnd: Cardinal): HResult; stdcall;
end;
Then we have to create instance of taskbarlist object and initialize it:
procedure TForm1.FormCreate(Sender: TObject);
begin
FTaskbarList:= CreateComObject(CLSID_TaskbarList) as ITaskbarList;
FTaskbarList.HrInit;
end;
Now we can change contents of taskbar:
procedure TForm1.FormShow(Sender: TObject);
begin
FTaskbarList.AddTab(Handle);
end;
procedure TForm1.FormHide(Sender: TObject);
begin
FTaskbarList.DeleteTab(Handle);
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
FTaskbarList.ActivateTab(Handle);
end;