Set Focus On WebGadget
Posted: Sat Sep 30, 2006 12:49 pm
Hi there! 
I got a problem with the WebGadget. As the title of this thread says I want to put the focus on a WebGadget when the gadget is created or a specific event has happend. Unfortunately the SetActiveGadget() function doesn't work with the WebGadget. So I did some research in the German and English board and found some code that shows how you can deal with the WebGadget using interfaces.
I used a code snippet that shows how to scroll in a WebGadget and changed it a bit to get a procedure with which I can put the focus on the WebGadget:
This code works perfectly ... under PureBasic 3.94. But it does not on the new version 4.00. Unfortunately I really need it to work under the latter version. Does anyone have a clue were the problem is? Is it a bug of PB 4 or do have to change something to get it working under PB4?
Would be great if anyone could help me because I really need this SetFocus stuff for a WebGadget!
Thanks in advance,
Christian

I got a problem with the WebGadget. As the title of this thread says I want to put the focus on a WebGadget when the gadget is created or a specific event has happend. Unfortunately the SetActiveGadget() function doesn't work with the WebGadget. So I did some research in the German and English board and found some code that shows how you can deal with the WebGadget using interfaces.
I used a code snippet that shows how to scroll in a WebGadget and changed it a bit to get a procedure with which I can put the focus on the WebGadget:
Code: Select all
DataSection
IID_IHTMLElement: ; {3050F1FF-98B5-11CF-BB82-00AA00BDCE0B}
Data.l $3050F1FF
Data.w $98B5, $11CF
Data.b $BB, $82, $00, $AA, $00, $BD, $CE, $0B
IID_IHTMLDocument2: ; {332C4425-26CB-11D0-B483-00C04FD90119}
Data.l $332C4425
Data.w $26CB, $11D0
Data.b $B4, $83, $00, $C0, $4F, $D9, $01, $19
EndDataSection
;- Webgadget Functions
Procedure ScrollWebGadget(Gadget.l, x.l, y.l)
Browser.IWebBrowser2 = GetWindowLong_(GadgetID(Gadget), #GWL_USERDATA)
If Browser
If Browser\get_document(@DocumentDispatch.IDispatch) = #S_OK
If DocumentDispatch\QueryInterface(?IID_IHTMLDocument2, @Document.IHTMLDocument2) = #S_OK
If Document\get_parentWindow(@window.IHTMLWindow2) = #S_OK
While WindowEvent(): Wend ; wichtig!
window\scrollTo(x, y)
window\Release()
EndIf
Document\Release()
EndIf
DocumentDispatch\Release()
EndIf
EndIf
EndProcedure
Procedure SetActiveWebGadget(Gadget.l)
Browser.IWebBrowser2 = GetWindowLong_(GadgetID(Gadget), #GWL_USERDATA)
If Browser
If Browser\get_document(@DocumentDispatch.IDispatch) = #S_OK
If DocumentDispatch\QueryInterface(?IID_IHTMLDocument2, @Document.IHTMLDocument2) = #S_OK
If Document\get_parentWindow(@window.IHTMLWindow2) = #S_OK
While WindowEvent(): Wend ; wichtig!
window\focus()
window\Release()
EndIf
Document\Release()
EndIf
DocumentDispatch\Release()
EndIf
EndIf
EndProcedure
#WebGadget = 0
#ButtonGadget = 1
If OpenWindow(0, 0, 0, 800, 600,"WebGadget example", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(0))
WebGadget(#WebGadget, 0, 0, 800, 600-25, "http://www.purebasic.fr/german/viewtopic.php?p=113667&sid=e5f3d3139620333841d907a61837e211#113667")
ScrollWebGadget(#WebGadget, 0, 250)
SetActiveWebGadget(#WebGadget)
Repeat
WindowEvent = WaitWindowEvent()
Until WindowEvent = #PB_Event_CloseWindow
EndIf
EndIf
Would be great if anyone could help me because I really need this SetFocus stuff for a WebGadget!
Thanks in advance,
Christian