Over a million developers have joined DZone.

Changewindows Desktop Background Color Every 30 Seconds

·
Keep the eyes alert during long coding sessions. Compiled and tested with cygwin.


#include "windows.h"
#include 
#include 
#include 

// 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;
}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}