PowerBASIC Peer Support Forums
 

Go Back   PowerBASIC Peer Support Forums > User to user Discussions > Source Code

Notices

Source Code PowerBASIC and related source code. Please do not post questions or discussions, just source code.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old May 1st, 2009, 03:59 PM
Mike Doty Mike Doty is online now
Member
 
Join Date: Feb 2005
Location: Omaha, Nebraska
Posts: 4,719
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; May 1st, 2009 at 04:50 PM.
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:26 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright © 1999-2010 PowerBASIC, Inc. All Rights Reserved.