Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Timed MsgBox with option to continue in PbWin or PB/CC

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Timed MsgBox with option to continue in PbWin or PB/CC

    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
    Last edited by Mike Doty; 1 May 2009, 03:50 PM.

  • #2
    Oops.
    Last edited by Michael Mattias; 2 May 2009, 04:42 PM. Reason: I WAS in the wrong thread
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      I think you are in the wrong thread.

      Comment

      Working...
      X