cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : General C++ Programming : quick timer question
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Articles
Lounge
Jobs

-

post  quick timer question

ftmthy412 (3)
Hey all

I'm writing a simple app that will turn off my computer after a user-defined time has passed. How do I use a timer in C++ (with minutes or hours, not seconds)? Any links to helpful resources are appreciated also.
Thanks lot.
|
SteakRider (110)
If you are using MFC, then use normal settimer,
if you are not using MFC
this code helps you
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* clock example: countdown */                           
#include <stdio.h>
#include <time.h>
#include <windows.h>

void wait ( int seconds )
{
	clock_t endwait;
	endwait = clock () + seconds * CLOCKS_PER_SEC ;
	while (clock() < endwait) {}
}

int main ()
{
	int n;
	printf ("Starting countdown...\n");
	for (n=3; n>0; n--)
	{
		printf ("%d\n",n);
		wait (1);
	}
	printf ("FIRE!!!\n");
	printf ("Shutting down system!!!\n");
/*
	1.EWX_LOGOFF: Logoff the current user.
	2. EWX_RESTART: Simply restart the computer.
	3. EWX_SHUTDOWN: Shut down but 'AT' style.
	4. EWX_POWEROFF: Shut down but 'ATX' style.                                              
*/

	ExitWindowsEx(EWX_POWEROFF,0);


	return 0;
}

| Last edited on

This topic is archived - New replies not allowed.
Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us