Needed to pause some batch files to display messages.
This also works if compiled using PB/CC to display a normal line of text.
Doesn't use MessageBoxTimeoutA which may fail in earlier windows.
'Usage: CALL Sleeper(2000) or Sleeper.exe 2000
Code:
#DIM ALL
#COMPILE EXE 'Sleeper.bas
#INCLUDE "win32api.inc"
FUNCTION PBMAIN AS LONG
Sleeper 2000 'sleeper.exe can be passed a value on the command line
END FUNCTION
FUNCTION Sleeper (milliseconds AS DWORD) AS LONG
LOCAL hThread AS DWORD
IF LEN(COMMAND$) THEN 'override passed value
milliseconds = ABS(VAL(COMMAND$)) 'use value in COMMAND$
END IF
THREAD CREATE TimedMessageBoxThread(milliseconds) TO hThread
SLEEP 50
WaitForSingleObject hThread, milliseconds
THREAD CLOSE hThread TO hThread
END FUNCTION
THREAD FUNCTION TimedMessageBoxThread(BYVAL milliseconds AS DWORD) AS LONG
#IF %DEF(%PB_CC32)
? "Press ENTER to continue or WAIT" + STR$(milliseconds) + " milliseconds"
WAITKEY$
#ELSE
? "Click OK to continue or WAIT" + STR$(milliseconds) + " milliseconds"
#ENDIF
END FUNCTION