如果没有源代码,我猜你没有将正确的窗口句柄传递给DwmRegisterThumbnail
函数。您可以使用该 FmxHandleToHWND
函数将 FMX 表单句柄转换为 Windows 句柄。
试试这个修改后的代码版本
unit Unit28;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, Winapi.Windows, Winapi.DwmApi;
type
TForm28 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
FTumbnail: HTHUMBNAIL;
FPreviewEnabled: Boolean;
{ Private declarations }
procedure PreviewWindow(const ASource, ADest: HWND; const ARect: TRect);
procedure PreviewDisable;
public
{ Public declarations }
end;
var
Form28: TForm28;
implementation
uses
FMX.Platform.Win;
{$R *.fmx}
procedure TForm28.Button1Click(Sender: TObject);
var
Index: Integer;
LRect: TRect;
begin
LRect := Rect(5, 5, Self.Width -20,Self.Height -50);
//here I'm using a fixed window handle ($000102EE) just a sample
PreviewWindow($000102EE, FmxHandleToHWND(Self.Handle), LRect);
end;
procedure TForm28.FormCreate(Sender: TObject);
begin
FPreviewEnabled := False;
end;
procedure TForm28.FormDestroy(Sender: TObject);
begin
PreviewDisable;
end;
procedure TForm28.PreviewDisable;
begin
if FPreviewEnabled then
FPreviewEnabled := NOT Succeeded(DwmUnregisterThumbnail(FTumbnail));
end;
procedure TForm28.PreviewWindow(const ASource, ADest: HWND; const ARect: TRect);
var
LResult: HRESULT;
LThumpProp: DWM_THUMBNAIL_PROPERTIES;
begin
if not DwmCompositionEnabled then begin
ShowMessage('DWM composition is NOT enabled.');
Exit;
end;
PreviewDisable;
FPreviewEnabled := Succeeded(DwmRegisterThumbnail(ADest, ASource, @FTumbnail));
if FPreviewEnabled then
begin
LThumpProp.dwFlags := DWM_TNP_SOURCECLIENTAREAONLY or DWM_TNP_VISIBLE or DWM_TNP_OPACITY or DWM_TNP_RECTDESTINATION;
LThumpProp.fSourceClientAreaOnly := False;
LThumpProp.fVisible := True;
LThumpProp.opacity := 200;
LThumpProp.rcDestination := ARect;
LResult := DwmUpdateThumbnailProperties(FTumbnail, LThumpProp);
FPreviewEnabled := (LResult = S_OK);
end else
ShowMessage('Cannot link to window ' + IntToStr(ASource));
end;
end.