unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, Windows, Variants; type { TForm1 } TForm1 = class(TForm) Label1: TLabel; StaticText1: TStaticText; TimerMonitor: TTimer; procedure TimerMonitorTimer(Sender: TObject); private FParentHWND: HWND; public procedure PreparePreview(AParent: HWND); end; var Form1: TForm1; implementation {$R *.lfm} procedure TForm1.PreparePreview(AParent: HWND); var R: TRect; begin FParentHWND := AParent; // フォームの拡張スタイルから「タスクバー表示フラグ」を除去して // 「ツールウィンドウ」属性を付与 SetWindowLong(Handle, GWL_EXSTYLE, (GetWindowLong(Handle, GWL_EXSTYLE) and not WS_EX_APPWINDOW) or WS_EX_TOOLWINDOW); // フォームのスタイルを「子ウィンドウ」化してタイトルバーなどを除去 SetWindowLong(Handle, GWL_STYLE, (GetWindowLong(Handle, GWL_STYLE) or WS_CHILD) and not (WS_POPUP or WS_CAPTION or WS_THICKFRAME)); // 親ウィンドウをプレビュー枠に設定 Windows.SetParent(Handle, FParentHWND); // サイズ合わせ Windows.GetClientRect(FParentHWND, @R); SetBounds(0, 0, R.Right, R.Bottom); // 表示。これでLCLの描画サイクルが正常に回る Self.Visible := True; TimerMonitor.Enabled := True; end; procedure TForm1.TimerMonitorTimer(Sender: TObject); begin // 親ウィンドウが消滅(設定画面が閉じられた)したらアプリ終了 if (FParentHWND <> 0) and (not IsWindow(FParentHWND)) then Application.Terminate; end; end.