Page 1 of 1

More Webgadget Printing Trouble

Posted: Wed Jul 21, 2004 4:53 pm
by Karbon
Really, really odd behavior here. I am trying to load and print a web page in a webgadget. It works fine if I load the page and have another button to trigger the print. When I load the URL with setgadgettext() and immediately try to issue the print command I get absolutely nothing.

Code: Select all

WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(webgadget), #GWL_USERDATA)
  
  Repeat
    WebObject\get_Busy(@IsBusy.l)
    Delay(1)
  Until IsBusy = 0
  
  If prompt = 0
    WebObject\ExecWB(#OLECMDID_PRINT, #OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)
  Else
    WebObject\ExecWB(#OLECMDID_PRINTPREVIEW, #OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)
  EndIf
WebObject\get_Busy() returns non-zero the very first time it's called but 1 every time after. WebObject\get_Readystate() ALWAYS returns 1, so it's totally useless too. I've tried delay()'ing - even a really long time, but it seems as if the web gadget is waiting for something, loading, or in some kind of disabled state.

Any other ideas?

Thanks!!

Posted: Wed Jul 21, 2004 7:05 pm
by freak
Try to process window events while waiting for the page to load.
A simple "While WindowEvent(): Wend" in the wait loop could do the trick.

Timo

Posted: Wed Jul 21, 2004 7:09 pm
by Sparkie
See if you can work with this...

Code: Select all

#READYSTATE_UNINITIALIZED = 0
#READYSTATE_LOADING = 1
#READYSTATE_LOADED = 2
#READYSTATE_INTERACTIVE = 3
#READYSTATE_COMPLETE = 4

#OLECMDID_PRINT = 6
#OLECMDID_PRINTPREVIEW = 7

#OLECMDEXECOPT_DONTPROMPTUSER = 2

Global WebObject.IWebbrowser2

Procedure printweb(prompt)
  
  If prompt = 0 
    WebObject\ExecWB(#OLECMDID_PRINT, #OLECMDEXECOPT_DONTPROMPTUSER, 0, 0) 
  Else 
    WebObject\ExecWB(#OLECMDID_PRINTPREVIEW, #OLECMDEXECOPT_DONTPROMPTUSER, 0, 0) 
  EndIf
   
EndProcedure

If OpenWindow(0, 0, 0, 700, 500,  #PB_Window_SystemMenu , "Auto-Print web page") 
   
  If CreateGadgetList(WindowID()) 
    WebGadget(0, 0, 0, WindowWidth(), WindowHeight()-25, "www.google.com")
    WebObject = GetWindowLong_(GadgetID(0), #GWL_USERDATA)
   
  EndIf 
  
EndIf 

printit = #True ; ok to print when ready

Repeat 
   
  Event = WaitWindowEvent() 
  
  If printit = #True
    WebObject\get_ReadyState(@ready.l)
    ; from what I've seen in the past, a web page may not reach
    ; #READYSTATE_COMPLETE = 4 if there are missing objects, such
    ; as images. Once the web page reaches #READYSTATE_INTERACTIVE = 3
    ; it seems as though print works fine. You can change the following line to
    ; If ready = 4 And printit = #True
    ; and see which works best in your situation.
    If ready > 2 And printit = #True ; once we have interactive page we print
    
      If printit
        printweb(0) ; print the page with prompt = 0
        printit = #False ; turn print off until we set to #True for next print job
      EndIf
    
    EndIf

  EndIf

Until Event = #PB_EventCloseWindow
End