Maybe already asked ...
Maybe already asked ...
Hello,
I'm desperately looking for a way to add a print function in a webgadget; I've read that we can use javascript to ad a button in the document itself, but how can we print any web page, when loaded ?
Thanks for any answer.
Pierre
I'm desperately looking for a way to add a print function in a webgadget; I've read that we can use javascript to ad a button in the document itself, but how can we print any web page, when loaded ?
Thanks for any answer.
Pierre
With PB 3.80 and it's Interface stuff, this can be done quite easy using the
IWebBrowser2 Interface of the Webgadget's WebBrowser object.
For more info about IWebBrowser2, go here:
http://msdn.microsoft.com/library/defau ... owser2.asp
Here's the code:
Timo
IWebBrowser2 Interface of the Webgadget's WebBrowser object.
For more info about IWebBrowser2, go here:
http://msdn.microsoft.com/library/defau ... owser2.asp
Here's the code:
Code: Select all
; Constants for the ExecWB() method of IWebBrowser2
Enumeration 1
#OLECMDID_OPEN
#OLECMDID_NEW
#OLECMDID_SAVE
#OLECMDID_SAVEAS
#OLECMDID_SAVECOPYAS
#OLECMDID_PRINT
#OLECMDID_PRINTPREVIEW
#OLECMDID_PAGESETUP
#OLECMDID_SPELL
#OLECMDID_PROPERTIES
#OLECMDID_CUT
#OLECMDID_COPY
#OLECMDID_PASTE
#OLECMDID_PASTESPECIAL
#OLECMDID_UNDO
#OLECMDID_REDO
#OLECMDID_SELECTALL
#OLECMDID_CLEARSELECTION
#OLECMDID_ZOOM
#OLECMDID_GETZOOMRANGE
#OLECMDID_UPDATECOMMANDS
#OLECMDID_REFRESH
#OLECMDID_STOP
#OLECMDID_HIDETOOLBARS
#OLECMDID_SETPROGRESSMAX
#OLECMDID_SETPROGRESSPOS
#OLECMDID_SETPROGRESSTEXT
#OLECMDID_SETTITLE
#OLECMDID_SETDOWNLOADSTATE
#OLECMDID_STOPDOWNLOAD
EndEnumeration
Enumeration 0
#OLECMDEXECOPT_DODEFAULT
#OLECMDEXECOPT_PROMPTUSER
#OLECMDEXECOPT_DONTPROMPTUSER
#OLECMDEXECOPT_SHOWHELP
EndEnumeration
; -----------------------------------------------------
#WebGadget = 1
#Button = 2
OpenWindow(0, 0, 0, 800, 800, #PB_Window_Screencentered|#PB_Window_SystemMenu, "WebBrowser")
CreateGadgetList(WindowID())
WebGadget(#WebGadget, 10, 40, 780, 750, "www.purebasic.com")
ButtonGadget(#Button, 10, 10, 60, 20, "Print")
; The IWebBrowser2 Interface is now defined in a .res file (with about 2000 others),
; so there's no definition work for us to do :)
; Fred the genius stored the Interface pointer to IWebBrowser2 in the DATA
; member of the windowstructure of the WebGadget containerwindow, so we can get
; that easily:
WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(#WebGadget), #GWL_USERDATA)
Repeat
Event = WaitWindowEvent()
If Event = #PB_EventGadget And EventGadgetID() = #Button
; Send the Print Command to the WebGadget:
WebObject\ExecWB(#OLECMDID_PRINT, #OLECMDEXECOPT_PROMPTUSER, 0, 0)
; using #OLECMDEXECOPT_DONTPROMPTUSER as second argument will print without
; the printrequester.
EndIf
Until Event = #PB_EventCLoseWindow
Endquidquid Latine dictum sit altum videtur
I'm trying to POST something, wait for the result and then save the page to a file so I can read it back into my app. My thought is to use ExecWB to #OLECMDID_SAVEAS, but I need to specify the filename in the pvaIn (3rd) argument to ExecWB() but that's a pointer to "VARIANT of type VT_BSTR". How can I see what that type looks like so I can make it play nice with PB?
Are all the members in IWebBrowser2 supported through PB? I'm especially interested in the Busy member, so I can tell when the page has finished loading. If the Busy member is supported it takes an argument of a pointer to type VARIANT_BOOL, is that var type defined in the resident(s) file(s) anywhere?
I know all this sounds like a dirty hack (and it is).. It seems like this is my only option that doesn't require almost 2 megs of libs to go with this application (libcurl +openssl)..
Thanks!
Are all the members in IWebBrowser2 supported through PB? I'm especially interested in the Busy member, so I can tell when the page has finished loading. If the Busy member is supported it takes an argument of a pointer to type VARIANT_BOOL, is that var type defined in the resident(s) file(s) anywhere?
I know all this sounds like a dirty hack (and it is).. It seems like this is my only option that doesn't require almost 2 megs of libs to go with this application (libcurl +openssl)..
Thanks!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Yes, everything in this Interface should work.
VARIANT_BOOL is just a long variable, that can hold $FFFF (true) or 0 (false)
As everything <> 0 is true in PB, it works just as a normal BOOL.
Example:
Timo
VARIANT_BOOL is just a long variable, that can hold $FFFF (true) or 0 (false)
As everything <> 0 is true in PB, it works just as a normal BOOL.
Example:
Code: Select all
If OpenWindow(0, 0, 0, 600, 600, #PB_Window_Screencentered|#PB_Window_SystemMenu, "WebBRowser")
If CreateGadgetList(WindowID())
WebGadget(0, 10, 10, 580, 555, "http://www.purebasic.com")
WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(0), #GWL_USERDATA)
TextGadget(1, 10, 570, 100, 20, "", #PB_Text_Border)
Repeat
Event = WindowEvent()
WebObject\get_Busy(@IsBusy.l)
If IsBusy
SetGadgetText(1, "busy!")
Else
SetGadgetText(1, "not busy")
EndIf
If Event = 0
Delay(1)
EndIf
Until Event = #PB_EventCloseWindow
EndIf
EndIfquidquid Latine dictum sit altum videtur
Ok, about the SaveAs...
I've made some code that *should* work, but it keeps crashing, anybody
else has an idea?
Did I mention, i hate that VARIANT sh*t ??
Timo
I've made some code that *should* work, but it keeps crashing, anybody
else has an idea?
Code: Select all
; Constants for the ExecWB() method of IWebBrowser2
Enumeration 1
#OLECMDID_OPEN
#OLECMDID_NEW
#OLECMDID_SAVE
#OLECMDID_SAVEAS
#OLECMDID_SAVECOPYAS
#OLECMDID_PRINT
#OLECMDID_PRINTPREVIEW
#OLECMDID_PAGESETUP
#OLECMDID_SPELL
#OLECMDID_PROPERTIES
#OLECMDID_CUT
#OLECMDID_COPY
#OLECMDID_PASTE
#OLECMDID_PASTESPECIAL
#OLECMDID_UNDO
#OLECMDID_REDO
#OLECMDID_SELECTALL
#OLECMDID_CLEARSELECTION
#OLECMDID_ZOOM
#OLECMDID_GETZOOMRANGE
#OLECMDID_UPDATECOMMANDS
#OLECMDID_REFRESH
#OLECMDID_STOP
#OLECMDID_HIDETOOLBARS
#OLECMDID_SETPROGRESSMAX
#OLECMDID_SETPROGRESSPOS
#OLECMDID_SETPROGRESSTEXT
#OLECMDID_SETTITLE
#OLECMDID_SETDOWNLOADSTATE
#OLECMDID_STOPDOWNLOAD
EndEnumeration
Enumeration 0
#OLECMDEXECOPT_DODEFAULT
#OLECMDEXECOPT_PROMPTUSER
#OLECMDEXECOPT_DONTPROMPTUSER
#OLECMDEXECOPT_SHOWHELP
EndEnumeration
; Variant stuff
Enumeration
#VT_EMPTY = 0
#VT_NULL = 1
#VT_I2 = 2
#VT_I4 = 3
#VT_R4 = 4
#VT_R8 = 5
#VT_CY = 6
#VT_DATE = 7
#VT_BSTR = 8
#VT_DISPATCH = 9
#VT_ERROR = 10
#VT_BOOL = 11
#VT_VARIANT = 12
#VT_UNKNOWN = 13
#VT_DECIMAL = 14
#VT_I1 = 16
#VT_UI1 = 17
#VT_UI2 = 18
#VT_UI4 = 19
#VT_I8 = 20
#VT_UI8 = 21
#VT_INT = 22
#VT_UINT = 23
#VT_VOID = 24
#VT_HRESULT = 25
#VT_PTR = 26
#VT_SAFEARRAY = 27
#VT_CARRAY = 28
#VT_USERDEFINED = 29
#VT_LPSTR = 30
#VT_LPWSTR = 31
#VT_RECORD = 36
#VT_FILETIME = 64
#VT_BLOB = 65
#VT_STREAM = 66
#VT_STORAGE = 67
#VT_STREAMED_OBJECT = 68
#VT_STORED_OBJECT = 69
#VT_BLOB_OBJECT = 70
#VT_CF = 71
#VT_CLSID = 72
#VT_BSTR_BLOB = $0fff
#VT_VECTOR = $1000
#VT_ARRAY = $2000
#VT_BYREF = $4000
#VT_RESERVED = $8000
#VT_ILLEGAL = $ffff
#VT_ILLEGALMASKED = $0fff
#VT_TYPEMASK = $0fff
EndEnumeration
Structure BRECORD
*pvRecord.l
*pRecInfo.IRecordInfo
EndStructure
Structure VARIANT
vt.l
wReserved1.w
wReserved2.w
wReserved3.w
StructureUnion
llVal.LARGE_INTEGER
lVal.l
bVal.b
iVal.b
fltVal.f
dblVal.LARGE_INTEGER
boolVal.l
bool.l
scode.l
cyVal.l
date.l
bstrVal.l
*punkVal.IUnknown
*pdispVal.IDispatch
*parray.l
*pbVal.b
*piVal.b
*plVal.l
*pllVal.LARGE_INTEGER
*pfltVal.f
*pdblVal.LARGE_INTEGER
*pboolVal.l
*pbool.l
*pscode.l
*pcyVal.l
*pdate.l
*pbstrVal.b
*ppunkVal.IUnknown
*ppdispVal.IDispatch
*pparray.l
*pvarVal.VARIANT
*byref
cVal.b
uiVal.b
ulVal.l
ullVal.LARGE_INTEGER
intVal.l
uintVal.l
*pdecVal.f
*pcVal.b
*puiVal.b
*pulVal.l
*pullVal.LARGE_INTEGER
*pintVal.l
*puintVal.l
record.BRECORD
EndStructureUnion
decVal.f
EndStructure
If OpenWindow(0, 0, 0, 600, 600, #PB_Window_Screencentered|#PB_Window_SystemMenu, "WebBRowser")
If CreateGadgetList(WindowID())
WebGadget(0, 10, 10, 580, 555, "http://www.purebasic.com")
WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(0), #GWL_USERDATA)
ButtonGadget(1, 10, 570, 100, 20, "Save as:")
StringGadget(2, 120, 570, 300, 20, "C:\Test.html")
Repeat
Event = WaitWindowEvent()
If Event = #PB_EventGadget And EventGadgetID() = 1
filename$ = GetGadgetText(2)
; convert to unicode
filename_Unicode = AllocateMemory(0, Len(filename$)*2+2)
MultiByteToWideChar_(#CP_ACP, 0, @filename$, -1, filename_Unicode, Len(filename$)*2+2)
; create bstr
filename_BSTR = SysAllocString_(filename_Unicode)
; fill variant
VariantIn.VARIANT
VariantIn\vt = #VT_BSTR
VariantIn\bstrVal = filename_BSTR
If WebObject\ExecWB(#OLECMDID_SAVEAS, #OLECMDEXECOPT_DONTPROMPTUSER, @VariantIn, 0) = #S_OK
MessageRequester("","Saved successfully")
Else
MessageRequester("","could not save file")
EndIf
FreeMemory(0)
SysFreeString_(filename_BSTR)
EndIf
Until Event = #PB_EventCloseWindow
EndIf
EndIfTimo
quidquid Latine dictum sit altum videtur
No wonder! I'm just looking at it and I hate it..
Gotta love that motto of "make things as hard as humanly possible"...
Gotta love that motto of "make things as hard as humanly possible"...
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net




