在 Inno Setup 中复制到剪贴板

Copy to clipboard in Inno Setup

有什么方法可以使用 Inno Setup 将字符串复制到剪贴板吗?

我需要实现一个按钮来将字段的内容复制到剪贴板。

是的,您可以发送 WM_COPY 消息。例如:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
const
  WM_COPY = 01;

var
  EditToCopy: TNewEdit;

procedure CopyToClipboard(Control: TWinControl);
begin
  SendMessage(Control.Handle, WM_COPY, 0, 0);
end;

procedure ButtonCopyClick(Sender: TObject);
begin
  EditToCopy.SelectAll;
  CopyToClipboard(EditToCopy);
end;

procedure InitializeWizard;
var
  ButtonCopy: TNewButton;
  WizardPage: TWizardPage;
begin
  WizardPage := CreateCustomPage(wpWelcome, 'Caption', 'Description');
  EditToCopy := TNewEdit.Create(WizardForm);
  EditToCopy.Parent := WizardPage.Surface;
  EditToCopy.Text := 'Text to copy';
  ButtonCopy := TNewButton.Create(WizardForm);
  ButtonCopy.Parent := WizardPage.Surface;
  ButtonCopy.Caption := 'Copy';
  ButtonCopy.Top := EditToCopy.Top + EditToCopy.Height + 8;
  ButtonCopy.OnClick := @ButtonCopyClick;
end;