SEM ALTERAR fontes originais da HMG Extended
E com recursos limitados
Código: Selecionar todos
#include <hmg.ch>
#include "hbclass.ch"
STATIC pClockThread, pProgThread // hold pointers of threads
STATIC nObject := 0
PROCEDURE Main
LOCAL oMain, oFrame1, oLabel1, oProgbar1, oButton1, oButton2, oButton3
LOCAL oButton31, oButton4, oButton5, oFrame2, oFrame3
WITH OBJECT oMain := WindowClass():New( .T. )
:nCol := 197
:nRow := 437
:nWidth := 550
:nHEIGHT := 350
:cCaption := "Multi threads Sample"
:Create( .T. )
ENDWITH
WITH OBJECT oFrame1 := FrameClass():New()
:nROW := 10
:nCOL := 200
:nWIDTH := 315
:nHEIGHT := 278
:cCAPTION := "Threads"
:Create( oMain )
ENDWITH
WITH OBJECT oLabel1 := LabelClass():New()
:nROW := 60
:nCOL := 290
:nWIDTH := 120
:nHEIGHT := 24
:cCaption := "Clock Here!"
:Create( oMain )
ENDWITH
WITH OBJECT oProgbar1 := ProgbarClass():New()
:nROW := 150
:nCOL := 290
:nWIDTH := 150
:nHEIGHT := 30
:nRANGEMIN := 1
:nRANGEMAX := 10
:Create( oMain )
ENDWITH
WITH OBJECT oButton1 := ButtonClass():New()
:nROW := 10
:nCOL := 10
:nWIDTH := 160
:nHEIGHT := 28
:bACTION := { || main_button_1_action( @pClockThread ) }
:cCAPTION := "Start Clock Thread"
:Create( oMain )
ENDWITH
WITH OBJECT oButton2 := ButtonClass():New()
:nROW := 50
:nCOL := 10
:nWIDTH := 160
:nHEIGHT := 28
:bACTION := { || main_button_2_action( @pProgThread ) }
:cCAPTION := "Start ProgressBar Thread"
:Create( oMain )
ENDWITH
WITH OBJECT oButton3 := ButtonClass():New()
:nROW := 90
:nCOL := 10
:nWIDTH := 160
:nHEIGHT := 28
:bACTION := { || main_button_3_action( @pClockThread, @pProgThread ) }
:cCAPTION := "Stop All Threads"
:Create( oMain )
ENDWITH
WITH OBJECT oButton31 := ButtonClass():New()
:nROW := 130
:nCOL := 10
:nWIDTH := 160
:nHEIGHT := 28
:bACTION := { || main_button_31_action( @pClockThread, @pProgThread ) }
:cCAPTION := "Start All Threads"
:Create( oMain )
ENDWITH
WITH OBJECT oButton4 := ButtonClass():New()
:nROW := 220
:nCOL := 220
:nWIDTH := 260
:nHEIGHT := 28
:bACTION := { || main_button_4_action( pClockThread, pProgThread ) }
:cCAPTION := "Main Thread Button"
:Create( oMain )
ENDWITH
WITH OBJECT oButton5 := ButtonClass():New()
:nROW := 250
:nCOL := 10
:nWIDTH := 160
:nHEIGHT := 28
:bACTION := {|| hb_threadTerminateAll(), DoMethod( "MainWin", "Release") }
:cCAPTION := "Exit (closing all threads)"
:Create( oMain )
ENDWITH
WITH OBJECT oFrame2 := FrameClass():New()
:nROW := 30
:nCOL := 220
:nWIDTH := 272
:nHEIGHT := 75
:cFONTNAME := 'Arial'
:nFONTSIZE := 10
:lFONTBOLD := .T.
:cCAPTION := "Clock Thread - ID:"
:lOPAQUE := .T.
:Create( oMain )
ENDWITH
WITH OBJECT oFrame3 := FrameClass():New()
:nROW := 120
:nCOL := 220
:nWIDTH := 272
:nHEIGHT := 75
:cFONTNAME := 'Arial'
:nFONTSIZE := 10
:lFONTBOLD := .T.
:cCAPTION := "Progressbar Thread - ID:"
:lOPAQUE :=.T.
:Create( oMain )
ENDWITH
END WINDOW
oButton1:Cargo := .F.
oButton2:Cargo := .F.
// ShowThreadsIDs()
oMain:Center()
oMain:Activate()
(oFrame1)
(oLabel1)
(oProgbar1)
(oButton3)
(oButton31)
(oButton4)
(oButton5)
(oFrame2)
(oFrame3)
RETURN
FUNCTION Show_Time( oLabel1 )
// please note that this function will NEVER return the control!
// but do not 'locks' the user interface since it is running in a separate thread
DO WHILE .T.
oLabel1:cCaption := Time()
hb_idleSleep( 0.1 )
ENDDO
RETURN NIL
FUNCTION Show_Progress( oProgbar1)
LOCAL nValue
DO WHILE .T.
nValue := Val(oProgbar1:Caption)
nValue ++
if nValue > 10
nValue := 1
endif
oProgbar1:cCaption := Ltrim(Str(nValue))
hb_idleSleep( 0.2 )
ENDDO
RETURN NIL
PROCEDURE ShowThreadsIDs( oFrame2, oFrame3 )
oFrame2:cCaption := "Clock (Thread pointer: " + hb_ntos( win_P2N( pClockThread ) ) +")"
oFrame3:cCaption := "Progressbar (Thread pointer: " + hb_ntos( win_P2N( pProgThread ) ) +")"
RETURN

