home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 8 Other
/
08-Other.zip
/
TEST.ZIP
/
TEST.SQC
Wrap
Text File
|
1993-01-04
|
36KB
|
913 lines
#define INCL_WIN
#define INCL_GPI
#define INCL_DOSPROCESS
#include <os2.h> /* PM header file */
#include <stdio.h>
#include <sqlenv.h>
#include <sqlca.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include "edihelp.h" /* Resource symbolic identifiers*/
#define SLEEPTIME 1
#define STRINGLENGTH 100 /* Length of string */
#define APPLWINWIDTH 400 /* Application Window'w width */
#define APPLWINHEIGTH 200 /* Application Window's heigth */
#define ANIMATE WM_USER
/*********************/
/* Global Variables. */
/*********************/
ULONG ulFrameFlags=FCF_TASKLIST | FCF_SIZEBORDER |
FCF_TITLEBAR | FCF_MINMAX |
FCF_SYSMENU | FCF_MENU | FCF_ICON | FCF_ACCELTABLE;
PSZ szWinClass[] = "EDI Window Class";
QMSG qmsg; /* Message from message queue */
HPS hps, hpsMemory;
HAB hab; /* PM anchor block handle */
HDC hdc, hdcMemory;
HWND hwndClient = NULLHANDLE; /* Client area window handle */
HWND hwndFrame = NULLHANDLE; /* Frame window handle */
HWND hwndFetch = NULLHANDLE; /* SQL Fetch window handle */
BITMAPINFOHEADER bmpSrc;
HBITMAP hbmSrc;
CHAR szHello[STRINGLENGTH]; /* String parameters, set in */
CHAR sz2[STRINGLENGTH]; /* and used in the processing */
CHAR sz3[STRINGLENGTH]; /* of WM_COMMAND, in window */
CHAR szString[STRINGLENGTH]; /* procedure. */
PSZ pszErrMsg;
BOOL bFirstTime = TRUE;
SHORT sxPels, syPels;
LONG alBmpFormats[2];
LONG lPointSize;
LONG lcxPelsPerInch, lcyPelsPerInch;
LONG lcxPelsPerMeter, lcyPelsPerMeter;
CHAR sDrvPath[80];
INT rc;
CHAR szRecord[ 74];
EXEC SQL BEGIN DECLARE SECTION;
char szSegId[ 4];
char szSegNm[ 71];
EXEC SQL END DECLARE SECTION;
/***********************/
/* Function prototypes */
/***********************/
MRESULT EXPENTRY EdiHelpMakeProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
MRESULT EXPENTRY DrivePathProc(HWND hwnd, ULONG msg,
MPARAM mp1, MPARAM mp2);
MRESULT EXPENTRY SegFetchProc(HWND hwnd, ULONG msg,
MPARAM mp1, MPARAM mp2);
BOOL FAR FindFont( HPS hps, LONG *lLcid, CHAR *szFontName);
LONG FAR GetSetID( HPS hps);
BOOL FAR SetPtSize( HPS hps, LONG lLcid, LONG lPointSize,
FIXED *width, FIXED *height);
void FAR SetWidthsTable( HPS hps, LONG *alWidths,
LONG *alWidthTable, CHAR *szStr, LONG *lTotal);
SHORT FAR Random_Range( SHORT lower_lim, SHORT upper_lim,
SHORT lower_exc, SHORT upper_exc);
/******************************************/
/* Required IPF Structures For Help Text. */
/******************************************/
HELPINIT hmiHelpData;
HWND hwndHelpInstance;
EXEC SQL INCLUDE SQLCA;
main(int argc, char *argv[], char *envp[])
{
HDC hdcTemp;
HPS hpsTemp;
HMQ hmq; /* Message queue handle */
if ((hab = WinInitialize(0)) == 0L) /* Initialize PM */
AbortHello( hwndFrame, hwndClient); /* Terminate the application */
if ((hmq = WinCreateMsgQueue( hab, 0 )) == 0L)/* Create a msg queue */
AbortHello( hwndFrame, hwndClient); /* Terminate the application */
/*********************************/
/* IPF Initialization Structure. */
/*********************************/
hmiHelpData.cb = sizeof( HELPINIT);
hmiHelpData.ulReturnCode = 0;
hmiHelpData.pszTutorialName = NULL;
hmiHelpData.phtHelpTable = ( PVOID)( 0xffff0000 | MAIN_HELPTABLE);
hmiHelpData.hmodAccelActionBarModule = 0;
hmiHelpData.idAccelTable = 0;
hmiHelpData.idActionBar = 0;
hmiHelpData.pszHelpWindowTitle = ( PSZ)"EDI 3020 Standards Help";
hmiHelpData.hmodHelpTableModule = 0;
hmiHelpData.fShowPanelId = 0;
hmiHelpData.pszHelpLibraryName = ( PSZ)"EDIHELP.HLP";
/***************************/
/* Create instance of IPF. */
/***************************/
/*
hwndHelpInstance = WinCreateHelpInstance( hab, &hmiHelpData);
if( !hwndHelpInstance)
WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
(PSZ)"Help Not Available", (PSZ)"Help Creation Error",
1, MB_OK | MB_APPLMODAL | MB_MOVEABLE);
else {
if( hmiHelpData.ulReturnCode){
WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
(PSZ)"Help Terminated Due to Error",
(PSZ)"Help Creation Error",
1, MB_OK | MB_APPLMODAL | MB_MOVEABLE);
WinDestroyHelpInstance( hwndHelpInstance);
}
}
*/
if (!(rc = WinRegisterClass( /* Register window class */
hab, /* Anchor block handle */
(PSZ)szWinClass, /* Window class name */
(PFNWP)EdiHelpMakeProc, /* Address of window procedure */
CS_SIZEREDRAW, /* Class style */
0 /* No extra window words */
)))
AbortHello(hwndFrame, hwndClient); /* Terminate the application */
if ((hwndFrame = WinCreateStdWindow(
HWND_DESKTOP, /* Desktop window is parent */
WS_VISIBLE, /* STD. window styles */
&ulFrameFlags, /* Frame control flag */
(PSZ)szWinClass, /* Client window class name */
"EDI Make Help Utility", /* Window text */
0, /* No special class style */
(HMODULE)0L, /* Resource is in .EXE file */
ID_WINDOW, /* Frame window identifier */
&hwndClient /* Client window handle */
)) == 0L)
AbortHello(hwndFrame, hwndClient); /* Terminate the application */
WinOpenWindowDC( hwndFrame);
/***************************************************/
/* Resolve the number of pels per inch in both the */
/* horizontal and vertical directions. */
/***************************************************/
hpsTemp = WinGetPS( HWND_DESKTOP);
hdcTemp = GpiQueryDevice( hpsTemp);
if(( hdcTemp != 0L) && ( hdcTemp != HDC_ERROR)){
DevQueryCaps( hdcTemp, CAPS_VERTICAL_RESOLUTION, 1L,
&lcyPelsPerMeter);
DevQueryCaps( hdcTemp, CAPS_HORIZONTAL_RESOLUTION, 1L,
&lcxPelsPerMeter);
lcxPelsPerInch = ( lcxPelsPerMeter * 254) / 10000;
lcyPelsPerInch = ( lcyPelsPerMeter * 254) / 10000;
}
/****************************************************/
/* Set window position to be one half inch to right */
/* and one half inch up. Make the window size */
/* 7 inches by 6 inches. Set input focus. */
/****************************************************/
if( !WinSetWindowPos( hwndFrame, 0L, (SHORT)lcxPelsPerInch / 2,
(SHORT)lcyPelsPerInch / 2, (SHORT)lcxPelsPerInch * 7,
(SHORT)lcyPelsPerInch * 6, SWP_SIZE | SWP_MOVE))
AbortHello( hwndFrame, hwndClient); /* Terminate the application */
WinReleasePS( hpsTemp);
WinSetFocus(HWND_DESKTOP, hwndFrame);
/******************************/
/* Associate instance of IPF. */
/******************************/
if( hwndHelpInstance)
WinAssociateHelpInstance( hwndHelpInstance, hwndFrame);
/**********************************************************************/
/* Get and dispatch messages from the application message queue */
/* until WinGetMsg returns FALSE, indicating a WM_QUIT message. */
/**********************************************************************/
while( WinGetMsg( hab, &qmsg, 0L, 0, 0 ) ){
DosEnterCritSec();
WinDispatchMsg( hab, &qmsg );
DosExitCritSec(); }
if( hwndHelpInstance) WinDestroyHelpInstance( hwndHelpInstance);
WinDestroyWindow( hwndFrame); /* Tidy up... */
WinDestroyMsgQueue( hmq); /* Tidy up... */
WinTerminate( hab); /* Terminate the application */
} /* End of main */
/**************************************************************************
* Name : EdiHelpMakeProc
*************************************************************************/
MRESULT EXPENTRY EdiHelpMakeProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
CHAR szStr1[]="EDI Help Utility";
CHAR szStr2[]="All standards, cross-platform";
CHAR szStr3[]="clear-text searchable EDI Help";
CHAR szStr4[]="(Putting the EDI user in touch)";
LONG lReturn;
POINTL aptl[ 4];
SIZEF sizefxCharBox;
FIXED width, height;
CHAR szFontName[]="Courier";
CHAR szFontName1[]="Times New Roman";
BOOL fRet = FALSE;
BITMAPINFOHEADER2 bmp;
LONG lTotal, lLcid;
HPS hpsd;
float fPitch;
POINTL ptl, shear;
LONG alWidths[80];
LONG alWidthTable[256];
SIZEL sizl;
SHORT x, y, i;
LONG pattern[]={
PATSYM_DEFAULT, PATSYM_DENSE1, PATSYM_DENSE2,
PATSYM_DENSE3, PATSYM_DENSE4, PATSYM_DENSE5,
PATSYM_DENSE6, PATSYM_DENSE7, PATSYM_DENSE8,
PATSYM_NOSHADE};
ULONG flStyle = FCF_SHELLPOSITION;
switch( msg)
{
case WM_CREATE:
hdc = WinOpenWindowDC( hwnd); /* Create window device context. */
sizl.cx = 0; /* Create Micro-PS. Keep as global. */
sizl.cy = 0;
hps = GpiCreatePS( hab, hdc, &sizl, PU_PELS | GPIT_MICRO |
GPIA_ASSOC | GPIF_DEFAULT);
lReturn = WinLoadString( hab, (HMODULE)0L, IDS_HELLO, STRINGLENGTH, szHello );
lReturn = WinLoadString( hab, (HMODULE)0L, IDS_3, STRINGLENGTH, sz3 );
strcpy( szString, szHello ); /* Copy text Hello into szString*/
/********************************************************/
/* Create memory device context for our screen bit-map. */
/********************************************************/
hdcMemory = DevOpenDC( hab, OD_MEMORY, (PSZ)"*", 0L, 0L, 0L);
sizl.cx = 0; /* Create presentation space for screen bit-map. */
sizl.cy = 0;
hpsMemory = GpiCreatePS( hab, hdcMemory, &sizl,
PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);
/*************************************************/
/* Get the screen dimension in pels and save it. */
/*************************************************/
sxPels = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN);
syPels = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN);
/*******************************************/
/* Set up bit-map header for correct size. */
/*******************************************/
GpiQueryDeviceBitmapFormats( hpsMemory, 2L, alBmpFormats);
memset( &bmp, 0, sizeof( bmp));
bmp.cbFix = sizeof bmp;
bmp.cx = sxPels;
bmp.cPlanes = (USHORT)alBmpFormats[0];
bmp.cBitCount = (USHORT)alBmpFormats[1];
bmp.cy = syPels;
hbmSrc = GpiCreateBitmap( hpsMemory, &bmp, 0L, NULL, NULL);
GpiSetBitmap( hpsMemory, hbmSrc);
aptl[0].x = 0; aptl[0].y = 0;
aptl[1].x = bmp.cx; aptl[1].y = bmp.cy;
aptl[2].x = 0; aptl[2].y = 0;
/************************************************/
/* Copy the desktop image to our memory device. */
/************************************************/
hpsd = WinGetScreenPS( HWND_DESKTOP);
GpiBitBlt( hpsMemory, hpsd, 3L, aptl, ROP_SRCCOPY, BBO_AND);
/*********************/
/* Release resource. */
/*********************/
WinReleasePS( hpsd);
return( MRESULT)FALSE;
case WM_COMMAND:
/*
* When the user chooses option 1, 2, or 3 from the Options pull-
* down, the text string is set to 1, 2, or 3, and
* WinInvalidateRegion sends a WM_PAINT message.
* When Exit is chosen, the application posts itself a WM_CLOSE
* message.
*/
{
USHORT command; /* WM_COMMAND command value */
command = SHORT1FROMMP(mp1); /* Extract the command value */
switch (command)
{
case ID_PATH:
rc = WinDlgBox( HWND_DESKTOP, hwnd, DrivePathProc, 0, ID_PATH, &sDrvPath);
WinInvalidateRegion( hwnd, 0L, FALSE );
return(( MRESULT) TRUE);
case ID_DBFETCH:
if (!(rc = WinRegisterClass( /* Register window class */
hab, /* Anchor block handle */
(PSZ)szWinClass, /* Window class name */
(PFNWP)SegFetchProc, /* Address of window procedure */
CS_SIZEREDRAW, /* Class style */
0 /* No extra window words */
)))
AbortHello( hwndFrame, hwndClient); /* Terminate the application */
hwndFrame = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE, &flStyle,
(PSZ)szWinClass, "", 0L, (HMODULE)0, ID_FETCHWINDOW,
&hwndFetch);
WinSetFocus( HWND_DESKTOP, hwndFetch);
EXEC SQL WHENEVER SQLERROR GO TO ext;
EXEC SQL WHENEVER NOT FOUND GO TO cls;
EXEC SQL DECLARE c1 CURSOR FOR
SELECT SegId, SegNm FROM Standrds.X31SegHdx;
EXEC SQL OPEN c1;
do
{
EXEC SQL FETCH c1 INTO :szSegId, :szSegNm;
strcpy( szRecord, szSegId);
strcat( szRecord, szSegNm);
printf( "%s\n", szRecord);
} while ( 1);
cls:
EXEC SQL CLOSE c1;
ext:
if( SQLCODE != 0)
printf( "Error: SQLCODE = %d.\n", SQLCODE);
EXEC SQL WHENEVER SQLERROR CONTINUE;
printf( "\nFinished Test Select.");
sqlestpd( &sqlca);
if( SQLCODE != 0)
printf( "\nStop DB Error: SQLCODE = %d", SQLCODE);
WinInvalidateRegion( hwnd, 0L, FALSE );
break;
case ID_OPTION3:
strcpy( szString, sz3 );
WinInvalidateRegion( hwnd, 0L, FALSE );
break;
case ID_EXITPROG:
WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
break;
}
case WM_ERASEBACKGROUND:
/*
* Return TRUE to request PM to paint the window background
* in SYSCLR_WINDOW.
*/
return (MRESULT)( TRUE );
case WM_PAINT:
/*
* Window contents are drawn here in WM_PAINT processing.
*/
if ( bFirstTime) {
bFirstTime = FALSE;
WinSendMsg( hwnd, ANIMATE, NULL, NULL);
} else {
HPS hps; /* Presentation Space handle */
RECTL rc; /* Rectangle coordinates */
POINTL pt; /* String screen coordinates */
/* Create a presentation space */
hps = WinBeginPaint( hwnd, 0L, &rc);
WinDrawText( hps, (LONG) strlen( szString), szString, &rc, 0L, 0L,
DT_CENTER | DT_VCENTER | DT_TEXTATTRS | DT_ERASERECT);
WinEndPaint( hps ); } /* Drawing is complete */
return (MRESULT)TRUE;
case ANIMATE:
/*****************************************************/
/* Reset presentation spaces, then get it again and */
/* animate with shearing. */
/*****************************************************/
WinSetPointer( HWND_DESKTOP,
WinQuerySysPointer( HWND_DESKTOP, SPTR_WAIT, FALSE));
GpiResetPS( hps, GRES_ALL);
GpiResetPS( hpsMemory, GRES_ALL);
/*********************************/
/* Clear out presentation page. */
/*********************************/
aptl[0].x = 0; /* Target lower-left */
aptl[0].y = 0;
aptl[1].x = sxPels; /* Target upper-right */
aptl[1].y = syPels;
GpiBitBlt( hps, hps, 2L, aptl, ROP_ZERO, BBO_AND);
GpiBitBlt(hpsMemory, hpsMemory, 2L, aptl, ROP_ZERO, BBO_AND);
/*****************************************************/
/* Look for font by name else find any outline font. */
/*****************************************************/
if( !FindFont( hpsMemory, &lLcid, szFontName1))
FindFont( hpsMemory, &lLcid, NULL);
lPointSize = 30; /* Set font to 30 points. */
fRet = SetPtSize( hpsMemory, lLcid, lPointSize, &width, &height);
if( fRet){
sizefxCharBox.cy = height;
sizefxCharBox.cx = width;
}
fRet = GpiSetCharBox( hpsMemory, &sizefxCharBox);
/******************************************************/
/* Set color and shear for memory presentation space. */
/* Then put all text in this presentation page. */
/******************************************************/
GpiSetColor( hpsMemory, CLR_CYAN);
shear.x = 10; shear.y = 25;
GpiSetCharShear( hpsMemory, &shear);
SetWidthsTable( hpsMemory, alWidths,
alWidthTable, szStr1, &lTotal);
ptl.x = (( 7 * lcxPelsPerInch) - lTotal)/2; /* Center text 4 */
ptl.y = lcyPelsPerInch * 4; /* inches from bottom */
GpiMove( hpsMemory, &ptl);
GpiCharStringPos( hpsMemory, NULL, CHS_VECTOR,
(LONG)strlen( szStr1), (PSZ)szStr1, alWidths);
/***************************************************/
/* Change point size of font and get rid of shear. */
/***************************************************/
lPointSize = 18;
fRet = SetPtSize( hpsMemory, lLcid, lPointSize, &width, &height);
if( fRet){
sizefxCharBox.cy = height;
sizefxCharBox.cx = width;
}
fRet = GpiSetCharBox( hpsMemory, &sizefxCharBox);
shear.x = 0; shear.y = 1;
GpiSetCharShear( hpsMemory, &shear);
/************************************************************/
/* Center next 2 lines of text in memory presentation page. */
/************************************************************/
SetWidthsTable( hpsMemory, alWidths,
alWidthTable, szStr2, &lTotal);
ptl.x = (( 7 * lcxPelsPerInch) - lTotal)/2; /* Center text */
ptl.y = lcyPelsPerInch * 3; /* 3 inches from bottom */
GpiMove( hpsMemory, &ptl);
GpiCharStringPos( hpsMemory, NULL, CHS_VECTOR,
(LONG)strlen( szStr2), (PSZ)szStr2, alWidths);
SetWidthsTable( hpsMemory, alWidths,
alWidthTable, szStr3, &lTotal);
ptl.x = ((7 * lcxPelsPerInch) - lTotal)/2; /* Center text */
ptl.y = lcyPelsPerInch * 2.5; /* 2.5 inches from bottom */
GpiMove( hpsMemory, &ptl);
GpiCharStringPos( hpsMemory, NULL, CHS_VECTOR,
(LONG)strlen( szStr3), (PSZ)szStr3, alWidths);
/*********************************************/
/* Change color and center last */
/* line of text in memory presentation page. */
/*********************************************/
GpiSetColor( hpsMemory, CLR_YELLOW);
SetWidthsTable( hpsMemory, alWidths,
alWidthTable, szStr4, &lTotal);
ptl.x = ((7 * lcxPelsPerInch) - lTotal)/2; /* Center text */
ptl.y = lcyPelsPerInch * 1.75; /* 1 inches from bottom */
GpiMove( hpsMemory, &ptl);
GpiCharStringPos( hpsMemory, NULL, CHS_VECTOR,
(LONG)strlen( szStr4), (PSZ)szStr4, alWidths);
/******************************************/
/* Fade in top 3 text lines with Bit Blt. */
/******************************************/
aptl[0].x = 0; aptl[0].y = lcyPelsPerInch * 2;
aptl[1].x = lcxPelsPerInch * 7; aptl[1].y = lcyPelsPerInch * 5;
aptl[2].x = 0; aptl[2].y = lcyPelsPerInch * 2;
for( x = 1; x < 10; x++){
GpiSetPattern( hps, pattern[x]);
GpiBitBlt( hps, hpsMemory, 3L, aptl, ROP_MERGECOPY, BBO_AND);
DosSleep( SLEEPTIME);
}
DosSleep( 2500); /* Wait 2.5 seconds. */
/****************************************/
/* Fade in last text line with Bit Blt. */
/****************************************/
aptl[0].x = 0; aptl[0].y = lcyPelsPerInch * .5;
aptl[1].x = lcxPelsPerInch * 7; aptl[1].y = lcyPelsPerInch * 2;
aptl[2].x = 0; aptl[2].y = lcyPelsPerInch * .5;
for( x = 1; x < 10; x++){
GpiSetPattern( hps, pattern[x]);
GpiBitBlt( hps, hpsMemory, 3L, aptl, ROP_MERGECOPY, BBO_AND);
DosSleep( SLEEPTIME);
}
DosSleep( 3000); /* Wait 3 seconds */
/***********************************************/
/* Fade out all text from screen with Bit Blt. */
/***********************************************/
aptl[0].x = 0; aptl[0].y = lcyPelsPerInch * .5;
aptl[1].x = lcxPelsPerInch * 7; aptl[1].y = lcyPelsPerInch * 5;
aptl[2].x = 0; aptl[2].y = lcyPelsPerInch * .5;
for( x = 9; x > 1; x--){
GpiSetPattern( hps, pattern[x]);
GpiBitBlt( hps, hpsMemory, 3L, aptl, ROP_MERGECOPY, BBO_AND);
DosSleep( SLEEPTIME);
}
/***********************************/
/* Get master bit-map from memory. */
/***********************************/
GpiResetPS( hpsMemory, GRES_ALL);
GpiQueryBitmapParameters( hbmSrc, &bmpSrc);
GpiSetBitmap( hpsMemory, hbmSrc);
/***************************************/
/* Clear out screen presentation page. */
/***************************************/
aptl[0].x = 0; aptl[0].y = 0;
aptl[1].x = sxPels; aptl[1].y = syPels;
GpiBitBlt( hps, hps, 2L, aptl, ROP_ZERO, BBO_AND);
DosSleep( 500); /* Wait .5 seconds. */
/************************************************/
/* Randomly blt in tenth inch squares of master */
/* bit-map. Do 8000 squares then stop. */
/************************************************/
for( i = 0; i < 8000; i++){
aptl[0].x = Random_Range( 0,
( 7 * lcxPelsPerInch) - ( lcxPelsPerInch / 10), 0, 0);
aptl[0].y = Random_Range( 0,
( 6 * lcyPelsPerInch) - ( lcyPelsPerInch / 10), 0, 0);
aptl[1].x = aptl[0].x + ( lcxPelsPerInch / 7);
aptl[1].y = aptl[0].y + ( lcyPelsPerInch / 7);
aptl[2].x = aptl[0].x; aptl[2].y = aptl[0].y;
GpiBitBlt( hps, hpsMemory, 3L, aptl, ROP_SRCCOPY, BBO_AND);
}
WinInvalidateRect( hwnd, NULL, FALSE); /* Cause full paint. */
WinSetPointer( HWND_DESKTOP,
WinQuerySysPointer( HWND_DESKTOP, SPTR_APPICON, FALSE));
return (MRESULT)TRUE;
case WM_CLOSE:
/*
* This is the place to put your termination routines
*/
WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );/* Cause termination*/
break;
default:
/*
* Everything else comes here. This call MUST exist
* in your window procedure.
*/
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
return (MRESULT)FALSE;
} /* End of EdiHelpMakeProc */
/**************************************************************************
* Name : AbortHello
*************************************************************************/
VOID AbortHello(HWND hwndFrame, HWND hwndClient)
{
PERRINFO pErrInfoBlk;
PSZ pszOffSet;
void stdprint(void);
DosBeep(100,10);
if ((pErrInfoBlk = WinGetErrorInfo(hab)) != (PERRINFO)NULL)
{
pszOffSet = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
pszErrMsg = ((PSZ)pErrInfoBlk) + *((PSHORT)pszOffSet);
if((INT)hwndFrame && (INT)hwndClient)
WinMessageBox(HWND_DESKTOP, /* Parent window is desk top */
hwndFrame, /* Owner window is our frame */
(PSZ)pszErrMsg, /* PMWIN Error message */
"Error Msg", /* Title bar message */
MSGBOXID, /* Message identifier */
MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL ); /* Flags */
WinFreeErrorInfo(pErrInfoBlk);
}
WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
} /* End of AbortHello */
/*************************************/
/* Random number in range function. */
/*************************************/
SHORT FAR Random_Range( SHORT lower_lim, SHORT upper_lim,
SHORT lower_exc, SHORT upper_exc)
{
int i;
getrand:
i = ((((double)rand()) / 32767) * ( upper_lim - lower_lim)) + lower_lim;
if( i >= lower_exc && i <= upper_exc)
goto getrand;
return( i);
}
/******************************/
/* Get a set ID for our font. */
/******************************/
LONG FAR GetSetID( HPS hps)
{
#define MAXSETID 254L
INT i;
LONG lLcid = GPI_ERROR;
LONG lCount;
BOOL fRet = FALSE;
PLONG alLcids = NULL;
PLONG alTypes;
PSTR8 aNames;
/************************************************/
/* See if any local set IDs have been used yet. */
/************************************************/
lCount = GpiQueryNumberSetIds( hps);
if(lCount == 0)
return( 1L);
/***********************************/
/* Find first unused local set ID. */
/***********************************/
if( lCount != GPI_ALTERROR){
alLcids = malloc((SHORT)( 16 * lCount));
alTypes = (PLONG)( alLcids + lCount);
aNames = (PSTR8)( alTypes + lCount);
if( alLcids != NULL)
fRet = GpiQuerySetIds( hps, lCount, alTypes, aNames, alLcids);
if( fRet){
for( lLcid = 1; lLcid < (MAXSETID + 1); lLcid++){
for( i = 0; (i < (INT)lCount) && ( alLcids[i] != lLcid); i++);
if( i == (INT)lCount) break;
}
if( lLcid == MAXSETID + 1) lLcid = GPI_ERROR;
}
free( alLcids);
}
return( lLcid);
}
/************************************/
/* Set point size for outline font. */
/************************************/
BOOL FAR SetPtSize( HPS hps, LONG lLcid, LONG lPointSize,
FIXED *width, FIXED *height)
{
#define POINTSPERINCH 72L
HDC hdc;
BOOL fRet = FALSE;
LONG lYDevResFont;
POINTL aptlPoints[2];
LONG lYSizeInPels;
LONG lYSizeInWC;
/*******************************************/
/* Query current font vertical resolution. */
/*******************************************/
hdc = GpiQueryDevice( hps);
DevQueryCaps( hdc, CAPS_VERTICAL_FONT_RES, 1L, &lYDevResFont);
/**********************************************************/
/* Calculate point size and convert to world coordinates. */
/**********************************************************/
lYSizeInPels = (( lYDevResFont * lPointSize)/POINTSPERINCH);
aptlPoints[0].x = 0L; aptlPoints[0].y = 0L;
aptlPoints[1].x = 0L; aptlPoints[1].y = lYSizeInPels;
GpiConvert( hps, CVTC_DEVICE, CVTC_WORLD, 2L, aptlPoints) ;
lYSizeInWC = aptlPoints[1].y-aptlPoints[0].y;
/********************************************************/
/* Set the font for the presentation space and make the */
/* width and height value type fixed. */
/********************************************************/
fRet = GpiSetCharSet( hps, lLcid);
*width = lYSizeInWC * 0x10000;
*height = lYSizeInWC * 0x10000;
return( fRet);
}
/************************************************/
/* Set width table and calculate string length. */
/************************************************/
void FAR SetWidthsTable(HPS hps, LONG *alWidths,
LONG *alWidthTable, CHAR *szStr, LONG *lTotal)
{
FONTMETRICS fm;
PKERNINGPAIRS akpairs = NULL;
LONG i, j;
/*******************************************/
/* Get width table for all 256 codepoints. */
/*******************************************/
GpiQueryWidthTable( hps, 0L, 256L, alWidthTable);
/**************************************************/
/* Check for kerning font and get pair if needed. */
/**************************************************/
GpiQueryFontMetrics( hps, (LONG)sizeof( FONTMETRICS), &fm);
if( fm.sKerningPairs){
akpairs = malloc( fm.sKerningPairs * sizeof( KERNINGPAIRS));
GpiQueryKerningPairs( hps, fm.sKerningPairs, akpairs);
}
/***********************************************************/
/* Set widths for each character in string before kerning. */
/***********************************************************/
for( i=0; i < (LONG)strlen( szStr); i++)
alWidths[i] = alWidthTable[ szStr[i]];
/*************************************************/
/* Modify widths array with kerning adjustments. */
/*************************************************/
if( fm.sKerningPairs){
for( i=0; i < (LONG)strlen( szStr); i++){
for( j = 0; j < fm.sKerningPairs; j++){
if( szStr[i] == (UCHAR)akpairs[j].sFirstChar &&
szStr[i+1] == (UCHAR)akpairs[j].sSecondChar){
alWidths[i] += akpairs[j].lKerningAmount;
break;
}
}
}
}
if( fm.sKerningPairs) free( akpairs); /* Free kerning values. */
/*********************************/
/* Calculate total string width. */
/*********************************/
*lTotal = 0;
for( i=0; i < (LONG)strlen( szStr); i++)
*lTotal = *lTotal + alWidths[i];
return;
}
/******************************/
/* Find outline font by name. */
/******************************/
BOOL FAR FindFont( HPS hps, LONG *lLcid, CHAR *szFontName)
{
PFONTMETRICS afmMetrics = NULL;
LONG lNumFonts, lReqFonts, i, lRemFonts = GPI_ALTERROR;
BOOL fRet = FALSE;
HDC hdc = 0L;
USHORT usCodepage = GPI_ERROR;
FATTRS fatAttrs;
/*********************************************************/
/* Query number of public fonts known by PM and allocate */
/* memory in which to read their metrics information. */
/*********************************************************/
lReqFonts = 0;
if( szFontName != NULL)
lNumFonts = GpiQueryFonts( hps, QF_PUBLIC, (PSZ)szFontName, &lReqFonts,
0L, NULL);
else lNumFonts = GpiQueryFonts( hps, QF_PUBLIC, NULL, &lReqFonts,
0L, NULL);
/*********************************************/
/* Get memory for font metrics if any exist. */
/*********************************************/
if(( lNumFonts != GPI_ALTERROR) && ( lNumFonts != 0L))
afmMetrics = malloc((SHORT)( lNumFonts * sizeof( FONTMETRICS)));
/**************************************/
/* Query font information into array. */
/**************************************/
if( afmMetrics != NULL)
if( szFontName != NULL)
lRemFonts = GpiQueryFonts( hps, QF_PUBLIC, (PSZ)szFontName,
&lNumFonts, (LONG)sizeof( FONTMETRICS), afmMetrics);
else
lRemFonts = GpiQueryFonts( hps, QF_PUBLIC, NULL, &lNumFonts,
(LONG)sizeof( FONTMETRICS), afmMetrics);
/******************************************/
/* Search for outline font and create it. */
/******************************************/
if( lRemFonts != GPI_ALTERROR){
for( i=0; i < (INT)lNumFonts; i++){
if( afmMetrics[i].fsDefn & FM_DEFN_OUTLINE){
*lLcid = GetSetID( hps); /* Get a set ID for the font. */
/**********************************/
/* Set the attribute of the font. */
/**********************************/
if( *lLcid != GPI_ERROR) usCodepage = GpiQueryCp( hps);
fatAttrs.usRecordLength = sizeof( FATTRS);
fatAttrs.fsSelection = 0;
fatAttrs.lMatch = 0L;
strcpy( fatAttrs.szFacename, afmMetrics[i].szFacename);
fatAttrs.idRegistry = afmMetrics[i].idRegistry;
fatAttrs.usCodePage = usCodepage;
fatAttrs.lMaxBaselineExt = 0L;
fatAttrs.lAveCharWidth = 0L;
fatAttrs.fsType = 0;
fatAttrs.fsFontUse = ( FATTR_FONTUSE_OUTLINE |
FATTR_FONTUSE_TRANSFORMABLE);
/************************/
/* Create logical font. */
/************************/
if( usCodepage != GPI_ERROR){
fRet = GpiCreateLogFont( hps, NULL,
*lLcid, &fatAttrs) != GPI_ERROR;
}
break ;
}
}
}
if( afmMetrics != NULL) free( afmMetrics); /* Free memory from array. */
return( fRet);
}
/************************************/
/* Drive and Path dialog procedure. */
/************************************/
MRESULT EXPENTRY DrivePathProc(HWND hwnd, ULONG msg,
MPARAM mp1, MPARAM mp2)
{
CHAR sDrvPathTemp[80];
switch( msg) {
/**********************/
/* Initialize dialog. */
/**********************/
case WM_INITDLG:
/* sDrvPathTemp = PVOIDFROMMP( mp2);*/
/* pfwnField1 = WinSubclassWindow(
WinWindowFromID( hwnd, IDD_GRIDEDIT), NumberSubProc1);
pfwnField2=WinSubclassWindow(
WinWindowFromID(hwnd, IDD_TIMEEDIT), NumberSubProc2);
sprintf(szTemp, "%d\0", pnew->sCapTime);
WinSetDlgItemText(hwnd, IDD_TIMEEDIT, (PSZ)szTemp);
sprintf(szTemp, "%d\0", pnew->sGrid);
WinSetDlgItemText(hwnd, IDD_GRIDEDIT, (PSZ)szTemp);
WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, IDD_GRIDEDIT));
*/
return(( MRESULT) TRUE);
/**************************/
/* Process notifications. */
/**************************/
case WM_COMMAND:
switch (COMMANDMSG(&msg)->cmd){
/**************************/
/* Process OK pushbutton. */
/**************************/
/*
case DID_OK:
WinQueryDlgItemText(hwnd, IDD_TIMEEDIT, 5, (PSZ)szTemp);
sTemp=atoi(szTemp);
if((sTemp<1) || (sTemp>60)){
WinMessageBox(HWND_DESKTOP, hwnd,
(PSZ)"Time value needs to be between 1 and 60.",
(PSZ)"New Puzzle", 0,
MB_MOVEABLE | MB_OK | MB_ICONEXCLAMATION);
return(MRESULT)TRUE;
}
pnew->sCapTime=sTemp;
WinQueryDlgItemText(hwnd, IDD_GRIDEDIT, 5, (PSZ)szTemp);
sTemp=atoi(szTemp);
if((sTemp<4) || (sTemp>25)){
WinMessageBox(HWND_DESKTOP, hwnd,
(PSZ)"Grid value needs to be between 4 and 25.",
(PSZ)"New Puzzle", 0,
MB_MOVEABLE | MB_OK | MB_ICONEXCLAMATION);
return(MRESULT)TRUE;
}
pnew->sGrid=sTemp;
WinSubclassWindow(
WinWindowFromID(hwnd, IDD_GRIDEDIT), pfwnField1);
WinSubclassWindow(
WinWindowFromID(hwnd, IDD_TIMEEDIT), pfwnField2);
WinDismissDlg(hwnd, TRUE);
return(MRESULT)TRUE;
*/
/******************************/
/* Process Cancel pushbutton. */
/******************************/
/*
case DID_CANCEL:
WinSubclassWindow(
WinWindowFromID(hwnd, IDD_GRIDEDIT), pfwnField1);
WinSubclassWindow(
WinWindowFromID(hwnd, IDD_TIMEEDIT), pfwnField2);
WinDismissDlg(hwnd, FALSE);
return(MRESULT)TRUE;
*/
}
break;
}
return WinDefDlgProc( hwnd, msg, mp1, mp2);
}
/************************************/
/* fetch segment from DBM procedure. */
/************************************/
MRESULT EXPENTRY SegFetchProc(HWND hwnd, ULONG msg,
MPARAM mp1, MPARAM mp2)
{
switch( msg){
case WM_CREATE:
return((MRESULT) FALSE);
case WM_CLOSE:
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
}
/*********************** End of the EdiHelp.c *******************************/