// time.cpp // This program pops up a message box with amount of time that // windows has been running. It has no window of its own, so the box // just pops up from the desktop. #define WIN32_LEAN_AND_MEAN // no MFC #include #include #include int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { char str[200] = {0}; int time = (int)GetTickCount(); int days = (time / 1000 / 60 / 60 / 24); int hours = (time /1000 / 60 / 60) - (days*24); int minutes = (time / 1000 / 60) - (days*24*60) - (hours*60); int seconds = (time / 1000) - (days*24*60*60) - (hours*60*60) - (minutes*60); int milliseconds = time - (days*24*60*60*1000) - (hours*60*60*1000) - (minutes*60*1000) - (seconds*1000); sprintf( str, "Your computer has been on for: \n %d days,\n %d hours,\n %d minutes,\n %d seconds,\n %d milliseconds", days, hours, minutes, seconds, milliseconds); MessageBox(NULL, str, "Time", MB_OK | MB_ICONINFORMATION); return 0; } // end WinMain // end time.cpp