Das problem ist, wann das Webgadget wirklich fertig ist mit den Laden der Webseite...
Nur mal schnell zusammengebastelt...
Code: Alles auswählen
;-TOP
CompilerIf #PB_Compiler_Thread = 0
CompilerError "Compiler-Option Threadsafe aktivieren!"
CompilerEndIf
; Constant
Enumeration Window
#Main
EndEnumeration
Enumeration Menu
#Menu
EndEnumeration
Enumeration MenuItems
#MenuStartThread
#MenuExitApplication
EndEnumeration
Enumeration Gadgets
#List
#Browser
EndEnumeration
Enumeration Statusbar
#Status
EndEnumeration
; -----------------------------------------------------------------------------
Enumeration CustomEvent #PB_Event_FirstCustomValue
#MyEventLoadURL
EndEnumeration
Structure udtWork
ThreadID.i
Exit.i
; Daten
List URL.s()
EndStructure
Structure udtSendData
Status.i
Semaphore.i
URL.s
EndStructure
Procedure thWork(*data.udtWork)
Protected SendData.udtSendData
With *data
SendData\Semaphore = CreateSemaphore()
ForEach \URL()
SendData\Status = 0
SendData\URL = \URL()
PostEvent(#MyEventLoadURL, 0, 0, 0, @SendData)
WaitSemaphore(SendData\Semaphore)
;TODO
Delay(5000)
Next
FreeSemaphore(SendData\Semaphore)
EndWith
EndProcedure
Global WorkData.udtWork
Procedure StartThread()
With WorkData
If IsThread(\ThreadID)
ProcedureReturn 0
EndIf
AddElement(\URL()) : \URL() = "http://www.t-online.de"
AddElement(\URL()) : \URL() = "about:blank"
AddElement(\URL()) : \URL() = "http://www.heise.de"
AddElement(\URL()) : \URL() = "http://www.chip.de"
AddElement(\URL()) : \URL() = "http://www.purebasic.com"
\ThreadID = CreateThread(@thWork(), WorkData)
ProcedureReturn 1
EndWith
EndProcedure
; -----------------------------------------------------------------------------
; Global Variable
Global ExitApplication
; Functions
Procedure UpdateWindow()
Protected x, y, dx, dy, menu, status
menu = MenuHeight()
If IsStatusBar(#Status)
status = StatusBarHeight(#Status)
Else
status = 0
EndIf
x = 0
y = 0
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - menu - status
ResizeGadget(#List, x, y, dx, dy)
EndProcedure
; Main
Procedure Main()
Protected event, style, *MyEventData.udtSendData
style = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget
dx = 800
dy = 600
If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, dx, dy, "Main", style)
; Enable Fullscreen
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Protected NewCollectionBehaviour
NewCollectionBehaviour = CocoaMessage(0, WindowID(#Main), "collectionBehavior") | $80
CocoaMessage(0, WindowID(#Main), "setCollectionBehavior:", NewCollectionBehaviour)
CompilerEndIf
; Menu
CreateMenu(#Menu, WindowID(#Main))
MenuTitle("Ablage")
MenuItem(#MenuStartThread, "Start Thread...")
MenuBar()
MenuItem(#MenuExitApplication, "Be&enden")
; Gadgets
ListViewGadget(#List, 0, 0, dx, dy)
WebGadget(#Browser, 0, 0, 0, 0, "about:blank")
; Statusbar
CreateStatusBar(#Status, WindowID(#Main))
AddStatusBarField(#PB_Ignore)
UpdateWindow()
; Main Loop
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Menu
Select EventMenu()
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Case #PB_Menu_About
Case #PB_Menu_Preferences
Case #PB_Menu_Quit
ExitApplication = #True
CompilerEndIf
Case #MenuExitApplication
ExitApplication = #True
Case #MenuStartThread
StartThread()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #List
Case #Browser
Select EventType()
Case #PB_EventType_DownloadStart
AddGadgetItem(#List, -1, "Download Start URL - " + GetGadgetText(#Browser))
Case #PB_EventType_DownloadEnd
AddGadgetItem(#List, -1, "Download End URL - " + GetGadgetText(#Browser))
If *MyEventData
*MyEventData\Status + 1
If *MyEventData\Status = 1
SignalSemaphore(*MyEventData\Semaphore)
EndIf
EndIf
EndSelect
EndSelect
Case #PB_Event_SizeWindow
Select EventWindow()
Case #Main
UpdateWindow()
EndSelect
Case #PB_Event_CloseWindow
Select EventWindow()
Case #Main
ExitApplication = #True
EndSelect
Case #MyEventLoadURL
*MyEventData = EventData()
AddGadgetItem(#List, -1, "Thread Request URL - " + *MyEventData\URL)
SetGadgetText(#Browser, *MyEventData\URL)
EndSelect
Until ExitApplication
EndIf
EndProcedure : Main()
End