home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / mag&info / msjv7_6.zip / TOPTEN.ARJ / MOUSEEAT.ARJ / MOUSEEAT.C < prev    next >
Text File  |  1992-10-01  |  9KB  |  273 lines

  1. #include <windows.h>
  2.  
  3. #include "mouseeat.h"
  4. #include "basedefs.h"
  5.  
  6. /**************************************************************
  7. *                                                             *
  8. *                  Function Prototypes                        *
  9. *                                                             *
  10. **************************************************************/
  11.  
  12. WINPROC WndProc ( WINDOWS_PARAMS );
  13. WINPROC InvisoWndProc ( WINDOWS_PARAMS );
  14. DLGPROC DlgProc ( DIALOG_PARAMS  );
  15. HWND    hCreateInvisoWindow ( HWND hParent );
  16.  
  17. /**************************************************************
  18. *                                                             *
  19. *                   Global Variables                          *
  20. *                                                             *
  21. **************************************************************/
  22.  
  23. HANDLE ghInst;
  24. HWND   ghWnd;
  25. char   szAppName[]    = "MOUSEEAT";
  26. char   szInvisoName[] = "INVISOWINDOW";
  27.  
  28. /**************************************************************
  29. *                                                             *
  30. *                      WinMain                                *
  31. *                                                             *
  32. **************************************************************/
  33.  
  34. int PASCAL WinMain (HANDLE hInstance,  HANDLE hPrevInstance, 
  35.                     LPSTR lpszCmdLine, int    nCmdShow       )
  36. {
  37.   MSG         msg       ;
  38.   WNDCLASS    wndclass  ;
  39.  
  40.   if (!hPrevInstance) 
  41.     {
  42.  
  43.     // Register Parent Window
  44.  
  45.     wndclass.style         = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNCLIENT;
  46.     wndclass.lpfnWndProc   = (WNDPROC)WndProc ;
  47.     wndclass.cbClsExtra    = 0 ;
  48.     wndclass.cbWndExtra    = 0 ;
  49.     wndclass.hInstance     = hInstance ;
  50.     wndclass.hIcon         = NULL;
  51.     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  52.     wndclass.hbrBackground = GetStockObject ( GRAY_BRUSH ) ;
  53.     wndclass.lpszMenuName  = (LPSTR)"PlainMenu" ;
  54.     wndclass.lpszClassName = szAppName ;
  55.  
  56.     if (!RegisterClass (&wndclass))
  57.          return FALSE;
  58.  
  59.     // Register the message eater
  60.  
  61.     wndclass.style         = NULL;
  62.     wndclass.lpfnWndProc   = (WNDPROC)InvisoWndProc ;
  63.     wndclass.cbClsExtra    = 0 ;
  64.     wndclass.cbWndExtra    = 0 ;
  65.     wndclass.hInstance     = hInstance ;
  66.     wndclass.hIcon         = NULL;
  67.     wndclass.hCursor       = LoadCursor (NULL, IDC_WAIT) ;
  68.     wndclass.hbrBackground = GetStockObject ( NULL_BRUSH ) ;
  69.     wndclass.lpszMenuName  = (LPSTR)NULL;
  70.     wndclass.lpszClassName = szInvisoName ;
  71.  
  72.     if (!RegisterClass (&wndclass))
  73.          return FALSE;
  74.     }
  75.  
  76.   ghInst   = hInstance;
  77.  
  78.   ghWnd =        CreateWindow (szAppName, "Tiny Windows App",
  79.                                WS_OVERLAPPEDWINDOW,
  80.                                CW_USEDEFAULT, 0,
  81.                                CW_USEDEFAULT, 0,
  82.                                NULL, NULL, hInstance, NULL) ;
  83.  
  84.   ShowWindow ( ghWnd, nCmdShow );
  85.   UpdateWindow ( ghWnd );
  86.  
  87.   while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  88.     {
  89.     TranslateMessage(&msg);
  90.     DispatchMessage(&msg);
  91.     }
  92.  
  93.   return msg.wParam ;
  94. }
  95.  
  96. /*********************************************************************
  97. *                                                                    *
  98. *                  ModalDialog: Calls a Modal Dialog Box             *
  99. *                                                                    *
  100. *********************************************************************/
  101.  
  102. int ModalDialog ( LPSTR TemplateName, FARPROC FunctionName, LONG dwParam )
  103. {
  104.   FARPROC  lpDialogProc;
  105.   int      RetVal;
  106.  
  107.   lpDialogProc = MakeProcInstance ( FunctionName, ghInst );
  108.   RetVal       = DialogBoxParam ( ghInst, TemplateName, ghWnd, 
  109.                                   lpDialogProc, (DWORD)dwParam );
  110.   FreeProcInstance ( lpDialogProc );
  111.   return RetVal;
  112. }
  113.  
  114. /*********************************************************************
  115. *                                                                    *
  116. *                       WndProc: Main Message Translator             *
  117. *                                                                    *
  118. *********************************************************************/
  119.  
  120. WINPROC WndProc ( WINDOWS_PARAMS )
  121. {
  122.   switch ( msg )
  123.     {
  124.     case WM_DESTROY :
  125.  
  126.       PostQuitMessage (0) ;
  127.       break ;
  128.  
  129.     case WM_COMMAND :
  130.  
  131.       switch ( wParam )
  132.  
  133.         {
  134.         case IDM_MODAL :
  135.  
  136.            ModalDialog ( "MODALDIALOG", DlgProc, 0L );
  137.            break;
  138.  
  139.         default:
  140.  
  141.            return DefWindowProc ( hWnd, msg, wParam, lParam ) ;
  142.            break;
  143.         }
  144.  
  145.       break;
  146.  
  147.     default :
  148.  
  149.       return DefWindowProc ( hWnd, msg, wParam, lParam );
  150.  
  151.     }
  152.   return 0L ;
  153. }
  154. /*********************************************************************
  155. *                                                                    *
  156. *                   InvisoWndProc: A message eater                   *
  157. *                                                reak;
  158.  
  159.     case WM_TIMER:
  160.  
  161.        // This is the cheesy recalc. Does nothing, but it takes a while.
  162.  
  163.        iTimerCount++;
  164.        SetDlgItemInt ( hDlg, IDD_LEFT, iTimerCount, FALSE );
  165.        if (iTimerCount >= iRecalcTime)
  166.          {
  167.          KillTimer ( hDlg, 1 );
  168.  
  169.          // Beep to tell the user that the recalc is done
  170.  
  171.          MessageBeep (0);
  172.  
  173.          // Reset the dialog to its original, upright position
  174.  
  175.          SetDlgItemText ( hDlg, IDD_LEFT, "" );
  176.          SetFocus ( GetDlgItem ( hDlg, IDOK ) );
  177.  
  178.          // Kill the message eater and reset the semaphore wannabe
  179.  
  180.          DestroyWindow (hWndInviso);
  181.          hWndInviso = NULL;
  182.          }
  183.        break;
  184.  
  185.     case WM_COMMAND:
  186.       
  187.        switch (wParam)
  188.          {
  189.          case IDCANCEL:
  190.  
  191.             // Check to see if user cancelled during a recalc, if so housekeep
  192.  
  193.             if (hWndInviso)
  194.               {
  195.               KillTimer ( hDlg, 1 );
  196.               DestroyWindow (hWndInviso);
  197.               hWndInviso = NULL;
  198.               }
  199.             EndDialog ( hDlg, TRUE );          
  200.             return TRUE;
  201.         
  202.          case IDOK:
  203.  
  204.             if (hWndInviso) break; // In a recalc, don't start another recalc
  205.  
  206.             if (BN_CLICKED == HIWORD(lParam))
  207.               {
  208.               iRecalcTime = GetDlgItemInt ( hDlg, IDD_RTIME, &err, FALSE );
  209.               iTimerCount = 0;
  210.  
  211.               SetDlgItemText ( hDlg, IDD_LEFT, "0" );
  212.               SetTimer ( hDlg, 1, 1000, NULL );
  213.               hWndInviso = hCreateInvisoWindow ( hDlg );
  214.               }
  215.  
  216.             break;
  217.  
  218.          default:
  219.           
  220.             return FALSE;
  221.          }
  222.        break;
  223.  
  224.     default:
  225.  
  226.        return FALSE;
  227.     }
  228.  
  229.   return TRUE;
  230. }
  231.  
  232. /*********************************************************************
  233. *                                                                    *
  234. *                                                                    *
  235. *                                                                    *
  236. *********************************************************************/
  237.  
  238. HWND hCreateInvisoWindow ( HWND hParent )
  239. {
  240.   RECT r;
  241.   HWND hWnd;
  242.  
  243.   GetClientRect ( hParent, &r );
  244.  
  245.   hWnd = CreateWindowEx 
  246.            (
  247.            WS_EX_TRANSPARENT,
  248.            szInvisoName,
  249.            "",
  250.            WS_CHILD | WS_VISIBLE,
  251.            0, 0,
  252.            r.right, r.bottom,
  253.            hParent,
  254.            42,
  255.            ghInst,
  256.            NULL
  257.            );
  258.  
  259.   // Cover all controls with the message eater
  260.  
  261.   BringWindowToTop ( hWnd );                         
  262.  
  263.   // Bring the cancel button up from "below" so the user can bag the recalc
  264.  
  265.   BringWindowToTop ( GetDlgItem ( hParent, IDCANCEL) ); // Uncover the Cancel key
  266.  
  267.   // Set focus so that the hourglass appears
  268.  
  269.   SetFocus ( hWnd );
  270.  
  271.   return hWnd;
  272. }
  273.