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

  1. /*
  2.     GTMSEVNT.C -- Generates mouse movements by calling the
  3.     mouse event handler directly
  4.  
  5.     From Chapter 6 of "Undocumented Windows" (Addison-Wesley 1992)
  6.     by Andrew Schulman, Dave Maxey and Matt Pietrek
  7.  
  8.     Build using: WINIOBC GTMSEVNT (for Borland C++ v3.00)
  9.                  WINIOMS GTMSEVNT (for Microsoft C/SDK)
  10. */
  11.  
  12. #include <windows.h> 
  13. #include "winio.h" 
  14.  
  15. #ifdef __BORLANC__
  16. #define _asm asm
  17. #endif
  18.  
  19. #define ME_MOVE     0x01
  20. #define ME_LDOWN    0x02
  21. #define ME_LUP      0x04
  22. #define ME_RDOWN    0x08
  23. #define ME_RUP      0x10
  24.  
  25. FARPROC lpfnMouseEventProc;
  26. FARPROC lpfnTimerFunc;
  27. int i;  
  28. int xInc;
  29. int yInc;
  30. HANDLE hTimer;
  31.  
  32.  
  33. /* undocumented function */ 
  34. extern FARPROC FAR PASCAL GetMouseEventProc(void);
  35.  
  36. #include "checkord.c"
  37.  
  38. BOOL StopMoving(HWND hwnd)
  39.     {
  40.     KillTimer(winio_current(), hTimer);
  41.     FreeProcInstance(lpfnTimerFunc);
  42.     return TRUE;
  43.     }
  44.  
  45. WORD FAR PASCAL TimerFunc(HWND hwnd, WORD wMsg, int id, DWORD dwTime)
  46.     {
  47.     if (++i & 7)
  48.         {
  49.         // This trickery simply moves the mouse in a rectangular path
  50.         if ((xInc = 32 - (((i >> 3) & 3) * 16)) == 32)
  51.             xInc = 0;
  52.         if ((yInc = 32 - ((((i + 24) >> 3) & 3) * 16)) == 32)
  53.             yInc = 0;
  54.         }
  55.     
  56.     _asm {
  57.         mov ax, ME_MOVE;
  58.         mov bx, xInc;
  59.         mov cx, yInc;
  60.         mov dx, 2;
  61.         call    dword ptr [lpfnMouseEventProc];
  62.         }
  63.     
  64.     return 1;
  65.     }
  66.  
  67. int main() 
  68.     {
  69.     // Ord/name check
  70.     if (! CheckOrdName("GetMouseEventProc", "USER", 337))
  71.         return 0;
  72.  
  73.     winio_about("GTMSEVNT"
  74.         "\nGenerates mouse movements by calling the"
  75.         "\nmouse event handler directly"
  76.         "\n\nFrom Chapter 6 of"
  77.         "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
  78.         "\nby Andrew Schulman, David Maxey and Matt Pietrek"
  79.         );
  80.     
  81.     lpfnTimerFunc = MakeProcInstance((FARPROC) TimerFunc, __hInst);
  82.     
  83.     printf("Mouse event proc is at %Fp\n",
  84.         lpfnMouseEventProc = GetMouseEventProc());
  85.  
  86.     if (lpfnMouseEventProc ==
  87.         GetProcAddress(GetModuleHandle("USER"), "mouse_event"))
  88.         printf("Address is of Mouse_Event..\n");
  89.         
  90.     printf("The mouse will now move as if by magic....!\n\n");
  91.     
  92.     hTimer = SetTimer(winio_current(), 1, 30, lpfnTimerFunc);
  93.     
  94.     winio_onclose(winio_current(), (DESTROY_FUNC) StopMoving);
  95.     
  96.     printf("\nClose window to exit. (Use Alt-F4)");
  97.  
  98.     return 0;
  99.     }
  100.