home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l430 / 1.ddi / CHAP6.ZIP / CPNLINFO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  4.0 KB  |  131 lines

  1. /*
  2.     CPNLINFO.C -- Uses ControlPanelInfo to change some desktop settings
  3.  
  4.     From Chapter 6 of "Undocumented Windows" (Addison-Wesley 1992)
  5.     by Andrew Schulman, Dave Maxey and Matt Pietrek
  6.  
  7.     Build using: WINIOBC CPNLINFO (for Borland C++ v3.00)
  8.                  WINIOMS CPNLINFO (for Microsoft C/SDK)
  9. */
  10.  
  11. #include <windows.h>
  12. #include <ctype.h>
  13. #include <stdlib.h>
  14. #include "winio.h"
  15.  
  16. /* undocumented function */ 
  17. extern WORD FAR PASCAL ControlPanelInfo(int nInfoType,
  18.                                     WORD wData, LPSTR lpBuf);
  19.  
  20. #define CPI_GETBEEP 1
  21. #define CPI_SETBEEP 2
  22. #define CPI_GETMOUSE 3
  23. #define CPI_SETMOUSE 4
  24. #define CPI_GETBORDER 5
  25. #define CPI_SETBORDER 6
  26. #define CPI_GETKEYBOARDSPEED 10
  27. #define CPI_SETKEYBOARDSPEED 11
  28. #define CPI_LANGDRIVER 12
  29. #define CPI_ICONSPACING 13
  30.  
  31.  
  32. #include "checkord.c"
  33.  
  34. int main() 
  35.     {
  36.     WORD wBuf[3];
  37.     char bBuf[80];
  38.     int n;
  39.     
  40.     winio_about("CPNLINFO"
  41.         "\nUses ControlPanelInfo to change some desktop settings"
  42.         "\n\nFrom Chapter 6 of"
  43.         "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
  44.         "\nby Andrew Schulman, David Maxey and Matt Pietrek"
  45.         );
  46.     
  47.     // Ord/name check
  48.     if (! CheckOrdName("ControlPanelInfo", "USER", 273))
  49.         return 0;
  50.  
  51.     for (;;)
  52.         {
  53.         ControlPanelInfo(CPI_GETBEEP, 0, (LPSTR) &wBuf);
  54.         printf("\nWarning beeps    : %s\n",
  55.                                 wBuf[0] ? "Enabled" : "Disabled");
  56.  
  57.         ControlPanelInfo(CPI_GETMOUSE, 0, (LPSTR) &wBuf);
  58.         printf("Mouse speed      : %d (%d %d %d)\n",
  59.                     wBuf[2] == 0 ? 1 :
  60.                     wBuf[2] == 1 ? (16 - wBuf[0]) / 3 :
  61.                     wBuf[2] == 2 ? (27 - wBuf[1]) / 3 : -1,
  62.                     wBuf[0], wBuf[1], wBuf[2]); 
  63.  
  64.         ControlPanelInfo(CPI_GETBORDER, 0, (LPSTR) &wBuf);
  65.         printf("Border Width     : %d pixels\n", wBuf[0]);
  66.  
  67.         ControlPanelInfo(CPI_GETKEYBOARDSPEED, 0, (LPSTR) &wBuf);
  68.         printf("Key repeat rate  : %d\n", wBuf[0]);
  69.  
  70.         ControlPanelInfo(CPI_ICONSPACING, 0, (LPSTR) &wBuf);
  71.         printf("Icon spacing     : %d\n", wBuf[0]);
  72.  
  73.         printf("enter type to set (w, m, b, k, i): ");
  74.  
  75.         switch (getchar())
  76.             {
  77.             case 'w' :
  78.             case 'W' :
  79.                 printf("\nToggling Warning Beep switch.\n");
  80.                 ControlPanelInfo(CPI_GETBEEP, 0, (LPSTR) &wBuf);
  81.                 wBuf[0] ^= 1;
  82.                 ControlPanelInfo(CPI_SETBEEP, wBuf[0], NULL);
  83.                 break;
  84.             case 'b' :
  85.             case 'B' :
  86.                 printf("\nEnter border width in pixels (1-50) : ");
  87.                 gets(bBuf);
  88.                 ControlPanelInfo(CPI_SETBORDER, atoi(bBuf), NULL);
  89.                 break;
  90.             case 'm' :
  91.             case 'M' :
  92.                 printf("\nEnter speed (1-7) : ");
  93.                 gets(bBuf);
  94.                 if ((n = atoi(bBuf)) == 0) n = 1;
  95.                 else
  96.                 if (n > 7) n = 7;
  97.                 if (n == 1)
  98.                     { wBuf[2] = 0; wBuf[1] = 0; wBuf[0] = 0; }
  99.                 else
  100.                 if (n < 5)
  101.                     { wBuf[2] = 1; wBuf[1] = 0; wBuf[0] = 16 - (3 * n); }
  102.                 else
  103.                     { wBuf[2] = 2; wBuf[1] = 27 - (3 * n); wBuf[0] = 4; }
  104.                 ControlPanelInfo(CPI_SETMOUSE, 0, (LPSTR) &wBuf);
  105.                 break;
  106.             case 'k' :
  107.             case 'K' :
  108.                 printf("\nEnter keyboard typematic repeat rate (1-31) : ");
  109.                 gets(bBuf);
  110.                 ControlPanelInfo(CPI_SETKEYBOARDSPEED, atoi(bBuf), NULL);
  111.                 break;
  112.             case 'i' :  
  113.             case 'I' :  
  114.                 printf("\nEnter desktop icon spacing in pixels : ");
  115.                 gets(bBuf);
  116.                 ControlPanelInfo(CPI_ICONSPACING, atoi(bBuf), NULL);
  117.                 break;
  118.             default :
  119.                 printf("\n");
  120.             }
  121.         }
  122.     
  123.     return 0;
  124.     }
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.