Code : Tout sélectionner
; voir ici : http://msdn.microsoft.com/en-us/library/ms531073(VS.85).aspx
Declare StringToBStr (string$)
#SIZEOF_WORD=2
Enumeration
#bold
#link
#link_google
#insert_image
#insert_image2
#edit_mode
#web_gadget
#Window
EndEnumeration
Procedure.l Ansi2Uni(string.s) ; Converts normal (Ansi) string To Unicode
*out = AllocateMemory(Len(string)*2 * #SIZEOF_WORD)
MultiByteToWideChar_(#CP_ACP, 0, string, -1, *out, Len(string))
ProcedureReturn *out
EndProcedure
If OpenWindow(#Window, 0, 0, 800, 600, "WebGadget Edit", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
If CreateGadgetList(WindowID(#Window))
WebGadget(#web_gadget, 5, 5, 790, 500, "http://www.purebasic.com/")
ButtonGadget(#bold, 5, 540, 100, 25, "Bold")
ButtonGadget(#link, 110, 540, 100, 25, "Link...")
ButtonGadget(#link_google, 210, 540, 100, 25, "Link google")
ButtonGadget(#insert_image, 310, 540, 100, 25, "Insert image...")
ButtonGadget(#insert_image2, 410, 540, 200, 25, "Insert image ess.jpg (don't work !)")
ButtonGadget(#edit_mode, 210, 510, 100, 25, "Edit mode",#PB_Button_Toggle)
;{initialisation webgadget
; get webgadgets IWebBrowser2 interface:
Browser.IWebBrowser2 = GetWindowLong_(GadgetID(#web_gadget), #GWL_USERDATA)
; wait For page To be loaded..
Repeat
While WindowEvent(): Wend
Delay(1)
Browser\get_Busy(@IsBusy.l)
Until IsBusy = 0
; get the document interface
If Browser\get_Document(@DocumentDispatch.IDispatch) = #S_OK
; query For IHTMLDocument3:
If DocumentDispatch\QueryInterface(?IID_IHTMLDocument2, @Document.IHTMLDocument2) = #S_OK
; here you have a IHTMLDocument2 pointer, can work with it...
Document\put_designMode("Off") ; Turns off Edit Mode
;Document\put_designMode(Ansi2Uni("On")) ; Turns on Edit Mode ;
CmdTarget.IOleCommandTarget
If DocumentDispatch\QueryInterface(?IID_IOleCommandTarget, @CmdTarget.IOleCommandTarget) = #S_OK
;CmdTarget\Exec(?CGID_MSHTML, #IDM_2D_POSITION, #OLECMDEXECOPT_DONTPROMPTUSER, @var, NULL) ;Lets you drag drop items
; CmdTarget\Release()
EndIf
Document\Release()
EndIf
DocumentDispatch\Release()
EndIf
;}
edit=0
Success.VARIANT
Command.VARIANT
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_Gadget ;checks For the events
Select EventGadget() ;Checks For Gadget Events
Case #bold
Command\vt = #VT_BSTR
Command\bstrVal = 0
Document\execCommand("Bold", 0, @Command , @Success)
Case #link
Command\vt = #VT_BSTR
Command\bstrVal = 0
Document\execCommand("CreateLink", 1, @Command , @Success)
Case #link_google
Command\vt = #VT_BSTR
Command\bstrVal = Ansi2Uni("http://www.google.fr")
Document\execCommand("CreateLink", 0, @Command , @Success)
Case #insert_image
Command\vt = #VT_BSTR
Command\bstrVal = 0
Document\execCommand("InsertImage", 1, @Command , @Success)
Case #insert_image2
CallDebugger
Command\vt = #VT_BSTR
; Command\bstrVal = Ansi2Uni("far_breton.jpg")
Command\bstrVal = StringToBStr("D:\PureBasic\dobro\ExemplePerso\internet\far_breton.jpg")
Document\execCommand("insertimage",#False, @Command , @Success)
Case #edit_mode
If edit=1
edit=0
Document\put_designMode("Off")
Else
edit=1
Document\put_designMode("On")
EndIf
EndSelect
EndIf
Until EventID = #PB_Event_CloseWindow
If CmdTarget
CmdTarget\Release()
EndIf
EndIf
EndIf
End
Procedure StringToBStr (string$) ; By Zapman Inspired by Fr34k
Protected Unicode$ = Space(Len(string$)* 2 + 2)
Protected bstr_string.l
PokeS(@Unicode$, string$, -1, #PB_Unicode)
bstr_string = SysAllocString_(@Unicode$)
ProcedureReturn bstr_string
EndProcedure
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_IOleCommandTarget: ; {b722bccb-4e68-101b-a2bc-00aa00404770}
Data.l $B722BCCB
Data.w $4E68, $101B
Data.b $A2, $BC, $00, $AA, $00, $40, $47, $70
CGID_MSHTML: ; { 0xDE4BA900, 0x59CA, 0x11CF, { 0x95, 0x92, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 } }
Data.l $DE4BA900
Data.w $59CA, $11CF
Data.b $95, $92, $44, $45, $53, $54, $00, $00
EndDataSection