Seite 1 von 1

Kleine Spielerei mit dem Webgadget

Verfasst: 24.09.2008 10:20
von Kiffi
Hallö,

hier mal was völlig sinnfreies (mir war grade danach) ;-)

(folgender Code benötigt COMate von srod)

Code: Alles auswählen

Global myCOMateObject.COMateObject

Procedure Move()
  
  Protected PosX_PX.s
  Protected PosX.l
  
  Protected PosY_PX.s
  Protected Posy.l
  
  Static directionx = 2
  Static directiony = 2
  
  PosX_PX = myCOMateObject\GetStringProperty("document\getElementById('box')\Style\top" )
  PosY_PX = myCOMateObject\GetStringProperty("document\getElementById('box')\Style\left" )
  
  PosX = Val(PosX_PX) ; remove 'px'
  Posy = Val(PosY_PX) ; remove 'px'
  
  If PosX > 150 Or PosX < 50
    directionx * -1
  EndIf
  
  If Posy > 200 Or Posy < 50
    directiony * -1
  EndIf
  
  myCOMateObject\SetProperty("document\getElementById('box')\Style\top = '" + Str(PosX + directionx) + "px'" )
  myCOMateObject\SetProperty("document\getElementById('box')\Style\left = '" + Str(Posy + directiony) + "px'" )
  
EndProcedure

If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  
  WebGadget(0, 10, 10, 580, 280, "")
  
  HTML$="<html><body><div id='box' style='width:100px; height:100px; top:100px; left:100px; position: absolute; border:solid 1px black'></div></body></html>"
  
  SetGadgetItemText(0, #PB_Web_HtmlCode, HTML$)
  
  Repeat
    Delay(10)
  Until GetGadgetAttribute(0, #PB_Web_Busy) = 0
  
  myCOMateObject = COMate_WrapCOMObject(GetWindowLong_(GadgetID(0), #GWL_USERDATA))
  
  SetTimer_(WindowID(0), 1, 20, @Move()) 
  
  Repeat 
    WWE = WaitWindowEvent()
  Until WWE = #PB_Event_CloseWindow
  
  myCOMateObject\Release()
  
EndIf
Bahn frei für das erste Webgadget-Pong! :-)

Grüße ... Kiffi