;Autor: freak ;http://www.purebasic.fr/german/viewtopic.php?p=112747#p112747 EnableExplicit Procedure WebGadget_Document(Gadget, *IID) Protected Document = 0 Protected Browser.IWebBrowser2 Protected DocumentDispatch.IDispatch Browser.IWebBrowser2 = GetWindowLongPtr_(GadgetID(Gadget), #GWL_USERDATA) If Browser If Browser\get_Document(@DocumentDispatch.IDispatch) = #S_OK And DocumentDispatch DocumentDispatch\QueryInterface(*IID, @Document) DocumentDispatch\Release() EndIf EndIf ProcedureReturn Document EndProcedure Procedure.s WebGadget_Selection(Gadget) Protected Result$ = "" Protected Document.IHTMLDocument2 Protected Selection.IHTMLSelectionObject Protected bstr_type Protected TextRange.IDispatch Protected UnicodeText$ Protected pUnicodeText Protected dispid_text Protected params.DISPPARAMS Protected varResult.VARIANT Document.IHTMLDocument2 = WebGadget_Document(Gadget, ?IID_IHTMLDocument2) If Document If Document\get_selection(@Selection.IHTMLSelectionObject) = #S_OK If Selection\get_type(@bstr_type) = #S_OK And bstr_type If LCase(PeekS(bstr_type, -1, #PB_Unicode)) = "text" If Selection\createRange(@TextRange.IDispatch) = #S_OK And TextRange UnicodeText$ = Space(10) PokeS(@UnicodeText$, "text", -1, #PB_Unicode) pUnicodeText = @UnicodeText$ If TextRange\GetIDsOfNames(?IID_NULL, @pUnicodeText, 1, #LOCALE_SYSTEM_DEFAULT, @dispid_text) = #S_OK params.DISPPARAMS\cArgs = 0 params\cNamedArgs = 0 If TextRange\Invoke(dispid_text, ?IID_NULL, #LOCALE_SYSTEM_DEFAULT, #DISPATCH_PROPERTYGET, @params, @varResult.VARIANT, #Null, #Null) = #S_OK If varResult\vt <> #VT_BSTR VariantChangeType_(@varResult, @varResult, 0, #VT_BSTR) EndIf If varResult\vt = #VT_BSTR Result$ = PeekS(varResult\bstrVal, -1, #PB_Unicode) EndIf VariantClear_(@varResult) EndIf EndIf TextRange\Release() EndIf EndIf SysFreeString_(bstr_type) EndIf Selection\Release() EndIf Document\Release() EndIf ProcedureReturn Result$ EndProcedure If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) WebGadget(1, 0, 0, WindowWidth(0), WindowHeight(0)-40, "http://www.purebasic.com") ButtonGadget(2, WindowWidth(0)-210, WindowHeight(0)-30, 200, 20, "Markierten Text ermitteln", 0) Repeat Select WaitWindowEvent() Case #PB_Event_Gadget Select EventGadget() Case 2 Debug WebGadget_Selection(1) EndSelect Case #PB_Event_CloseWindow End EndSelect ForEver EndIf 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_IHTMLDocument3: ; {3050F485-98B5-11CF-BB82-00AA00BDCE0B} Data.l $3050F485 Data.w $98B5, $11CF Data.b $BB, $82, $00, $AA, $00, $BD, $CE, $0B IID_NULL: ; {00000000-0000-0000-0000-000000000000} Data.l $00000000 Data.w $0000, $0000 Data.b $00, $00, $00, $00, $00, $00, $00, $00 EndDataSection ; IDE Options = PureBasic 5.31 (Windows - x64) ; CursorPosition = 2 ; Folding = - ; EnableUnicode ; EnableXP ; EnableUser ; EnableCompileCount = 0 ; EnableBuildCount = 0