views:

77

answers:

2

Hello all,

I've found many ways to make the TWebBrowser show a modeless print dialog box, but how do I make it show a modal one? I would like to print an html page, that's why I need the modal dialog.

I'd really appreciate your ideas on this one.

Thanks!

+1  A: 

I cannot think of a reason why there would be lots of ways to show a modeless dialog. Why would you want to continue interacting with the web browser while a modeless print dialog is displayed?

If you want to initiate the print by program, but need the user to select the printer, use:

ExecWB(OLE_CMDID_PRINT, OLECMDEXECOPT_PROMPTUSER); 
frogb
You didn't read the post well. ExecWB(OLE_CMDID_PRINT, OLECMDEXECOPT_PROMPTUSER); will show a modeless print dialog. That means while the print dialog is shown, the user can continue interacting with the program. And that's not what I want! So how do I make it show a MODAL print dialog? (meaning that the print dialog is modal to my program, not the webbrowser!)
Steve
OK, I always use DONTPROMPTUSER! Have you tried simply disabling the webbrowser while you do this?
frogb
A: 

Eureka! I solved it.

Here is how:

When you show the modeless print dialog, you can disable the calling Form in Delphi. Then you can use the OnCommandStateChange event to detect when the user Prints or Cancels the Print dialog.

Example code:

  WebBrowser1.OnCommandStateChange:=WebBrowser1CommandStateChange;
  WebBrowser1.ControlInterface.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER,
    vaIn, vaOut);

procedure TForm1.WebBrowser1CommandStateChange(Sender: TObject; Command:
    Integer; Enable: WordBool);
begin
  if Enabled then
    Enabled:=false
  else begin
    Enabled:=true;
    WebBrowser1.OnCommandStateChange:=nil;
  end;
end;

I kindly ask you people to test my solution, as I'm not sure of the reliability of this code.

Thanks!

Steve