一般的方法很难做到,因为Delphi并不能获取到打印对话框窗口中发生的消息,
以下是测试代码,但代码中并不能截获“取消”或“确定”按下后产生的message
procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
if not (Msg.hwnd in [Self.Handle,Button1.Handle,Memo1.Handle]) then
Memo1.Lines.Add(Format('hwnd=$%x, message=$%x, wp=%d, lp=%d',[Msg.hwnd,Msg.message,Msg.wParam,Msg.lParam]));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled:=True;
PrintDialog1.Execute;
Timer1.Enabled:=False;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
Application.OnMessage:=AppMessage;
end;