Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DWORD to _int64?

Status
Not open for further replies.

Bones3

Programmer
Jul 27, 2003
151
US
First of all, hello everyone again.

I am making a win32 MFC console program that is supposed to use a timer. (kind of like an alarm clock) The constructor in my CTimer class currently goes like this:

CTimer::CTimer(_int64 days, _int64 hours, _int64 minutes, _int64 seconds)
{
seconds = seconds * 1000;
minutes = minutes * 60000;
hours = hours * 3600000;
days = days * 86400000;
designatedTime = days + hours + minutes + seconds;
DWORD designatedPeriod;
cout << &quot;\n\nPlease enter this number: &quot; << designatedTime << &quot;: &quot;;
cin >> designatedPeriod;
cout << &quot;\nSleeping for the designated amount of time...&quot;;
::Sleep(designatedPeriod);
::Beep(2000,20000);
}


My goal is to be able to get rid of the ridiculous part where the user has to enter the milliseconds in, after all, what is the efficiency of that? In summary, if there is a way to convert a _int64 to a DWORD, how; and if not what would be a better way of going about this.

-Bones
 
1) Can't you pass in a timestring in the constructor ?
2) Just multiply the user value by 1000 to convert it to miliseconds, so that the user can work in seconds ?

What do you do if the user wants 10 hours, 15 minutes and 8 seconds? does he have to work it all into miliseconds first ?

K
 
Well the point was not to have any iostream in the constructor. I just put it there so it would do something when I compiled it. The way I wanted it to work, the user just enters the values in main() and all I have to do is create a CTimer object and it does it. This is the main funciton:

int main()
{
_int64 Days, Hours, Minutes, Seconds;

cout << &quot;********** Bones' Timer **********\n\n&quot;;
cout << &quot;Enter Days in timer: &quot;;
cin >> Days;
cout << &quot;Enter Hours in timer: &quot;;
cin >> Hours;
cout << &quot;Enter Minutes in timer: &quot;;
cin >> Minutes;
cout << &quot;Enter Seconds in timer: &quot;;
cin >> Seconds;

CTimer myTimer(Days, Hours, Minutes, Seconds);

cout << &quot;\n\n\n\n&quot;;

return 0;
}


So really I guess another way to ask my question would be, &quot;How can I ::Sleep() the program since I am using _int64 and it requires DWORD; or sould I look at this a whole different way?&quot; I guess I'm just not being creative enough, but it does make a good forum discussion in my opinion.

-Bones
 
can you not make days, hours, minutes and seconds DWORDS from the outset ?

K
 
Wow I was under the impression DWORD's couldn't use mathematic operators! Now I feel stupid lol. If I was smart I would have looked in the glossery and would have seen:

DWORD
The Win32 API designation for a 32-bit integer.

I guess it would be really dumb to make the ::Sleep function to use something that couldn't use the mathematic operators. Thanks Kalisto now back to my learning...

-Bones
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top