Okay, sorry for my stupidness. I forgot that
1: In C++ you can't append numbers onto strings with the + operator. *shakes fist at Java* I stole the code from the C++ FAQ Lite to convert the DWORD into a string (which uses string streams as Paradigm Shifter suggested).
2: How to split up the miliseconds into hours, minutes and seconds! I still can't remember how to do it with %, so I used another less efficient method.
Anyway, so I finally got it done (which took far more time than it should have) and the following code spits out how long you've been running windows.
#include <windows.h>#include <string>#include <sstream>//eww global variablesHINSTANCE hInst;HWND wndHandle;//window size and stuffconst int windowWidth = 1024;const int windowHeight = 768;//function forward declarationsbool initWindow(HINSTANCE hInstance);LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//-------------------------------------------------------------------------------// WINMAIN()//-------------------------------------------------------------------------------int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){ //initialize window if(!initWindow(hInstance)) return false; //main message loop MSG msg; ZeroMemory(&msg, sizeof(msg)); while(msg.message != WM_QUIT) { //check message queue if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE )) { TranslateMessage(&msg); DispatchMessage(&msg); } else { } //get number of miliseconds windows has been running for DWORD time = GetTickCount(); int hours = time / 3600000; time -= hours * 3600000; int minutes = time / 60000; time -= minutes * 60000; int seconds = time / 1000; std::ostringstream o1, o2, o3; o1 << hours; o2 << minutes; o3 << seconds; std::string theMessage = "Windows has been running for: " + o1.str() + " hours, " + o2.str() + " minutes, " + o3.str() + " seconds."; MessageBox(NULL, theMessage.c_str(), "Time Windows has been on", MB_OK); msg.message = WM_QUIT; } return (int)msg.wParam;}//----------------------------------------------------------------------------// InitWindow()//----------------------------------------------------------------------------bool initWindow(HINSTANCE hInstance){ WNDCLASSEX wcex; //create window properties structure wcex.cbSize = sizeof(WNDCLASSEX); //size of window wcex.style = CS_HREDRAW | CS_VREDRAW; //window graphic style wcex.lpfnWndProc = (WNDPROC)WndProc; //"window procedure callback" wcex.cbClsExtra = 0; //extra unused bytes wcex.cbWndExtra = 0; //extra unused bytes wcex.hInstance = hInstance; //handle to application instance wcex.hIcon = 0; //application icon wcex.hCursor = LoadCursor(NULL, IDC_ARROW); //application cursor wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); //background color wcex.lpszMenuName = NULL; //window menu name wcex.lpszClassName = "Windows Time Running"; //window class name wcex.hIconSm = 0; //"small handle" icon //registers window property class with Windows RegisterClassEx(&wcex); //create window wndHandle = CreateWindow( "Windows Time Running", //name of window class using "Windows Time Running Title", //name of title bar WS_OVERLAPPEDWINDOW, //window graphic style /* WS_OVERLAPPEDWINDOW is a standard window */ CW_USEDEFAULT, //window x coordinate CW_USEDEFAULT, //window y coordinate windowWidth, //window width windowHeight, //window height NULL, //"parent window" (NULL means desktop) NULL, //menu name hInstance, //application instance NULL); //value passed to window (unused) //verify window has been created if(!wndHandle) return false; //display window on screen //ShowWindow(wndHandle, SW_SHOW); UpdateWindow(wndHandle); return true;}//----------------------------------------------------------------------------// WNDPROC()//----------------------------------------------------------------------------LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ //check queue for messages switch(message) { case WM_DESTROY: //destroy window PostQuitMessage(0); break; } //return message to default window for further processing return DefWindowProc(hWnd, message, wParam, lParam);}
hplus0603: I'm not using the timer for a game or anything so the 10 milisecond inaccuracy doesn't really matter :]