How to detect Print command has finished in TWebBrowser?

前端 未结 3 838
Happy的楠姐
Happy的楠姐 2021-01-14 03:24
procedure TForm1.Button1Click(Sender: TObject);
var 
  vaIn, vaOut: OleVariant;
begin
  WebBrowser1.Navigate(\'http://www.google.com\');
  while WebBrowser1.ReadySta         


        
3条回答
  •  星月不相逢
    2021-01-14 03:59

    When I've been looking for a solution I've found the PRINT_WAITFORCOMPLETION flag few days ago but can't get it to work. And the trick was quite easy (see note nr. 4). I've been wrong with passing the third parameter of ExecWB method for the OLECMDID_PRINT command as variant type VT_I4 but it is overloaded and for PRINT_WAITFORCOMPLETION must be converted to the exact type VT_I2, what is in Delphi represented as a smallint.

    Here is how to make the print dialog modal (also answer to this by accident :)

    procedure TForm1.Button1Click(Sender: TObject);
    var
      vaIn: OleVariant;
      vaOut: OleVariant;
    const
      PRINT_WAITFORCOMPLETION = $02;
    begin
      WebBrowser1.Navigate('http://www.google.com');
      while WebBrowser1.ReadyState < READYSTATE_COMPLETE do
        Application.ProcessMessages;
    
      vaIn := OleVariant(VarAsType(PRINT_WAITFORCOMPLETION, varSmallint));
      WebBrowser1.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, vaIn, vaOut);
    
      ShowMessage('Print dialog has been closed ...');
    end;
    

    Unfortunately you can't get any feedback if user sent the document to the printer queue or cancelled the dialog. The IDM_PRINT has no output value, which would return this. Another thing is that even if user accepts the printing dialog it doesn't mean that the document will be physically printed. For this you would have to, as Remy said, monitor the printer queue.

提交回复
热议问题