Code: Select all
#include <hmg.ch>
Function Main()
private pThID:={}
IF !hb_mtvm()
MSGSTOP("There is no support for multi-threading")
QUIT
ENDIF
DEFINE WINDOW Form_1 AT 100 , 100 WIDTH 550 HEIGHT 380 MAIN
@ 50, 100 BUTTON Button_1 CAPTION "Notifier MT" ACTION CreateThread()
@ 100, 100 BUTTON Button_2 CAPTION "Terminate Thread" ACTION CloseThread()
END WINDOW
Form_1.Activate
Return Nil
PROCEDURE CreateThread
local i:=0
for i:=1 to 5
aadd(pThID,hb_threadStart( @Notifier()))
next
RETURN
Function Notifier( )
LOCAL nHeight, nWidth
LOCAL nLeft, nTop
LOCAL hWnd, aBcolor, nWinRow, nWinCol
LOCAL nTimeIni
LOCAL hWinMain
nHeight := 82
nWidth := 604
nLeft := (GetDesktopWidth() - 5) - nWidth
nTop := (GetDesktopHeight() - 50) - nHeight
nWinRow := nTop
nWinCol := nLeft
nLeft := hb_Random() * ( GetDesktopWidth() - nWidth - 10 )
nTop := hb_Random() * ( GetDesktopHeight() - nHeight - 10 )
DEFINE WINDOW Win_Msg AT nTop, nLeft WIDTH nWidth HEIGHT nHeight ; // TOPMOST
NOMAXIMIZE NOSIZE
DEFINE BUTTON Button_1
ROW 13
COL 200
WIDTH 160
HEIGHT 28
ACTION ( msginfo("OK") )
CAPTION "CLICKED"
END BUTTON
END WINDOW
Win_Msg.Activate
Return Nil
STATIC FUNCTION CloseThread()
LOCAL i
FOR i := 1 TO LEN( pThID )
IF pThID[ i ] <> NIL
hb_threadDetach( pThID[ i ] ) // close thread handle
hb_threadQuitRequest( pThID[ i ] ) // terminate thread
pThID[ i ] := NIL
ENDIF
NEXT
RETURN NIL