Поздний ответ - я только что обошел эту проблему. Мы хотели функциональность ALT-TAB и WIN-TAB в стиле Aero, но MainFormOnTaskBar вызвал некоторые проблемы со сторонним компонентом. (Стыковка LMD - если на основной форме был док-сайт, а на дочернем - док-сайт, перетаскивание закрепленного элемента на дочернем элементе вывело основную форму вперед)
Решением этой проблемы было:
- Установите для Params.WndParent значение 0 в CreateParams
- используйте интерфейс ITaskBarList для управления вкладками панели задач. Это также добавляет окна к обработчикам ALT-TAB и WIN-TAB,
TaskBarList.pas
unit TaskbarList;
interface
uses
Windows, Messages,
CommCtrl,
ShlObj,
SysUtils, Classes, ComCtrls;
const
SID_ITaskbarList = '{56FDF342-FD6D-11D0-958A-006097C9A090}';
SID_ITaskbarList2 = '{602D4995-B13A-429B-A66E-1935E44F4317}';
SID_ITaskbarList3 = '{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}';
SID_ITaskbarList4 = '{C43DC798-95D1-4BEA-9030-BB99E2983A1A}';
CLSID_TaskbarList: TGUID = '{56FDF344-FD6D-11d0-958A-006097C9A090}';
type
ITaskbarList = interface(IUnknown)
[SID_ITaskbarList]
function HrInit: HRESULT; stdcall;
function AddTab(hwnd: HWND): HRESULT; stdcall;
function DeleteTab(hwnd: HWND): HRESULT; stdcall;
function ActivateTab(hwnd: HWND): HRESULT; stdcall;
function SetActiveAlt(hwnd: HWND): HRESULT; stdcall;
end;
ITaskbarList2 = interface(ITaskbarList)
[SID_ITaskbarList2]
function MarkFullscreenWindow(hwnd: HWND; fFullscreen: BOOL): HRESULT; stdcall;
end;
type
THUMBBUTTON = record
dwMask: DWORD;
iId: UINT;
iBitmap: UINT;
hIcon: HICON;
szTip: packed array[0..259] of WCHAR;
dwFlags: DWORD;
end;
tagTHUMBBUTTON = THUMBBUTTON;
TThumbButton = THUMBBUTTON;
PThumbButton = ^TThumbButton;
// THUMBBUTTON flags
const
THBF_ENABLED = $0000;
THBF_DISABLED = $0001;
THBF_DISMISSONCLICK = $0002;
THBF_NOBACKGROUND = $0004;
THBF_HIDDEN = $0008;
THBF_NONINTERACTIVE = $10;
// THUMBBUTTON mask
THB_BITMAP = $0001;
THB_ICON = $0002;
THB_TOOLTIP = $0004;
THB_FLAGS = $0008;
THBN_CLICKED = $1800;
const
TBPF_NOPROGRESS = 0;
TBPF_INDETERMINATE = $1;
TBPF_NORMAL = $2;
TBPF_ERROR = $4;
TBPF_PAUSED = $8;
TBATF_USEMDITHUMBNAIL = $1;
TBATF_USEMDILIVEPREVIEW = $2;
const
STPF_NONE = $00000000;
STPF_USEAPPTHUMBNAILALWAYS = $00000001;
STPF_USEAPPTHUMBNAILWHENACTIVE = $00000002;
STPF_USEAPPPEEKALWAYS = $00000004;
STPF_USEAPPPEEKWHENACTIVE = $00000008;
type
ITaskbarList3 = interface(ITaskbarList2)
[SID_ITaskbarList3]
function SetProgressValue(hwnd: HWND; ullCompleted: ULONGLONG;
ullTotal: ULONGLONG): HRESULT; stdcall;
function SetProgressState(hwnd: HWND; tbpFlags: Integer): HRESULT; stdcall;
function RegisterTab(hwndTab: HWND; hwndMDI: HWND): HRESULT; stdcall;
function UnregisterTab(hwndTab: HWND): HRESULT; stdcall;
function SetTabOrder(hwndTab: HWND; hwndInsertBefore: HWND): HRESULT; stdcall;
function SetTabActive(hwndTab: HWND; hwndMDI: HWND;
tbatFlags: Integer): HRESULT; stdcall;
function ThumbBarAddButtons(hwnd: HWND; cButtons: UINT;
pButton: PThumbButton): HRESULT; stdcall;
function ThumbBarUpdateButtons(hwnd: HWND; cButtons: UINT;
pButton: PThumbButton): HRESULT; stdcall;
function ThumbBarSetImageList(hwnd: HWND; himl: HIMAGELIST): HRESULT; stdcall;
function SetOverlayIcon(hwnd: HWND; hIcon: HICON;
pszDescription: LPCWSTR): HRESULT; stdcall;
function SetThumbnailTooltip(hwnd: HWND; pszTip: LPCWSTR): HRESULT; stdcall;
function SetThumbnailClip(hwnd: HWND; var prcClip: TRect): HRESULT; stdcall;
end;
ITaskbarList4 = interface(ITaskbarList3)
[SID_ITaskbarList4]
function SetTabProperties (hwnd: HWND; stpFlags: Integer): HRESULT; stdcall;
end;
implementation
end.
BaseForm.pas:
unit BaseForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,
TaskBarList;
type
TBaseForm = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
class var FTaskBarList: ITaskbarList;
protected
class function TaskBarList: ITaskbarList;
procedure DoShow;override;
procedure DoHide;override;
procedure Activate;override;
procedure CreateParams(var Params: TCreateParams); override;
public
constructor Create(AOwner: TComponent); override;
end;
var
BaseForm: TBaseForm;
implementation
uses
ComObj;
{$R *.dfm}
{ TBaseForm }
procedure TBaseForm.Activate;
begin
inherited;
TaskBarList.ActivateTab(Handle);
end;
procedure TBaseForm.Button1Click(Sender: TObject);
begin
TBaseForm.Create(Self).Show;
end;
constructor TBaseForm.Create(AOwner: TComponent);
begin
inherited;
// remove taskbar button for Application.Handle
TaskBarList.DeleteTab(Application.Handle);
end;
procedure TBaseForm.CreateParams(var Params: TCreateParams);
begin
inherited;
if (Parent = nil) and (ParentWindow = 0) then // don't use on docked Windows
Params.WndParent := 0;
end;
procedure TBaseForm.DoHide;
begin
inherited;
TaskBarList.DeleteTab(Handle);
end;
procedure TBaseForm.DoShow;
begin
inherited;
TaskBarList.AddTab(Handle);
end;
class function TBaseForm.TaskBarList: ITaskbarList;
var
pIntF: IInterface;
begin
if not assigned(FTaskBarList) then
begin
pIntF := CreateComObject(CLSID_TaskbarList);
pIntF.QueryInterface(ITaskBarList, FTaskBarList);
FTaskBarList.HrInit;
end;
Result := FTaskBarList;
end;
end.
ПРИМЕЧАНИЕ. Я не проверял HRESULTS с помощью OleCheck, так как предпочел бы, чтобы он не работал в полевых условиях.