Then maybe my Vista computer is too slow.
But now the problem I promised yesterday.
I made a small program that shows a clock running in background using CreateThread(). When you start the program all is going fine. But when you click on the menu File/Mayan Date Countdown it will open a new window with his own CreateThread() counting down the number of seconds until 21st December 2012, the famous "End of the Mayan Era". I had to add a KillThread() in the main window, otherwise the countdown window won't work. My goal is of course that both windows are running (clock & countdown) as BACKGROUND operation.
Either I don't know how to do that, or there is probably a conflict between the StartDrawing() of both operations.
I tried to keep the code as small as simple as possible.
Code: Select all
Declare zMayanDateCountDown(*Interval)
;StartEnumeration
Enumeration
#Font_1
#Image_1
#Image_2
#Image_11
#Image_12
#Gad_Image_1
#Gad_Image_11
EndEnumeration
;EndEnumeration
Procedure zMaya(ParentWin)
DisableWindow(ParentWin, 1)
Win1=OpenWindow(#PB_Any,0,0,400,300,"Mayan Date Countdown",#PB_Window_SystemMenu,WindowID(ParentWin))
h = LoadImage(#Image_11, #PB_Compiler_Home+"Examples\Sources\Data\terrain_texture.jpg")
ImageGadget(#Gad_Image_11, 0, 0, 400, 300, h)
DisableGadget( #Gad_Image_11, 1 )
CreateImage(#Image_12, 400,300)
Thread1 = CreateThread(@zMayanDateCountDown(), 50)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
ExitEventLoop = #True
;EndCase
EndSelect
Until ExitEventLoop
KillThread(Thread1) ; this line is okay since we leave the window
CloseWindow(Win1)
DisableWindow(ParentWin, 0)
EndProcedure
Procedure zClockText(Text.s)
StartDrawing(ImageOutput(#Image_2))
DrawImage(ImageID(#Image_1), 0, 0)
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(#Font_1))
DrawText(150, 400, Text, $000000)
DrawText(147, 397, Text, $0000FF)
StopDrawing()
SetGadgetState(#Gad_Image_1, ImageID(#Image_2))
EndProcedure
Procedure zMayanText(Text.s)
StartDrawing(ImageOutput(#Image_12))
DrawImage(ImageID(#Image_11), 0, 0)
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(#Font_1))
DrawText(50, 120, Text, $000000)
DrawText(47, 117, Text, $0000FF)
StopDrawing()
SetGadgetState(#Gad_Image_11, ImageID(#Image_12))
EndProcedure
Procedure zMayanDateCountDown(*Interval)
Repeat
Maya=Date(2012,12,21,0,0,0) ; Mayan Date assumed to be 21st Dec 2010, Time unknown, so midnight is assumed
Today=Date()
Remaining=Maya-Today
zMayanText(Str(Remaining))
Delay(*Interval)
ForEver
EndProcedure
Procedure zClock(*Interval)
Repeat
zClockText(FormatDate("%yyyy-%mm-%dd %hh:%ii:%ss",Date()))
Delay(*Interval)
ForEver
EndProcedure
;StartProgram -------------------------------------------------------------------------------------------------------------------
LoadFont(#Font_1,"Arial",50, #PB_Font_Bold)
UseJPEGImageDecoder()
Win = OpenWindow(#PB_Any, 0, 0, 1024, 600, "Applications", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
h = LoadImage(#Image_1, #PB_Compiler_Home+"Examples\Sources\Data\terrain_texture.jpg")
ImageGadget(#Gad_Image_1, 0, 0, 1024, 600, h)
DisableGadget( #Gad_Image_1, 1 )
CreateImage(#Image_2, 1024, 600)
BodyMenu = CreateMenu(#PB_Any, WindowID(Win))
MenuTitle("File")
MenuItem(0001, "Mayan Date Countdown")
Thread = CreateThread(@zClock(), 50)
;EndProgram
;StartEventLoop ----------------------------------------------------------------------------------------------------------------------
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
ExitEventLoop = #True
Case #PB_Event_Menu
Select EventMenu()
Case 0001
KillThread(Thread) ;this line should not be there............ but it avoids conflicts... Solution???
; and due to the killthread, you cannot request it a second time
zMaya(Win)
;EndCase
EndSelect
;EndCase
EndSelect
Until ExitEventLoop
;EndEventLoop