home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 8 Other
/
08-Other.zip
/
kwikstik.zip
/
MAIN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-03-25
|
8KB
|
277 lines
/*
* main.c
*
* Written 90-02-28 by John W. Cocula
*/
#define INCL_DOSMODULEMGR
#define INCL_DOSSEMAPHORES
#define INCL_GPICONTROL
#define INCL_WINDIALOGS
#define INCL_WINFRAMEMGR
#define INCL_WINHOOKS
#define INCL_WININPUT
#define INCL_WINMESSAGEMGR
#define INCL_WINPOINTERS
#define INCL_WINSHELLDATA
#define INCL_WINSWITCHLIST
#define INCL_WINSYS
#define INCL_WINWINDOWMGR
#include <os2.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include "main.h"
#include "maindef.h"
/***** Function Prototypes *****/
VOID main( VOID );
static BOOL InitMain( VOID );
static VOID FinalizeMain( VOID );
static BOOL InstallHook( HAB );
static VOID DeinstallHook( HAB );
MRESULT EXPENTRY ClientWndProc( HWND hwnd , USHORT msg, MPARAM mp1, MPARAM mp2 );
/***** Global Data *****/
HAB habMain;
HMQ hmqMain;
HWND hwndFrame, hwndClient, hwndHelp;
CHAR szAppName[] = "KwikStik";
CHAR szKeyName[] = "swpSave";
CHAR szWindowTitle[MAXWINTITLELEN];
HSWITCH hSwitch;
CHAR achMsg[MAXSTRING];
/************************************************************************/
/* MAIN THREAD CODE */
/************************************************************************/
/******************************** main **********************************/
VOID main( VOID )
{
QMSG qmsg;
if (!InitMain())
FinalizeMain();
while (WinGetMsg( habMain, &qmsg, NULL, 0, 0 ))
WinDispatchMsg( habMain, &qmsg );
FinalizeMain();
} /* main */
/******************************* InitMain ******************************/
static BOOL InitMain( VOID )
{
static CHAR szClassName[] = "KwikStik.Main";
ULONG flCreate = FCF_ACCELTABLE | FCF_MENU |
FCF_MINMAX | FCF_SIZEBORDER |
FCF_SYSMENU | FCF_TITLEBAR;
SWCNTRL sw;
SWP swp;
ULONG cbswp = sizeof swp;
RECTL rcl;
if ((habMain = WinInitialize( 0 )) == NULL)
return FALSE;
if ((hmqMain = WinCreateMsgQueue( habMain, 0 )) == NULL)
return FALSE;
if (!WinRegisterClass( habMain, szClassName, ClientWndProc,
CS_SIZEREDRAW, 0 ))
return FALSE;
WinLoadString( habMain, 0, IDS_PROGNAME, MAXWINTITLELEN,
szWindowTitle );
if ((hwndFrame = WinCreateStdWindow( HWND_DESKTOP,
WS_VISIBLE, &flCreate, szClassName, szWindowTitle,
0L, 0, ID_MAIN, &hwndClient )) == NULL)
return FALSE;
WinSetWindowText( hwndFrame, szWindowTitle );
/* See if a saved size exists in OS2.INI. If so, use it. */
if (!PrfQueryProfileData( HINI_USERPROFILE, szAppName, szKeyName,
&swp, &cbswp ))
{
/* Determine centered size and position of frame window. */
WinQueryWindowRect( HWND_DESKTOP, &rcl );
swp.cx = (SHORT)(rcl.xRight / 2);
swp.cy = (SHORT)(rcl.yTop / 2);
swp.x = (SHORT)(rcl.xRight / 2 - swp.cx / 2);
swp.y = (SHORT)(rcl.yTop / 2 - swp.cy / 2);
}
swp.fs = SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW;
swp.hwndInsertBehind = HWND_TOP;
swp.hwnd = hwndFrame;
WinSetMultWindowPos( habMain, &swp, 1 );
/* Add entry to switch list in Task Manager. */
sw.hwnd = hwndFrame;
sw.hwndIcon = NULL;
sw.hprog = NULL;
sw.idProcess = 0;
sw.idSession = 0;
sw.uchVisibility = SWL_VISIBLE;
sw.fbJump = SWL_JUMPABLE;
strcpy( sw.szSwtitle, szWindowTitle );
hSwitch = WinAddSwitchEntry( &sw );
/* Install the system input hook to catch the Shift key. */
if (!InstallHook( habMain ))
{
ErrorMessage( IDS_NODLL );
return FALSE;
}
return TRUE;
} /* InitMain */
/*************************** FinalizeMain *******************************/
static VOID FinalizeMain( VOID )
{
DeinstallHook( habMain );
if (hSwitch) WinRemoveSwitchEntry( hSwitch );
if (hwndFrame) WinDestroyWindow( hwndFrame );
if (hmqMain) WinDestroyMsgQueue( hmqMain );
if (habMain) WinTerminate( habMain );
DosExit( EXIT_PROCESS, 0 );
} /* FinalizeMain */
/****************************** ClientWndProc ***************************/
MRESULT EXPENTRY ClientWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
{
SWP swpSize;
RECTL rcl;
HPS hps;
static SHORT cxClient, cyClient;
static BOOL fObjectCreated = FALSE;
switch (msg) {
case WM_CREATE:
return (MRESULT)FALSE;
case WM_SIZE:
cxClient = SHORT1FROMMP(mp2);
cyClient = SHORT2FROMMP(mp2);
return NULL;
case WM_PAINT:
hps = WinBeginPaint( hwnd, NULL, &rcl );
WinFillRect( hps, &rcl, SYSCLR_WINDOW );
WinQueryWindowRect( hwnd, &rcl );
WinDrawText( hps, strlen( achMsg ), achMsg,
&rcl, SYSCLR_WINDOWTEXT, SYSCLR_WINDOW,
DT_CENTER | DT_VCENTER | DT_WORDBREAK );
WinEndPaint( hps );
return NULL;
case WM_COMMAND:
switch (SHORT1FROMMP(mp1))
{
case IDM_EXITPROG:
WinSendMsg( hwnd, WM_CLOSE, 0L, 0L );
break;
case IDM_ABOUT:
WinDlgBox( HWND_DESKTOP, hwndFrame, WinDefDlgProc, 0,
ID_ABOUT, NULL );
break;
}
return NULL;
case WM_SAVEAPPLICATION:
WinQueryWindowPos( hwndFrame, &swpSize );
PrfWriteProfileData( HINI_USERPROFILE, szAppName, szKeyName,
&swpSize, (ULONG)sizeof swpSize );
break;
case WM_CLOSE:
WinPostMsg( hwnd, WM_QUIT, 0L, 0L );
return NULL;
/* Message from captive thread to main thread to display msg. */
case TM_CAPTURE:
if (PVOIDFROMMP(mp1))
strcpy( achMsg, PVOIDFROMMP(mp1) );
WinInvalidateRect( hwnd, NULL, FALSE );
return NULL;
} /* end switch */
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
} /* ClientWndProc */
/************** Input hook installation/deinstallation *****************/
HMODULE hmodHookDLL;
PFN pfnStickyInputHook;
static BOOL InstallHook( HAB hab )
{
CHAR achFailName[128];
if (DosLoadModule( achFailName, /* failure-name buffer */
sizeof achFailName, /* size of failure buffer */
"STIKHOOK", /* module name */
&hmodHookDLL )) /* address of handle */
return FALSE;
if (DosGetProcAddr( hmodHookDLL, "STICKYINPUTHOOK", &pfnStickyInputHook ))
{
DosFreeModule( hmodHookDLL );
return FALSE;
}
return WinSetHook(hab, /* anchor-block handle */
NULL, /* system queue */
HK_INPUT, /* hook type */
pfnStickyInputHook, /* far pointer to function */
hmodHookDLL); /* module handle for DLL */
}
static VOID DeinstallHook( HAB hab )
{
WinReleaseHook( hab, NULL, HK_INPUT,
pfnStickyInputHook, hmodHookDLL );
DosFreeModule( hmodHookDLL );
}
/*** end of main.c ***/