home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
JUMP.ZIP
/
JUMPLDR.C
< prev
next >
Wrap
Text File
|
1991-09-05
|
13KB
|
335 lines
/*---------------------------------------------------------------------
This loads the system hook dll (jumphook.dll) and starts the
program that actually does the 3270 Window controlling (jump.exe)
----------------------------------------------------------------------*/
#define INCL_DOS
#define INCL_ERRORS
#define INCL_PM
#define NUL '\0'
#include <os2.h>
#include <stdio.h>
#include <string.h>
#include "jumpldr.h"
HAB hab;
HMODULE hmodule = (HMODULE)NULL;
PFN pfnInputHook;
MRESULT EXPENTRY JumpWndProc( HWND, USHORT, MPARAM, MPARAM );
VOID cdecl main()
{
HMQ hmq;
HPOINTER hptrIcon;
HWND hwndDlg;
hab = WinInitialize( NUL );
hmq = WinCreateMsgQueue( hab, 0 );
if((DosCreateSem(1,&hsemDie,DIE_SEM_NAME)==ERROR_ALREADY_EXISTS));
DosOpenSem(&hsemDie,DIE_SEM_NAME);
if((DosCreateSem(1,&hsemJump,JUMP_SEM_NAME)==ERROR_ALREADY_EXISTS));
DosOpenSem(&hsemJump,JUMP_SEM_NAME);
DosSemSet(hsemJump);
DosSemRequest(hsemDie,0);
hwndDlg = WinLoadDlg( HWND_DESKTOP, /* Load the dialog window */
HWND_DESKTOP, /* which allows turning the */
JumpDlgProc, /* hook on and off. This */
NUL, /* window also provides a */
IDD_JUMPLDR, /* visual notification that a */
NUL ); /* hook may be active (if set)*/
hptrIcon = WinLoadPointer( HWND_DESKTOP, NUL, IDD_JUMPLDR );
WinSendMsg( hwndDlg, /* Attach the icon to the */
WM_SETICON, /* frame window. */
(MPARAM)hptrIcon,
(MPARAM)NULL );
WinProcessDlg( hwndDlg );
WinReleaseHook( hab, /* Make sure hook is released */
(HMQ)NULL,
HK_INPUT,
pfnInputHook,
hmodule );
/* clear the semaphores - first the DIE semaphore so when
the JUMP semaphore is cleared, JUMP.EXE knows to exit */
DosSemClear( hsemDie );
DosSemClear( hsemJump );
WinDestroyWindow( hwndDlg );
WinDestroyMsgQueue( hmq );
WinTerminate( hab );
return;
}
/***************************************************************************|
| Change Pointer Window Procedure |
|***************************************************************************/
MRESULT EXPENTRY JumpDlgProc( hwnd, msg, mp1, mp2 )
HWND hwnd;
USHORT msg;
MPARAM mp1;
MPARAM mp2;
{
USHORT usCheckedState;
STARTDATA StartData; /* Start session data */
PSTARTDATA pStartData; /* Start session data */
USHORT SessID; /* Session ID (returned) */
USHORT PID; /* Process ID (returned) */
char start_sess_args[18]=" /c detach jump ";
HWND hwndSysMenu; /* system menu handle */
switch(msg)
{
case WM_INITDLG:
{
USHORT idSysMenu; /* system menu id */
MENUITEM miSysMenu; /* system menu item info */
MENUITEM miMenuItem; /* About menu item info */
USHORT rc = 0; /* return code */
/* add About item to system menu */
if ( hwndSysMenu = WinWindowFromID( hwnd, FID_SYSMENU ) )
{
/* get handle of system submenu */
idSysMenu = SHORT1FROMMR( WinSendMsg( hwndSysMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT( 0 ), 0L ) );
WinSendMsg( hwndSysMenu, MM_QUERYITEM, MPFROM2SHORT( idSysMenu, FALSE ), MPFROMP( &miSysMenu ) );
hwndSysMenu = miSysMenu.hwndSubMenu;
/* add menu separator */
miMenuItem.iPosition = MIT_END;
miMenuItem.afStyle = MIS_SEPARATOR;
miMenuItem.afAttribute = 0;
miMenuItem.id = 0;
miMenuItem.hwndSubMenu = NUL;
miMenuItem.hItem = NUL;
WinSendMsg( hwndSysMenu, MM_INSERTITEM, MPFROMP( &miMenuItem ), NUL );
/* add About item */
miMenuItem.afStyle = MIS_TEXT;
miMenuItem.id = IDM_ABOUT;
WinSendMsg( hwndSysMenu, MM_INSERTITEM, MPFROMP( &miMenuItem ), MPFROMP( "A~bout..." ) );
}
WinSetDlgItemText( hwnd, /* Set title bar text */
FID_TITLEBAR,
"Session Jumper" );
WinSendMsg( WinWindowFromID( hwnd,IDCB_JUMPSW ),
BM_SETCHECK, /* set check box */
MPFROMSHORT(1),
(MPARAM)NULL );
rc = DosLoadModule( NULL, /* Load the DLL module */
0, /* containing the Hook */
"jumphook", /* procedure (must use a DLL).*/
&hmodule ); /* Get module handle */
if(rc)
{
WinMessageBox (HWND_DESKTOP,HWND_DESKTOP,
"There was an error in loading JUMPHOOK.DLL",
"DLL could not be loaded",
0,MB_OK | MB_ERROR);
WinPostMsg(hwnd,WM_CLOSE,0L,0L);
}
else
{
rc = DosGetProcAddr( hmodule, /* Get address of Hook Proc. */
"JUMPHOOKPROC", /* FOR THE WINSETHOOK AND */
&pfnInputHook ); /* WinReleaseHook calls. */
if(rc)
{
WinMessageBox (HWND_DESKTOP,HWND_DESKTOP,
"There is an error in JUMPHOOK.DLL",
"Error in DLL",
0,MB_OK | MB_ERROR);
WinPostMsg(hwnd,WM_CLOSE,0L,0L);
}
else
{
/* Start the jump program detached */
/* so it doesn't show up in the task list or */
/* as an icon */
/* JUMP.EXE actually controls the 3270 sessions */
StartData.Related = 1; /* 0=independent session, 1=child session */
StartData.FgBg = 1; /* 0=start in foreground, 1=start in background */
StartData.TraceOpt = 0; /* 0=no trace, 1=trace */
StartData.PgmTitle = NULL; /* address of program title */
StartData.PgmName = NULL; /* address of program name */
StartData.TermQ = NULL; /* address of program queue name */
StartData.Environment = NULL; /* address of environment string */
StartData.InheritOpt = 0; /* inherit option (shell of program) */
StartData.SessionType = 2; /* session type (standard, windowed, ) */
StartData.IconFile = NULL; /* address of icon definition */
StartData.PgmHandle = 0; /* program handle */
StartData.PgmControl=4; /* initial state of windowed application */
StartData.InitXPos=0; /* x coordinate of initial session window */
StartData.InitYPos=0; /* y coordinate of initial session window */
StartData.InitXSize=0; /* initial size of x */
StartData.InitYSize=0; /* initial size of y */
StartData.Length = sizeof(StartData); /* length of data structure in bytes */
pStartData = &StartData;
StartData.PgmInputs = (PSZ)&start_sess_args;
rc = DosStartSession(pStartData, &SessID, &PID);
/* Quit if JUMP.EXE could not be started */
if(rc)
{
WinMessageBox (HWND_DESKTOP,HWND_DESKTOP,
"Place JUMP.EXE in a sub-directory on your PATH",
"JUMP.EXE could not be found",
0,MB_OK | MB_ERROR);
WinPostMsg(hwnd,WM_CLOSE,0L,0L);
}
WinSetHook( hab,
(HMQ)NULL, /* set hook to capture*/
HK_INPUT, /* input messages for filtering.*/
pfnInputHook,
hmodule );
}
}
break;
}
case WM_COMMAND:
switch ( COMMANDMSG( &msg )->cmd )
{
case IDM_ABOUT:
WinDlgBox( HWND_DESKTOP, hwnd, AboutDlgProc, NUL, IDD_ABOUT, NUL );
return( (MRESULT)TRUE );
break;
break;
}
case WM_CONTROL:
if( (SHORT1FROMMP(mp1) != IDCB_JUMPSW) /* Only care about CLICK */
|| (SHORT2FROMMP(mp1) != BN_CLICKED) ) /* Check Box messages. */
break;
usCheckedState /* Query if check box is*/
= SHORT1FROMMR( WinSendDlgItemMsg( hwnd, /* set or not after */
IDCB_JUMPSW,
BM_QUERYCHECK, /* activity in the check*/
(MPARAM)NULL, /* box. */
(MPARAM)NULL ) );
if( usCheckedState == 1 )
{
WinSetHook( hab, /* Check box is checked so make */
(HMQ)NULL, /* sure hook is "set" to capture*/
HK_INPUT, /* input messages for filtering.*/
pfnInputHook,
hmodule );
}
else
{
WinReleaseHook( hab, /* Check box is not checked so */
(HMQ)NULL, /* make sure hook is not "set" */
HK_INPUT, /* so input messages are not */
pfnInputHook, /* intercepted by the hook */
hmodule ); /* procedure. */
}
break;
case WM_ERASEBACKGROUND:
return( (MRESULT)TRUE );
break;
case WM_MINMAXFRAME:
{
PSWP pswp; /* pos change structure */
/* hide check box when minimized so it doesn't overwrite icon */
pswp = PVOIDFROMMP( mp1 );
WinShowWindow(
WinWindowFromID( hwnd, IDCB_JUMPSW ),
!(pswp->fs & SWP_MINIMIZE)
);
}
break;
}
return( WinDefDlgProc( hwnd, msg, mp1, mp2 ) );
}
/*
* AboutDlgProc( hwndDlg, usMsg, mp1, mp2 ) : MRESULT;
*
* hwndDlg handle to dialog box
* usMsg message number
* mp1 message parameter 1
* mp2 message parameter 2
*
* This is the dialog procedure for the About dialog box.
*
*/
MRESULT EXPENTRY AboutDlgProc( HWND hwndDlg, USHORT usMsg, MPARAM mp1, MPARAM mp2 )
{
MRESULT mresRtnVal; /* function return value */
BOOL fPassToDef; /* pass to def dlg proc? */
mresRtnVal = FALSE;
fPassToDef = FALSE;
switch ( usMsg ) {
case WM_INITDLG:
break;
case WM_COMMAND:
switch ( COMMANDMSG( &usMsg )->cmd ) {
case DID_OK:
WinDismissDlg( hwndDlg, TRUE );
break;
default:
fPassToDef = TRUE;
break;
}
break;
default:
fPassToDef = TRUE;
break;
}
if ( fPassToDef )
mresRtnVal = WinDefDlgProc( hwndDlg, usMsg, mp1, mp2 );
return mresRtnVal;
}
/* Exit List processing at program termination */
VOID APIENTRY ProgramTermination( )
{
if( hmodule != (HMODULE)NULL ) /* Unfortunately does not free the */
DosFreeModule( hmodule ); /* DLL because System Input Queue */
/* hooks cannot be freed. */
DosCloseSem( hsemJump ); /* Close the Jump indicator sem */
/* jump.exe closes the die sem */
DosExitList( EXLST_EXIT, /* Required to end ExitList process.*/
(PFNEXITLIST)ProgramTermination );
}