Hello,
I've made a little program that changes the desktop wallpaper every hour. The only thing is, I want the code that changes it to be executed on the hour (1:00 PM, 2:00 PM, 3:00 PM). Since WM_TIMERs have a maximum elapse time of 65,535 milliseconds I'm running my function every minute, or 60,000 milliseconds, and checking if the number of minutes returned by GetSystemTime is zero. I can't help thinking that's just a smidge wasteful.
Also, at the beginning of the program, I'm synchronising the timer used with the system clock like so:-
Code:
case WM_CREATE:
{
SYSTEMTIME st;
PostMessage(hwnd, WM_TIMER, 0, 0); // run the function at startup
GetSystemTime(&st);
while (st.wSecond != 0) // Synchronised?
{
GetSystemTime(&st);
Sleep(1000); // Fudge fudge fudge
}
SetTimer(hwnd, TIMER, 60000, NULL);
break;
}
As I've pointed out, the Sleep function is perhaps the worst solution, ever, for this situation as it renders the earlier PostMessage call useless (It holds up the message pump for anything up to a minute). Please God (*cough*) I mean you, Is there a better way?