home *** CD-ROM | disk | FTP | other *** search
/ Desktop Works 1995 - 1996 / desktopworks1995-1996.iso / scrnsave / win_ptr / winptr.c < prev    next >
Text File  |  1996-01-01  |  11KB  |  396 lines

  1. //========================================================================
  2. //
  3. //  WINPTR.C -- A Program for locating the Windows Pointer
  4. //
  5. //  (c) Douglas Boling, 1992
  6. //
  7. //  For better readability, set tab stops to every 3 characters.
  8. //
  9. //========================================================================
  10.  
  11. #include <windows.h>
  12.  
  13. #include "winptr.h"
  14.  
  15. //------------------------------------------------------------------------
  16. //Function prototypes
  17. //------------------------------------------------------------------------
  18. int    PASCAL         WinMain (HANDLE, HANDLE, LPSTR, int);
  19. long    FAR PASCAL    WndProc (HWND, WORD, WORD, LONG);
  20.  
  21. VOID    FAR PASCAL    GetStatus (PHOOKSTAT);
  22. BOOL    FAR PASCAL    LocatePointer (VOID);
  23. BOOL    FAR PASCAL    SetLocate (BOOL);
  24. BOOL    FAR PASCAL    SetTriggers (WORD, WORD);
  25. BOOL    FAR PASCAL    SetCursorID (WORD);
  26. BOOL    FAR PASCAL    SetArrowOnly (BOOL);
  27.  
  28. char        szAppName[] = "WinPtr";
  29. char        szProfileName[] = "WINPTR.INI";
  30. HANDLE      hInstance;
  31.  
  32. //=======================================================================
  33. //
  34. // Program Entry Point (WinMain)
  35. //
  36. //=======================================================================
  37. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  38.                 LPSTR lpszCmdParam, int nCmdShow) {
  39.  
  40.  
  41.    HWND            hwnd;
  42.     HANDLE        hAccel;
  43.    MSG            msg;
  44.    WNDCLASS        wndclass;
  45.  
  46.     if (!hPrevInstance) {
  47.       wndclass.style          = CS_HREDRAW | CS_VREDRAW;
  48.       wndclass.lpfnWndProc    = WndProc;
  49.       wndclass.cbClsExtra     = 0;
  50.       wndclass.cbWndExtra     = DLGWINDOWEXTRA;
  51.       wndclass.hInstance      = hInstance;
  52.       wndclass.hIcon          = LoadIcon (hInstance, szAppName);
  53.       wndclass.hCursor        = LoadCursor (NULL, IDC_ARROW);
  54.       wndclass.hbrBackground  = COLOR_WINDOW + 1;
  55.       wndclass.lpszMenuName   = 0;
  56.       wndclass.lpszClassName  = szAppName;
  57.  
  58.       RegisterClass (&wndclass);
  59.    }
  60.    hwnd = CreateDialog (hInstance, szAppName, 0, NULL);
  61.  
  62.     if (lpszCmdParam[0] == '/' || lpszCmdParam[0] == '-') 
  63.         if (lpszCmdParam[1] == 'i' || lpszCmdParam[1] == 'I') 
  64.             nCmdShow |= SW_MINIMIZE;
  65.  
  66.     ShowWindow (hwnd, nCmdShow);
  67.     hAccel = LoadAccelerators (hInstance, szAppName);
  68.  
  69.     while (GetMessage (&msg, NULL, 0, 0)) {
  70.         if (!TranslateAccelerator (hwnd, hAccel, &msg)) {
  71.            TranslateMessage (&msg);
  72.            DispatchMessage (&msg);
  73.         }
  74.     }
  75.     SetLocate(FALSE);
  76.    return msg.wParam;
  77. }
  78.  
  79. //========================================================================
  80. //
  81. // Routines that replace standard library functions.
  82. //
  83. //========================================================================
  84.  
  85. //------------------------------------------------------------------------
  86. // STRCPY - Copy String.
  87. //------------------------------------------------------------------------
  88. VOID strcpy (char * pDest, char * pSrc) {
  89.  
  90.     while (*pDest++ = *pSrc++);
  91. }
  92.  
  93. //------------------------------------------------------------------------
  94. // STRCAT - Concatinate String.
  95. //------------------------------------------------------------------------
  96. VOID strcat (char * pDest, char * pSrc) {
  97.  
  98.     while (*pDest)
  99.         *pDest++;
  100.     strcpy (pDest, pSrc);
  101. }
  102.  
  103. //------------------------------------------------------------------------
  104. // ITOA - Convert integer to ASCII
  105. // NOTE:  This routine only works for sBase <= 10
  106. //------------------------------------------------------------------------
  107. VOID itoa (int sNum, char * pDest, int sBase) {
  108.  
  109.     char *pTemp;
  110.     char    c;
  111.  
  112.     pTemp = pDest;
  113.     //
  114.     // Convert string
  115.     //
  116.     do {
  117.         *pDest++ = (char)(sNum % sBase) + '0';
  118.     } while (sNum /= sBase);
  119.  
  120.      *pDest-- = 0;
  121.     //
  122.     // Reverse string
  123.     //
  124.     while (pDest > pTemp) {
  125.         c = *pTemp;
  126.         *pTemp++ = *pDest;
  127.         *pDest-- = c;
  128.     }
  129. }
  130.  
  131. //========================================================================
  132. //
  133. // Routines used by WndProc
  134. //
  135. //========================================================================
  136. //------------------------------------------------------------------------
  137. // Set Enable Text
  138. //------------------------------------------------------------------------
  139. VOID SetEnableText (HWND hwnd, BOOL bEnable) {
  140.  
  141.     if (bEnable) {
  142.         SetWindowText (hwnd, "WinPtr - Enabled");
  143.         SetDlgItemText (hwnd, IDD_ENABLE, "Disable");
  144.     } else {
  145.         SetWindowText (hwnd, "WinPtr - Disabled");
  146.         SetDlgItemText (hwnd, IDD_ENABLE, "Enable");
  147.     }
  148.     return;
  149. }
  150.  
  151. //------------------------------------------------------------------------
  152. // Set Move Trigger Text
  153. //------------------------------------------------------------------------
  154. VOID SetMoveTrigText (HWND hwnd, WORD wMoveTrig) {
  155.  
  156.     char    szTemp[80];
  157.     char    szTemp1[10];
  158.  
  159.     itoa (wMoveTrig, szTemp1, 10);
  160.     strcpy (szTemp, "Movement Trigger: ");
  161.     strcat (szTemp, szTemp1);
  162.     strcat (szTemp, " Pels");
  163.     SetDlgItemText (hwnd, IDD_MOVETEXT, szTemp);
  164.     return;
  165. }
  166.  
  167. //------------------------------------------------------------------------
  168. // Set Time Trigger Text
  169. //------------------------------------------------------------------------
  170. VOID SetTimeTrigText (HWND hwnd, WORD wTimeTrig) {
  171.  
  172.     char    szTemp[80];
  173.     char    szTemp1[10];
  174.         
  175.     itoa (wTimeTrig, szTemp1, 10);
  176.     strcpy (szTemp, "Persistance Time: ");
  177.     strcat (szTemp, szTemp1);
  178.     strcat (szTemp, " mS");
  179.     SetDlgItemText (hwnd, IDD_TIMETEXT, szTemp);
  180.     return;
  181. }
  182.  
  183. //------------------------------------------------------------------------
  184. //
  185. // About box dialog procedure
  186. //
  187. //------------------------------------------------------------------------
  188. BOOL FAR PASCAL AboutDlgProc (HWND hwnd, WORD message, WORD wParam, 
  189.                                LONG lParam) {
  190.  
  191.     switch (message) {
  192.  
  193.         case WM_COMMAND:
  194.  
  195.             switch (wParam) {
  196.  
  197.                 case IDOK:
  198.  
  199.                     EndDialog (hwnd, 1);
  200.                     return TRUE;
  201.             }
  202.             break;
  203.  
  204.         case WM_CLOSE:
  205.             EndDialog (hwnd, 0);
  206.             return TRUE;
  207.     }
  208.     return FALSE;    
  209. }
  210.  
  211. //========================================================================
  212. //
  213. // Main Window Procedure.
  214. //
  215. //========================================================================
  216. long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam) {
  217.  
  218.     static    FARPROC    lpfnAboutDlgProc;
  219.     int       i,j;
  220.     HOOKSTAT    hsHook;
  221.     char        szTemp[10];
  222.  
  223.    switch (message) {
  224.     
  225.       case WM_CREATE:
  226.  
  227.             hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
  228.             //
  229.             //Create thunk for dialog box 
  230.             //
  231.             lpfnAboutDlgProc = MakeProcInstance (AboutDlgProc, 
  232.                                                  hInstance);
  233.             //
  234.             //Get and set initial trigger, cursor, and pos values 
  235.             //
  236.             i = GetPrivateProfileInt (szAppName, "MoveTrig", 
  237.                                       10, szProfileName);
  238.             j = GetPrivateProfileInt (szAppName, "TimeTrig", 
  239.                                       300, szProfileName);
  240.             SetTriggers (i, j);
  241.  
  242.             i = GetPrivateProfileInt (szAppName, "Cursor", 
  243.                                       1, szProfileName);
  244.             SetCursorID (i);
  245.  
  246.             i = GetPrivateProfileInt (szAppName, "ArrowOnly", 
  247.                                       1, szProfileName);
  248.             SetArrowOnly (i);
  249.  
  250.             SetLocate(TRUE);
  251.             return 0;
  252.  
  253.  
  254.         case WM_SIZE:
  255.  
  256.             GetStatus (&hsHook);
  257.             SetScrollRange (GetDlgItem (hwnd, IDD_MOVETRIG), 
  258.                             SB_CTL, 0, 200, FALSE);
  259.  
  260.             if (hsHook.wTimeTrig > 100) 
  261.                 i = 100 + ((hsHook.wMoveTrig - 100) / 5);
  262.             else
  263.                 i = hsHook.wMoveTrig;
  264.             SetScrollPos (GetDlgItem (hwnd, IDD_MOVETRIG), 
  265.                           SB_CTL, hsHook.wMoveTrig, TRUE);
  266.  
  267.  
  268.             SetScrollRange (GetDlgItem (hwnd, IDD_TIMETRIG), 
  269.                             SB_CTL, 0, 500, FALSE);
  270.  
  271.             if (hsHook.wTimeTrig > 100) 
  272.                 i = 100 + ((hsHook.wTimeTrig - 100) / 10);
  273.             else
  274.                 i = hsHook.wTimeTrig;
  275.             SetScrollPos (GetDlgItem (hwnd, IDD_TIMETRIG), 
  276.                           SB_CTL, i, TRUE);
  277.  
  278.             SetMoveTrigText (hwnd, hsHook.wMoveTrig);
  279.             SetTimeTrigText (hwnd, hsHook.wTimeTrig);
  280.             SetEnableText (hwnd, hsHook.bEnabled);
  281.             if (hsHook.bArrowOnly)
  282.                 CheckDlgButton (hwnd, IDD_ARROWONLY, 1);
  283.             else 
  284.                 CheckDlgButton (hwnd, IDD_ARROWONLY, 0);
  285.  
  286.             break;
  287.  
  288.  
  289.         case WM_COMMAND:
  290.  
  291.             GetStatus (&hsHook);
  292.             switch (wParam) {
  293.  
  294.                 case IDD_ABOUT:
  295.                     DialogBox (hInstance, "About", h