1  /** SetBgColor.c v1.0 - 2011-11-15
 2  Program to change the background color of the desktop.
 3  Update: http://myc01.free.fr/setbgcolor
 4  
 5  Licence: Common Public License Version 1.0 (CPL)
 6    http://www.opensource.org/licenses/cpl1.0.php
 7  **/
 8  
 9  #include <windows.h>
10  #include <stdio.h>
11  #include <stdlib.h>
12  
13  #define APP_NAME     "SetBgColor"
14  #define APP_VERSION  "1.0"
15  
16  #define DEF_R        58
17  #define DEF_G        110
18  #define DEF_B        165
19  
20  //-----------------------------------------------------------------------------
21  int main (int argc, char *argv[])
22  {
23      int i, last;
24      int aElements = COLOR_DESKTOP;
25      DWORD aNewColors = RGB (DEF_R, DEF_G, DEF_B);              /*
26      DWORD aNewColors = RGB (68, 33, 84);  // #bbggrr = #542144  */
27      char *endptr, c;
28  
29      if (argc > 1)
30      {
31          for (i = 1; i < argc; i++)
32          {
33              last = strlen (argv[i]) - 1;
34              c = argv[i][last];
35              if ((c == '?') || (c >= 'h'))
36              {
37                  printf (APP_NAME" "APP_VERSION"\n");
38                  printf ("Change the background color of the desktop.\n");
39                  printf ("Usage: SetBgColor.exe [#color] [/?|-h]\n");
40                  printf ("    #color : Background color in hexadecimal " \
41                          "(#bbggrr) (defaut = #%6lx)\n",
42                          RGB (DEF_B, DEF_G, DEF_R));
43                  printf ("    /? -h  : Display this help\n");
44                  if (argc == 2)
45                      return 0;
46              }
47  
48              c = *argv[i];
49              if ((c >= '#') && (c <= '&'))  // # $ % & = 35 36 37 38
50                  aNewColors = strtol (argv[i] + 1, &endptr, 16);
51              else
52                  if ((c >= '0') && (c <= '9'))
53                      aNewColors = atol (argv[i]);
54          }
55      }
56  
57      printf ("Change background color:" \
58              "    Red = %d    Green = %d    Blue = %d\n",
59              GetRValue (aNewColors),
60              GetGValue (aNewColors),
61              GetBValue (aNewColors));
62  
63      return !(SetSysColors (1, &aElements, &aNewColors));
64  }  // main