home *** CD-ROM | disk | FTP | other *** search
- /*
- CPNLINFO.C -- Uses ControlPanelInfo to change some desktop settings
-
- From Chapter 6 of "Undocumented Windows" (Addison-Wesley 1992)
- by Andrew Schulman, Dave Maxey and Matt Pietrek
-
- Build using: WINIOBC CPNLINFO (for Borland C++ v3.00)
- WINIOMS CPNLINFO (for Microsoft C/SDK)
- */
-
- #include <windows.h>
- #include <ctype.h>
- #include <stdlib.h>
- #include "winio.h"
-
- /* undocumented function */
- extern WORD FAR PASCAL ControlPanelInfo(int nInfoType,
- WORD wData, LPSTR lpBuf);
-
- #define CPI_GETBEEP 1
- #define CPI_SETBEEP 2
- #define CPI_GETMOUSE 3
- #define CPI_SETMOUSE 4
- #define CPI_GETBORDER 5
- #define CPI_SETBORDER 6
- #define CPI_GETKEYBOARDSPEED 10
- #define CPI_SETKEYBOARDSPEED 11
- #define CPI_LANGDRIVER 12
- #define CPI_ICONSPACING 13
-
-
- #include "checkord.c"
-
- int main()
- {
- WORD wBuf[3];
- char bBuf[80];
- int n;
-
- winio_about("CPNLINFO"
- "\nUses ControlPanelInfo to change some desktop settings"
- "\n\nFrom Chapter 6 of"
- "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
- "\nby Andrew Schulman, David Maxey and Matt Pietrek"
- );
-
- // Ord/name check
- if (! CheckOrdName("ControlPanelInfo", "USER", 273))
- return 0;
-
- for (;;)
- {
- ControlPanelInfo(CPI_GETBEEP, 0, (LPSTR) &wBuf);
- printf("\nWarning beeps : %s\n",
- wBuf[0] ? "Enabled" : "Disabled");
-
- ControlPanelInfo(CPI_GETMOUSE, 0, (LPSTR) &wBuf);
- printf("Mouse speed : %d (%d %d %d)\n",
- wBuf[2] == 0 ? 1 :
- wBuf[2] == 1 ? (16 - wBuf[0]) / 3 :
- wBuf[2] == 2 ? (27 - wBuf[1]) / 3 : -1,
- wBuf[0], wBuf[1], wBuf[2]);
-
- ControlPanelInfo(CPI_GETBORDER, 0, (LPSTR) &wBuf);
- printf("Border Width : %d pixels\n", wBuf[0]);
-
- ControlPanelInfo(CPI_GETKEYBOARDSPEED, 0, (LPSTR) &wBuf);
- printf("Key repeat rate : %d\n", wBuf[0]);
-
- ControlPanelInfo(CPI_ICONSPACING, 0, (LPSTR) &wBuf);
- printf("Icon spacing : %d\n", wBuf[0]);
-
- printf("enter type to set (w, m, b, k, i): ");
-
- switch (getchar())
- {
- case 'w' :
- case 'W' :
- printf("\nToggling Warning Beep switch.\n");
- ControlPanelInfo(CPI_GETBEEP, 0, (LPSTR) &wBuf);
- wBuf[0] ^= 1;
- ControlPanelInfo(CPI_SETBEEP, wBuf[0], NULL);
- break;
- case 'b' :
- case 'B' :
- printf("\nEnter border width in pixels (1-50) : ");
- gets(bBuf);
- ControlPanelInfo(CPI_SETBORDER, atoi(bBuf), NULL);
- break;
- case 'm' :
- case 'M' :
- printf("\nEnter speed (1-7) : ");
- gets(bBuf);
- if ((n = atoi(bBuf)) == 0) n = 1;
- else
- if (n > 7) n = 7;
- if (n == 1)
- { wBuf[2] = 0; wBuf[1] = 0; wBuf[0] = 0; }
- else
- if (n < 5)
- { wBuf[2] = 1; wBuf[1] = 0; wBuf[0] = 16 - (3 * n); }
- else
- { wBuf[2] = 2; wBuf[1] = 27 - (3 * n); wBuf[0] = 4; }
- ControlPanelInfo(CPI_SETMOUSE, 0, (LPSTR) &wBuf);
- break;
- case 'k' :
- case 'K' :
- printf("\nEnter keyboard typematic repeat rate (1-31) : ");
- gets(bBuf);
- ControlPanelInfo(CPI_SETKEYBOARDSPEED, atoi(bBuf), NULL);
- break;
- case 'i' :
- case 'I' :
- printf("\nEnter desktop icon spacing in pixels : ");
- gets(bBuf);
- ControlPanelInfo(CPI_ICONSPACING, atoi(bBuf), NULL);
- break;
- default :
- printf("\n");
- }
- }
-
- return 0;
- }
-
-
-
-
-
-
-