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.

Reply
 
Thread Tools Display Modes
  #1  
Old May 1st, 2009, 03:59 PM
Mike Doty Mike Doty is offline
Member
 
Join Date: Feb 2005
Location: Omaha, Nebraska
Posts: 4,603
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
  #2  
Old May 2nd, 2009, 11:51 AM
Michael Mattias Michael Mattias is offline
Member
 
Join Date: Aug 1998
Location: Racine WI USA
Posts: 26,189
Oops.

Last edited by Michael Mattias; May 2nd, 2009 at 05:42 PM. Reason: I WAS in the wrong thread
Reply With Quote
  #3  
Old May 2nd, 2009, 11:53 AM
Mike Doty Mike Doty is offline
Member
 
Join Date: Feb 2005
Location: Omaha, Nebraska
Posts: 4,603
I think you are in the wrong thread.
Reply With Quote
Reply

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:40 PM.


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