Webgadget - obtaining page's DocType with API
Posted: Sat Jan 10, 2009 5:13 am
According to this MSDN page, the DocType can be obtained using IHTMLDocument5.
But I'm having trouble getting it to work as there are no examples of using IHTMLDocument5 on the forum and I'm frankly a bit thick with this stuff. If somebody could help, I'd be very grateful!
As you can see I have no idea how to get IHTMLDocument5 to work. I can only apologise for my incompetence!
But I'm having trouble getting it to work as there are no examples of using IHTMLDocument5 on the forum and I'm frankly a bit thick with this stuff. If somebody could help, I'd be very grateful!
Code: Select all
DataSection
IID_IHTMLDocument2: ; {332C4425-26CB-11D0-B483-00C04FD90119}
Data.l $332C4425
Data.w $26CB, $11D0
Data.b $B4, $83, $00, $C0, $4F, $D9, $01, $19
IID_IHTMLDocument4: ; {3050F69A-98B5-11CF-BB82-00AA00BDCE0B}
Data.l $3050F69A
Data.w $98B5, $11CF
Data.b $BB, $82, $00, $AA, $00, $BD, $CE, $0B
IID_IHTMLDocument5: ; {3050F80C-98B5-11CF-BB82-00AA00BDCE0B}
Data.l $3050F80C
Data.w $98B5, $11CF
Data.b $BB, $82, $00, $AA, $00, $BD, $CE, $0B
EndDataSection
Procedure GetBrowser(g.i) ; By Zapman Inspired by Fr34k
If IsGadget(g)
If GetGadgetText(g) = ""
SetGadgetText(g, "about:blank") ; to avoid error when using Browser
While WindowEvent():Wend
EndIf
Browser.IWebBrowser2 = GetWindowLong_(GadgetID(g), #GWL_USERDATA)
If Browser
Ready = 0
ct = 0
While Ready < 4 And ct<200
WindowEvent()
State = 0
If Browser\get_ReadyState(@BrowserState.i) = #S_OK
If BrowserState = 4
Ready + 1
EndIf
EndIf
If Ready = 0 : Delay(5) : EndIf
ct + 1
Wend
EndIf
ProcedureReturn Browser
EndIf
EndProcedure
Procedure GetDocumentDispatch(g.i) ; By Zapman Inspired by Fr34k
; Example: DocumentDispatch.IDispatch = GetDocumentDispatch(WebGadget)
; Do not forget to release DocumentDispatch when finished to use it
Browser.IWebBrowser2 = GetBrowser(g)
If Browser
If Browser\get_Document(@DocumentDispatch.IDispatch) = #S_OK
ProcedureReturn DocumentDispatch
EndIf
EndIf
EndProcedure
Procedure.s WBGetDocType(g.i)
DocumentDispatch.IDispatch = GetDocumentDispatch(g)
If DocumentDispatch
If DocumentDispatch\QueryInterface(?IID_IHTMLDocument5, @Document.IHTMLDocument5) = #S_OK And Document
Document\get_DocType(@Dom.IHTMLDomNode)
If Dom
;Parent\get_outerHTML(@bstr)
;Parent\Release()
Dom\Release()
EndIf
Document\Release()
EndIf
DocumentDispatch\Release()
EndIf
doctype.s
If bstr
doctype = PeekS(bstr,-1,#PB_Unicode)
SysFreeString_(bstr)
EndIf
ProcedureReturn doctype
EndProcedure
Procedure WaitForWebgadget(gad.l,maxmilliseconds.l)
Browser.IWebBrowser2=GetWindowLong_(GadgetID(gad),#GWL_USERDATA)
milliwait=100
Repeat
While WindowEvent() : Wend : Browser\get_Busy(@busy.l)
count+milliwait
If busy=#VARIANT_TRUE
Sleep_(milliwait)
EndIf
If maxmilliseconds>0
If count=>maxmilliseconds
Break
EndIf
EndIf
Until busy=#VARIANT_FALSE
EndProcedure
win = OpenWindow(#PB_Any,0,0,800,600,"doctype test")
wg = WebGadget(#PB_Any,0,0,800,600,"http://www.purebasic.fr/english/index.php")
WaitForWebgadget(wg,10000)
dt.s = WBGetDocType(wg)
MessageRequester("DocType",dt,0)
End