DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Changewindows Desktop Background Color Every 30 Seconds
Keep the eyes alert during long coding sessions. Compiled and tested with cygwin.
#include "windows.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
// gcc -g -Wall eyesaver.c -o eyesaver
void setcolor () {
int elements[3];
DWORD color[3];
elements[0] = COLOR_DESKTOP;
elements[1] = COLOR_ACTIVECAPTION;
elements[2] = COLOR_SCROLLBAR;
color[0] = RGB (rand () % 0xFF, rand () % 0xFF, rand () % 0xFF);
color[1] = RGB (rand () % 0xFF, rand () % 0xFF, rand () % 0xFF);
color[2] = RGB (rand () % 0xFF, rand () % 0xFF, rand () % 0xFF);
SetSysColors (3, elements, color);
}
void showcolor () {
int color;
color = GetSysColor (COLOR_DESKTOP);
fprintf (stdout, "%X\n", color);
}
int main (int argc, char **argv) {
time_t now;
time(&now);
srand (now);
for (;;) {
setcolor ();
showcolor ();
Sleep (30 * 1000);
}
return 0;
}





