/ ************************************************** **************************** MODULE: TIMEDMSGBOX.CPPNOTICES: Copyright (c) 2000 Jeffrey Richter *************** *********************************************************** ******************* /
#include "../../cmnhdr.h" / * see appendix a. * / # include
//
// the caption of ity [] = text ("Timed Message Box");
// How much seconds we'll display the message boxint g_nseft = 0;
// this is static window control id for a message box # define id_msgbox_static_text 0x0000FFFFF
//
Void WinApi MsgboXtimeout (pvoid pvcontext, boolean ftimeout) {
// Note: Due to a thread Race Condition, IT IS Possible (But Very Unlikely) // That The Message Box Will NOT BE CREATED WHEN We get here. Hwnd hwnd = findwindow (NULL, G_SZCAPTION)
IF (hwnd! = null) {// the window does exist; Update the time remaining. Tchar SZ [100]; WSPrintf (SZ, Text ("You Have% D Seconds to Respond"), g_nseft--); setdlgitemText HWND, ID_MSGBOX_STATIC_Text, SZ);
IF (g_nseft == 0) {// The time is up; force the message box to exit. enddialog (hwnd, idok);}} else {
// the window does not exist yet; do noting this time. // We'll try again in another second.}
//
Int WinApi _twinmain (Hinstance Hinstexe, Hinstance, PTSTR PSZCMDLINE, INT) {
// chwindows9xnotallowed ();
// How much seconds we'll give the user to respond g_nseft = 10;
// Create a Multishot 1 Second Timer That Begins Firing After 1 Second. Handle Htimerqtimer; CreateTimerQueuetiMER (& Htimerqtimer, Null, MSGboXtimeout, NULL, 1000, 1000, 0);
// Display the message box MessageBox (NULL, TEXT ( "You have 10 seconds to respond"), g_szCaption, MB_OK); // Cancel the timer & delete the timer queue DeleteTimerQueueTimer (NULL, hTimerQTimer, NULL);
// let us Know if the user responded or if we timed-out. MessageBox (null, (g_nseft == 0): Text ("timeout"): Text ("User Responded", Text ("Result", MB_OK );
Return (0);
END OF FILE /