home *** CD-ROM | disk | FTP | other *** search
- /*-----------------------------------------------------------------
- This module loads and releases the System Hook DLL, WINHOOK.DLL.
- ------------------------------------------------------------------*/
-
- #define INCL_DOS
- #define INCL_ERRORS
- #define INCL_PM
-
- #include <os2.h>
- #include <stdio.h>
- #include <string.h>
-
- #include "winback.h"
-
- HAB hab;
- HMODULE hmodule = (HMODULE)NULL;
- PFN pfnInputHook;
-
-
- VOID cdecl main()
- {
- HMQ hmq;
- HWND hwndFrame,hwndClient;
- QMSG qmsg;
- ULONG frameflags = 0;
- HSYSSEM hssm; // handle to semaphore
-
- if (DosCreateSem(CSEM_PUBLIC, // specifies ownership
- &hssm, // address of handle
- "\\sem\\winback.sem")) // name of semaphore
- {
- DosBeep(600,200); // Already running
- DosExit(EXIT_PROCESS,1); // Terminate
- }
-
- hab = WinInitialize (0);
- hmq = WinCreateMsgQueue (hab,0);
-
- WinRegisterClass (hab, // Anchor block handle
- "WinBackClass", // Name of class being registered
- WinbackWndProc, // Window procedure for class
- 0, // Class style
- 0); // Extra bytes to reserve
-
- hwndFrame = WinCreateStdWindow (HWND_DESKTOP, // parent
- 0, // Invisible
- &frameflags, // Pointer to control data
- "WinBackClass", // Client window class name
- NULL, // titlebar text
- 0L, // Style of client window
- (HMODULE) NULL, // Module handle for resources
- 0, // resource id
- &hwndClient); // Pointer to client window handle
-
-
- while (WinGetMsg(hab,&qmsg,NULL,0,0))
- WinDispatchMsg(hab,&qmsg);
-
- WinReleaseHook (hab, // Make sure hook is released
- (HMQ) NULL,
- HK_INPUT,
- pfnInputHook,
- hmodule);
-
- WinDestroyWindow (hwndFrame);
-
- WinDestroyMsgQueue (hmq);
-
- WinTerminate (hab);
-
- return;
- }
-
- MRESULT CALLBACK WinbackWndProc (hwnd,msg,mp1,mp2)
- HWND hwnd;
- USHORT msg;
- MPARAM mp1;
- MPARAM mp2;
- {
-
- switch (msg)
- {
- case WM_CREATE:
- {
- USHORT rc; // return code
- WinPostMsg(hwnd,WM_USER,0L,0L);
-
- rc = DosLoadModule( NULL, // Load the DLL module
- 0, // containing the Hook
- "Winhook", // procedure (must use a DLL).
- &hmodule); // Get module handle
- if (rc)
- {
- WinMessageBox (HWND_DESKTOP,hwnd,
- "There was an error in loading WINHOOK.DLL",
- "DLL could not be loaded",
- 0,
- MB_OK | MB_ICONEXCLAMATION);
-
- WinPostMsg(hwnd,WM_CLOSE,0L,0L);
- }
- else
- {
- rc = DosGetProcAddr( hmodule, // Get address of Hook Proc.
- "WINHOOKPROC", // FOR THE WINSETHOOK AND
- &pfnInputHook ); // WinReleaseHook calls.
- if(rc)
- {
- WinMessageBox (HWND_DESKTOP,
- hwnd,
- "There is an error in WINHOOK.DLL",
- "Error in DLL",
- 0,
- MB_OK | MB_ICONEXCLAMATION);
-
- WinPostMsg(hwnd,WM_CLOSE,0L,0L);
- }
- else
- {
- WinSetHook (hab,
- (HMQ) NULL, // set hook to capture
- HK_INPUT, // input messages for filtering.
- pfnInputHook,
- hmodule);
- }
- }
- return FALSE;
- }
- case WM_USER:
- {
- WinDlgBox (HWND_DESKTOP,hwnd,InfoDlgProc,(HMODULE) NULL,InfoBox,NULL);
- return (MRESULT) TRUE;
- }
- case WM_QUIT:
- case WM_CLOSE:
- case WM_DESTROY:
- {
- WinReleaseHook (hab, // Make sure hook is released
- (HMQ) NULL,
- HK_INPUT,
- pfnInputHook,
- hmodule);
- }
-
- }
- return WinDefWindowProc(hwnd,msg,mp1,mp2);
- }
-
- MRESULT CALLBACK InfoDlgProc(HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2)
-
- {
- switch (msg)
- {
- case WM_INITDLG:
- WinStartTimer (hab,hwnd,1,4000);
- break;
- case WM_TIMER:
- WinStopTimer (hab,hwnd,1);
- WinDismissDlg (hwnd,0);
- break;
- }
- return WinDefDlgProc(hwnd,msg,mp1,mp2);
- }
-
-