WebGadget() Put & Get Scroll Position [Windows]

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4661
Joined: Sun Apr 12, 2009 6:27 am

WebGadget() Put & Get Scroll Position [Windows]

Post by RASHAD »

Hi all
#1 :

Code: Select all

Procedure PutScrollX(Gadget,ScrollX)
  Protected Result,Browser.IWebBrowser2 , DocumentDispatch.IDispatch
  Protected Document.IHTMLDocument3,  DocElement.IHTMLElement ,Element.IHTMLElement2
  
  Browser.IWebBrowser2 = GetWindowLongPtr_(GadgetID(Gadget), #GWL_USERDATA)
  If Browser
    If Browser\get_Document(@DocumentDispatch) = #S_OK And DocumentDispatch
      If DocumentDispatch\QueryInterface(?IID_IHTMLDocument3, @Document) = #S_OK And Document
        If Document\get_documentElement(@DocElement) = #S_OK And DocElement
          If docElement\QueryInterface(?IID_IHTMLElement2, @Element) = #S_OK And Element
            Result = ScrollX
            If Element\put_scrollLeft(Result) <> #S_OK
              Result = 0
            EndIf
            Element\Release()
          EndIf
          DocElement\Release()
        EndIf
        Document\Release()
      EndIf
      DocumentDispatch\Release()
    EndIf
  EndIf

  ProcedureReturn Result
EndProcedure

Procedure GetScrollX(Gadget)
  Protected Result , Browser.IWebBrowser2 , DocumentDispatch.IDispatch
  Protected Document.IHTMLDocument3,  DocElement.IHTMLElement ,Element.IHTMLElement2
  
  Browser.IWebBrowser2 = GetWindowLongPtr_(GadgetID(Gadget), #GWL_USERDATA)
  If Browser
    If Browser\get_Document(@DocumentDispatch) = #S_OK And DocumentDispatch
      If DocumentDispatch\QueryInterface(?IID_IHTMLDocument3, @Document) = #S_OK And Document
        If Document\get_documentElement(@DocElement) = #S_OK And DocElement
          If docElement\QueryInterface(?IID_IHTMLElement2, @Element) = #S_OK And Element
            If Element\get_scrollLeft(@Result) <> #S_OK
              Result = 0
            EndIf
            Element\Release()
          EndIf
          DocElement\Release()
        EndIf
        Document\Release()
      EndIf
      DocumentDispatch\Release()
    EndIf
  EndIf

  ProcedureReturn Result
EndProcedure

Procedure PutScrollY(Gadget,ScrollY)
  Protected Result , Browser.IWebBrowser2 , DocumentDispatch.IDispatch
  Protected Document.IHTMLDocument3,  DocElement.IHTMLElement ,Element.IHTMLElement2
  
  Browser.IWebBrowser2 = GetWindowLongPtr_(GadgetID(Gadget), #GWL_USERDATA)
  If Browser
    If Browser\get_Document(@DocumentDispatch) = #S_OK And DocumentDispatch
      If DocumentDispatch\QueryInterface(?IID_IHTMLDocument3, @Document) = #S_OK And Document
        If Document\get_documentElement(@DocElement) = #S_OK And DocElement
          If docElement\QueryInterface(?IID_IHTMLElement2, @Element) = #S_OK And Element
            Result = ScrollY
            If Element\put_scrollTop(Result) <> #S_OK
              Result = 0
            EndIf
            Element\Release()
          EndIf
          DocElement\Release()
        EndIf
        Document\Release()
      EndIf
      DocumentDispatch\Release()
    EndIf
  EndIf

  ProcedureReturn Result
EndProcedure

Procedure GetScrollY(Gadget)
  Protected Result , Browser.IWebBrowser2 , DocumentDispatch.IDispatch
  Protected Document.IHTMLDocument3,  DocElement.IHTMLElement ,Element.IHTMLElement2
  
  Browser.IWebBrowser2 = GetWindowLongPtr_(GadgetID(Gadget), #GWL_USERDATA)
  If Browser
    If Browser\get_Document(@DocumentDispatch) = #S_OK And DocumentDispatch
      If DocumentDispatch\QueryInterface(?IID_IHTMLDocument3, @Document) = #S_OK And Document
        If Document\get_documentElement(@DocElement) = #S_OK And DocElement
          If docElement\QueryInterface(?IID_IHTMLElement2, @Element) = #S_OK And Element
            If Element\get_scrollTop(@Result) <> #S_OK
              Result = 0
            EndIf
            Element\Release()
          EndIf
          DocElement\Release()
        EndIf
        Document\Release()
      EndIf
      DocumentDispatch\Release()
    EndIf
  EndIf

  ProcedureReturn Result
EndProcedure

OpenWindow(0, 0, 0, 600, 400, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(10, 10, 10, 580,345, "http://www.purebasic.com")
ButtonGadget(1,10,365,80,24,"Scroll To")
ButtonGadget(2,100,365,120,24,"Get Scroll Position")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          PutScrollX(10,180)
          PutScrollY(10,100)
            
        Case 2
          Debug GetScrollX(10)
          Debug GetScrollY(10)
      EndSelect
  EndSelect
Until Quit

DataSection
  IID_IHTMLDocument3:
    Data.l $3050F485
    Data.w $98B5,$11CF
    Data.b $BB,$82,$00,$AA,$00,$BD,$CE,$0B    

  IID_IDispatch:
    Data.l $00020400
    Data.w $0000, $0000
    Data.b $C0, $00, $00, $00, $00, $00, $00, $46

  IID_IHTMLElement2:
    Data.l $3050F434
    Data.w $98B5, $11CF
    Data.b $BB, $82, $00, $AA, $00, $BD, $CE, $0B
EndDataSection
#2 :

Code: Select all

Procedure SetScroll(Gadget,Flag,Scroll)
  Protected Result,Browser.IWebBrowser2 , DocumentDispatch.IDispatch
  Protected Document.IHTMLDocument3,  DocElement.IHTMLElement ,Element.IHTMLElement2 
  Browser.IWebBrowser2 = GetWindowLongPtr_(GadgetID(Gadget), #GWL_USERDATA)
  If Browser
    If Browser\get_Document(@DocumentDispatch) = #S_OK And DocumentDispatch
      If DocumentDispatch\QueryInterface(?IID_IHTMLDocument3, @Document) = #S_OK And Document
        If Document\get_documentElement(@DocElement) = #S_OK And DocElement
          If docElement\QueryInterface(?IID_IHTMLElement2, @Element) = #S_OK And Element
            Result = Scroll
            If Flag = 0
              If Element\put_scrollLeft(Result) <> #S_OK
                Result = 0
              EndIf
            ElseIf Flag = 1
              If Element\put_scrollTop(Result) <> #S_OK
                Result = 0
              EndIf
            EndIf
            Element\Release()
          EndIf
          DocElement\Release()
        EndIf
        Document\Release()
      EndIf
      DocumentDispatch\Release()
    EndIf
  EndIf
  ProcedureReturn Result
EndProcedure

Procedure GetScroll(Gadget,Flag)
  Protected Result , Browser.IWebBrowser2 , DocumentDispatch.IDispatch
  Protected Document.IHTMLDocument3,  DocElement.IHTMLElement ,Element.IHTMLElement2 
  Browser.IWebBrowser2 = GetWindowLongPtr_(GadgetID(Gadget), #GWL_USERDATA)
  If Browser
    If Browser\get_Document(@DocumentDispatch) = #S_OK And DocumentDispatch
      If DocumentDispatch\QueryInterface(?IID_IHTMLDocument3, @Document) = #S_OK And Document
        If Document\get_documentElement(@DocElement) = #S_OK And DocElement
          If docElement\QueryInterface(?IID_IHTMLElement2, @Element) = #S_OK And Element
            If Flag = 0
              If Element\get_scrollLeft(@Result) <> #S_OK
                Result = 0
              EndIf
            ElseIf Flag = 1
              If Element\get_scrolltop(@Result) <> #S_OK
                Result = 0
              EndIf
            EndIf
            Element\Release()
          EndIf
          DocElement\Release()
        EndIf
        Document\Release()
      EndIf
      DocumentDispatch\Release()
    EndIf
  EndIf

  ProcedureReturn Result
EndProcedure

OpenWindow(0, 0, 0, 600, 400, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(10, 10, 10, 580,345, "http://www.purebasic.com")
ButtonGadget(1,10,365,80,24,"Scroll To")
ButtonGadget(2,100,365,120,24,"Get Scroll Position")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
     
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          SetScroll(10,0,180)     ;Scroll(Gadget,Flag,Value) Flag = 0 for X , 1 for Y
          SetScroll(10,1,100)
           
        Case 2
          Debug GetScroll(10,0)    ;GetScroll(Gadget,Flag) Flag = 0 for X 1 for Y
          Debug GetScroll(10,1)
      EndSelect
  EndSelect
Until Quit

DataSection
  IID_IHTMLDocument3:
    Data.l $3050F485
    Data.w $98B5,$11CF
    Data.b $BB,$82,$00,$AA,$00,$BD,$CE,$0B   

  IID_IDispatch:
    Data.l $00020400
    Data.w $0000, $0000
    Data.b $C0, $00, $00, $00, $00, $00, $00, $46

  IID_IHTMLElement2:
    Data.l $3050F434
    Data.w $98B5, $11CF
    Data.b $BB, $82, $00, $AA, $00, $BD, $CE, $0B
EndDataSection
Egypt my love
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: WebGadget() Put & Get Scroll Position [Windows]

Post by Kwai chang caine »

Hello RASHAD, works perfectly here !!
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
Post Reply