home *** CD-ROM | disk | FTP | other *** search
- /*
- GTMSEVNT.C -- Generates mouse movements by calling the
- mouse event handler directly
-
- From Chapter 6 of "Undocumented Windows" (Addison-Wesley 1992)
- by Andrew Schulman, Dave Maxey and Matt Pietrek
-
- Build using: WINIOBC GTMSEVNT (for Borland C++ v3.00)
- WINIOMS GTMSEVNT (for Microsoft C/SDK)
- */
-
- #include <windows.h>
- #include "winio.h"
-
- #ifdef __BORLANC__
- #define _asm asm
- #endif
-
- #define ME_MOVE 0x01
- #define ME_LDOWN 0x02
- #define ME_LUP 0x04
- #define ME_RDOWN 0x08
- #define ME_RUP 0x10
-
- FARPROC lpfnMouseEventProc;
- FARPROC lpfnTimerFunc;
- int i;
- int xInc;
- int yInc;
- HANDLE hTimer;
-
-
- /* undocumented function */
- extern FARPROC FAR PASCAL GetMouseEventProc(void);
-
- #include "checkord.c"
-
- BOOL StopMoving(HWND hwnd)
- {
- KillTimer(winio_current(), hTimer);
- FreeProcInstance(lpfnTimerFunc);
- return TRUE;
- }
-
- WORD FAR PASCAL TimerFunc(HWND hwnd, WORD wMsg, int id, DWORD dwTime)
- {
- if (++i & 7)
- {
- // This trickery simply moves the mouse in a rectangular path
- if ((xInc = 32 - (((i >> 3) & 3) * 16)) == 32)
- xInc = 0;
- if ((yInc = 32 - ((((i + 24) >> 3) & 3) * 16)) == 32)
- yInc = 0;
- }
-
- _asm {
- mov ax, ME_MOVE;
- mov bx, xInc;
- mov cx, yInc;
- mov dx, 2;
- call dword ptr [lpfnMouseEventProc];
- }
-
- return 1;
- }
-
- int main()
- {
- // Ord/name check
- if (! CheckOrdName("GetMouseEventProc", "USER", 337))
- return 0;
-
- winio_about("GTMSEVNT"
- "\nGenerates mouse movements by calling the"
- "\nmouse event handler directly"
- "\n\nFrom Chapter 6 of"
- "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
- "\nby Andrew Schulman, David Maxey and Matt Pietrek"
- );
-
- lpfnTimerFunc = MakeProcInstance((FARPROC) TimerFunc, __hInst);
-
- printf("Mouse event proc is at %Fp\n",
- lpfnMouseEventProc = GetMouseEventProc());
-
- if (lpfnMouseEventProc ==
- GetProcAddress(GetModuleHandle("USER"), "mouse_event"))
- printf("Address is of Mouse_Event..\n");
-
- printf("The mouse will now move as if by magic....!\n\n");
-
- hTimer = SetTimer(winio_current(), 1, 30, lpfnTimerFunc);
-
- winio_onclose(winio_current(), (DESTROY_FUNC) StopMoving);
-
- printf("\nClose window to exit. (Use Alt-F4)");
-
- return 0;
- }
-