Scrolling the WebGadget

Just starting out? Need help? Post your questions and find answers here.
shadowvox
User
User
Posts: 14
Joined: Wed Jul 10, 2019 4:38 pm

Scrolling the WebGadget

Post by shadowvox »

I have a webgadget load a weather map, and a timer is used to wait for it to load.
I have it scroll x 150, works
Then a delay just so I can watch and make sure it's working (will be removed)
Then it scrolls y 250, works, but now the x is back at 0

Code: Select all

;Wait for weather to finish
  If event = #PB_Event_Timer And EventTimer() = 1
    SetGadgetAttribute(WeatherWindow,#PB_Web_ScrollX,150)
    Delay(1000)
    SetGadgetAttribute(WeatherWindow,#PB_Web_ScrollY,250)
    RemoveWindowTimer(0,1)    ;Remove timer as it's no longer needed, or wanted, like your momma
  EndIf

I have reversed x and y, and the last one always sets the other to 0. What am I doing wrong?
Last edited by shadowvox on Wed Jul 24, 2019 10:44 pm, edited 1 time in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 6412
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Scrolling the WebGadget

Post by mk-soft »

Never use delay in an event loop.
This will block the GUI update.

Use AddWindowTimer or AddGadgetTimer (Link)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
shadowvox
User
User
Posts: 14
Joined: Wed Jul 10, 2019 4:38 pm

Re: Scrolling the WebGadget

Post by shadowvox »

Like I said above, I'm only using it to observe the behavior. It will be taken out as soon as I figure out why this is not working. I put it in there trying to figure out why the second scroll is making the first one reset to 0.
So even with the delay out, it's still not acting correctly.
shadowvox
User
User
Posts: 14
Joined: Wed Jul 10, 2019 4:38 pm

Re: Scrolling the WebGadget

Post by shadowvox »

Still unable to get it working properly. Anyone? Beuller?
User avatar
kenmo
Addict
Addict
Posts: 2069
Joined: Tue Dec 23, 2003 3:54 am

Re: Scrolling the WebGadget

Post by kenmo »

Hi. You'll get much better response if you post a working code example.

Looks like a bug to me. X resets Y to 0, and Y resets X to 0.

Somebody probably has a clever API fix though..?

Code: Select all

OpenWindow(0, 0, 0, 480, 480, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(0, 0, 20, 480, 460, "http://en.wikipedia.org")
ButtonGadget(1, 0, 0, 100, 20, "Scroll X 250")
ButtonGadget(2, 100, 0, 100, 20, "Scroll Y 250")
ButtonGadget(3, 200, 0, 100, 20, "Scroll X, Y")
ButtonGadget(4, 300, 0, 100, 20, "Scroll Y, X")

Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget
    Select (EventGadget())
      Case 1
        SetGadgetAttribute(0, #PB_Web_ScrollX, 250) ; resets Y
      Case 2
        SetGadgetAttribute(0, #PB_Web_ScrollY, 250) ; resets X
      Case 3
        SetGadgetAttribute(0, #PB_Web_ScrollX, 250)
        SetGadgetAttribute(0, #PB_Web_ScrollY, 250) ; resets X
      Case 4
        SetGadgetAttribute(0, #PB_Web_ScrollY, 250)
        SetGadgetAttribute(0, #PB_Web_ScrollX, 250) ; resets Y
    EndSelect
  EndIf
Until (Event = #PB_Event_CloseWindow)
shadowvox
User
User
Posts: 14
Joined: Wed Jul 10, 2019 4:38 pm

Re: Scrolling the WebGadget

Post by shadowvox »

kenmo wrote:Hi. You'll get much better response if you post a working code example.

Looks like a bug to me. X resets Y to 0, and Y resets X to 0.

Somebody probably has a clever API fix though..?

Code: Select all

OpenWindow(0, 0, 0, 480, 480, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(0, 0, 20, 480, 460, "http://en.wikipedia.org")
ButtonGadget(1, 0, 0, 100, 20, "Scroll X 250")
ButtonGadget(2, 100, 0, 100, 20, "Scroll Y 250")
ButtonGadget(3, 200, 0, 100, 20, "Scroll X, Y")
ButtonGadget(4, 300, 0, 100, 20, "Scroll Y, X")

Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget
    Select (EventGadget())
      Case 1
        SetGadgetAttribute(0, #PB_Web_ScrollX, 250) ; resets Y
      Case 2
        SetGadgetAttribute(0, #PB_Web_ScrollY, 250) ; resets X
      Case 3
        SetGadgetAttribute(0, #PB_Web_ScrollX, 250)
        SetGadgetAttribute(0, #PB_Web_ScrollY, 250) ; resets X
      Case 4
        SetGadgetAttribute(0, #PB_Web_ScrollY, 250)
        SetGadgetAttribute(0, #PB_Web_ScrollX, 250) ; resets Y
    EndSelect
  EndIf
Until (Event = #PB_Event_CloseWindow)
I did, but forgot to flag it as code, fixed.
Oh great, my first real prject and I find a bug :D
normeus
Enthusiast
Enthusiast
Posts: 485
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Scrolling the WebGadget

Post by normeus »

Using @kenmos sample code and @Freaks code:
(this one scrolls by the number of pixels )

Code: Select all

; Freak from German forum
Enumeration
  #Web_0
  #Window_0
  #String_0
  #Button_0
EndEnumeration
Procedure WebGadget_Scroll(Gadget.l, x.l, y.l)
   Protected Browser.IWebBrowser2
   Protected Window.IHTMLWindow2
   Protected DocumentDispatch.IDispatch
   Protected Document.IHTMLDocument2
 ;  Protected Element.IHTMLElement2
   
   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!
            If x=-1
               window\scrollBY(0,y)
            ElseIf y=-1 
               window\scrollBY(x,0)
               Else
                  Window\ScrollTo(x, y) 
           EndIf
            Window\Release()
         EndIf                   
         Document\Release()
      EndIf         
      DocumentDispatch\Release()
   EndIf
EndIf   
EndProcedure



   
OpenWindow(0, 0, 0, 480, 480, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(0, 0, 20, 480, 460, "http://en.wikipedia.org")
ButtonGadget(1, 0, 0, 100, 20, "Scroll X by 250")
ButtonGadget(2, 100, 0, 100, 20, "Scroll Y by 250")
ButtonGadget(3, 200, 0, 100, 20, "Scroll to 200,200")
ButtonGadget(4, 300, 0, 100, 20, "Scroll to 300,300")

Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget
     Select (EventGadget())

       Case 1
        ;
          WebGadget_Scroll(0, 250, -1) ; resets Y
           Debug "-------1-------"
          Debug GetGadgetAttribute(0, #PB_Web_ScrollY)
          Debug GetGadgetAttribute(0, #PB_Web_ScrollX)
      Case 2

         WebGadget_Scroll(0, -1,250) ; resets X
                 Debug "-------2-------"
          Debug GetGadgetAttribute(0, #PB_Web_ScrollY)
          Debug GetGadgetAttribute(0, #PB_Web_ScrollX)   
      Case 3
       ; SetGadgetAttribute(0, #PB_Web_ScrollX, 250)
       ; SetGadgetAttribute(0, #PB_Web_ScrollY, 250) ; resets X
        WebGadget_Scroll(0,200,200)
                Debug "-------3-------"
          Debug GetGadgetAttribute(0, #PB_Web_ScrollY)
          Debug GetGadgetAttribute(0, #PB_Web_ScrollX)   
     Case 4
        ;SetGadgetAttribute(0, #PB_Web_ScrollY, 250)
        ;SetGadgetAttribute(0, #PB_Web_ScrollX, 250) ; resets Y
          WebGadget_Scroll(0,300,300)
               Debug "-------4-------"
          Debug GetGadgetAttribute(0, #PB_Web_ScrollY)
          Debug GetGadgetAttribute(0, #PB_Web_ScrollX)      
    EndSelect

  EndIf
Until (Event = #PB_Event_CloseWindow)


DataSection
  IID_IHTMLDocument2:
  Data.l $332C4425
  Data.w $26CB, $11D0
  Data.b $B4, $83, $00, $C0, $4F, $D9, $01, $19
  IID_IHTMLElement2:
  Data.l $3050F434
  Data.w $98B5, $11CF
  Data.b $BB, $82, $00, $AA, $00, $BD, $CE, $0B
EndDataSection
or use @RSBasic excellent webgadget
viewtopic.php?p=535740#p535740
also the mighty @JHPJHP has an HTML5 library that works great



Norm
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
shadowvox
User
User
Posts: 14
Joined: Wed Jul 10, 2019 4:38 pm

Re: Scrolling the WebGadget

Post by shadowvox »

normeus wrote:Using @kenmos sample code and @Freaks code:
(this one scrolls by the number of pixels )

Code: Select all

;edited for clarity :)
or use @RSBasic excellent webgadget
viewtopic.php?p=535740#p535740
also the mighty @JHPJHP has an HTML5 library that works great



Norm
Thank you. I will try this when I get back to my PC.
shadowvox
User
User
Posts: 14
Joined: Wed Jul 10, 2019 4:38 pm

Re: Scrolling the WebGadget

Post by shadowvox »

I found a simple way, and it works great.

Code: Select all

Macro Click()
  mouse_event_(#MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
  mouse_event_(#MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
EndMacro
 
; Click at the current location
Click()
 
Delay(1000) ; Wait a second
 
; Move to a new location and click it
SetCursorPos_(50, 50)
Click()
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Scrolling the WebGadget

Post by RSBasic »

@shadowvox
It would work, but it's not recommended. A program should not change or abuse the mouse.
Image
Image
User avatar
kenmo
Addict
Addict
Posts: 2069
Joined: Tue Dec 23, 2003 3:54 am

Re: Scrolling the WebGadget

Post by kenmo »

Yeah, please don't scroll a webgadget by moving the user's cursor and simulating mouse clicks!

Use the proper code in this thread or RASHAD's post:
viewtopic.php?f=12&t=73261
shadowvox
User
User
Posts: 14
Joined: Wed Jul 10, 2019 4:38 pm

Re: Scrolling the WebGadget

Post by shadowvox »

@RSBasic and @kenmo
Message received and understood.
Mouse abuse is real.
Many have not even heard of it.
There could be a mouse in your house being abused.
Please help. Your donation will go a long way to help stop mouse abuse.
This message paid for by the Speedy Gonzales Memorial Foundation.

But no, I get it.
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Scrolling the WebGadget

Post by RSBasic »

:D
Image
Image
Post Reply