Category : OS/2 Files
Archive   : PMHPENV.ZIP
Filename : PMHPENV.C
/*
* OS/2 Presentation Manager HP LaserJet Envelope Printing Program
*
* Dave Briccetti & Associates CompuServe: 74475,1072
* P.O. Box 1713
* Lafayette, CA 94549-7013
* USA
*
* Copyright (c) 1990, David C. Briccetti
*
* See the extended help in the program for more information.
*/
#include
#include
#include
#include
#include
#include
#define INCL_WINDIALOGS
#define INCL_WINFRAMEMGR
#define INCL_WINHELP
#define INCL_WINMESSAGEMGR
#define INCL_WINMENUS
#define INCL_WINMLE
#define INCL_WINRECTANGLES
#define INCL_WINSHELLDATA
#define INCL_WINSYS
#define INCL_WINWINDOWMGR
#include
#include "pmenv.h"
#define OUTSTREAM stdprn
#define MLE_BUFSIZE 2000
static HAB hab;
static HWND hwndHelpInstance;
static MRESULT EXPENTRY
DlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2);
static ULONG
GetAllText (HWND hwnd, USHORT idMle, USHORT cbBuf);
static ULONG
SetAllText (HWND hwnd, USHORT idMle, ULONG cbCopy);
static VOID PrintEnvelope (HWND hwnd, USHORT idAddr,
USHORT idRetAddr, PBYTE pabBufAddr, PBYTE pabBufRetAddr);
static HWND InitializeHelp (HAB hab, HWND hwndFrame);
static MRESULT ProcessHmMessages (HWND hwndHelpInstance,
USHORT msg, MPARAM mp1, MPARAM mp2);
static VOID CenterDlgBox( HWND hwnd );
static VOID SetSystemMenu( HWND hwndDlg );
/* ----------------------------------------------------------------- */
VOID main (VOID)
{
HMQ hmq;
QMSG qmsg;
HWND hwndDlg;
hab = WinInitialize (0);
hmq = WinCreateMsgQueue (hab, DEFAULT_QUEUE_SIZE);
hwndDlg = WinLoadDlg (HWND_DESKTOP, HWND_DESKTOP,
DlgProc, 0, DID_DLG, 0);
hwndHelpInstance = InitializeHelp (hab, hwndDlg);
while (WinGetMsg (hab, &qmsg, 0, 0, 0))
WinDispatchMsg (hab, &qmsg);
if (hwndHelpInstance)
WinDestroyHelpInstance (hwndHelpInstance);
WinDestroyMsgQueue (hmq);
WinTerminate (hab);
}
/* ----------------------------------------------------------------- */
static MRESULT EXPENTRY
DlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
{
static PBYTE pabBufAddr;
static PBYTE pabBufRetAddr;
ULONG cbData;
switch (msg)
{
case WM_INITDLG:
{
HWND hwndStamp;
RECTL rclStamp;
SWP swpEnvelope;
/* Make cosmetic changes to dialog box */
CenterDlgBox (hwnd);
SetSystemMenu (hwnd);
/* Place stamp in upper right corner of envelope */
WinQueryWindowRect (hwndStamp =
WinWindowFromID (hwnd, DID_STAMP),
&rclStamp);
WinQueryWindowPos (
WinWindowFromID (hwnd, DID_ENVELOPE),
&swpEnvelope);
WinSetWindowPos (hwndStamp, 0,
(SHORT) (swpEnvelope.x +
swpEnvelope.cx - (rclStamp.xRight * 6 / 5)),
(SHORT) (swpEnvelope.y +
swpEnvelope.cy - (rclStamp.yTop * 6 / 5)),
0, 0, SWP_MOVE);
/* Allocate MLE buffers and assign them to MLE controls */
pabBufAddr = halloc (MLE_BUFSIZE, sizeof (BYTE));
pabBufRetAddr = halloc (MLE_BUFSIZE, sizeof (BYTE));
WinSendDlgItemMsg (hwnd, DID_ADDR,
MLM_SETIMPORTEXPORT, MPFROMP (pabBufAddr),
MPFROMSHORT (MLE_BUFSIZE));
WinSendDlgItemMsg (hwnd, DID_RETURN_ADDR,
MLM_SETIMPORTEXPORT, MPFROMP (pabBufRetAddr),
MPFROMSHORT (MLE_BUFSIZE));
/* Retrieve saved data from user profile */
cbData = MLE_BUFSIZE;
if (PrfQueryProfileData (HINI_USERPROFILE,
"PMHPENV", "Address", pabBufAddr, &cbData))
SetAllText (hwnd, DID_ADDR, cbData);
cbData = MLE_BUFSIZE;
if (PrfQueryProfileData (HINI_USERPROFILE, "PMHPENV",
"ReturnAddress", pabBufRetAddr, &cbData))
SetAllText (hwnd, DID_RETURN_ADDR, cbData);
return 0;
}
case WM_COMMAND:
switch (SHORT1FROMMP (mp1))
{
case DID_SAVE:
/* Save address in profile */
cbData = GetAllText (hwnd, DID_ADDR,
MLE_BUFSIZE);
PrfWriteProfileData (HINI_USERPROFILE,
"PMHPENV", "Address", pabBufAddr, cbData);
break;
case DID_SAVE_RET:
/* Save return address in profile */
cbData = GetAllText (hwnd, DID_RETURN_ADDR,
MLE_BUFSIZE);
PrfWriteProfileData (HINI_USERPROFILE, "PMHPENV",
"ReturnAddress", pabBufRetAddr, cbData);
break;
case DID_PRINT:
PrintEnvelope (hwnd, DID_ADDR,
DID_RETURN_ADDR, pabBufAddr,
pabBufRetAddr);
break;
case DID_CANCEL:
WinPostMsg (hwnd, WM_CLOSE, 0L, 0L);
break;
}
break;
case WM_CLOSE:
WinPostMsg (0, WM_QUIT, 0L, 0L);
WinDestroyWindow (hwnd);
hfree (pabBufAddr);
hfree (pabBufRetAddr);
break;
case HM_ERROR:
return ProcessHmMessages (hwndHelpInstance,
msg, mp1, mp2);
default:
return WinDefDlgProc (hwnd, msg, mp1, mp2);
}
return (MRESULT) 0;
}
/* ----------------------------------------------------------------- */
static ULONG
GetAllText (HWND hwnd, USHORT idMle, USHORT cbBuf)
{
/*
* Export text from MLE
*/
ULONG lOffset = 0;
ULONG cbCopy = cbBuf;
ULONG cbText;
cbText = LONGFROMMR (WinSendDlgItemMsg (hwnd, idMle,
MLM_QUERYTEXTLENGTH, 0, 0));
return WinSendDlgItemMsg (hwnd, idMle,
MLM_EXPORT, MPFROMP (&lOffset), MPFROMP (&cbCopy)) ?
cbText : 0;
}
/* ----------------------------------------------------------------- */
static ULONG
SetAllText (HWND hwnd, USHORT idMle, ULONG cbCopy)
{
/*
* Export text to MLE
*/
ULONG lOffset = 0;
return LONGFROMMR (WinSendDlgItemMsg (hwnd, idMle,
MLM_IMPORT, MPFROMP (&lOffset),
MPFROMP (&cbCopy)));
}
/* ----------------------------------------------------------------- */
static VOID PrintEnvelope (HWND hwnd, USHORT idAddr,
USHORT idRetAddr, PBYTE pabBufAddr, PBYTE pabBufRetAddr)
{
/*
* Print Envelope
*/
FILE *pfPrint;
static PSZ pszTempTemplate = "HPPXXXXX";
CHAR szTempFilename [9];
CHAR szCommand [40];
ULONG cbData;
/* Export MLE data to buffers */
cbData = GetAllText (hwnd, idRetAddr,
MLE_BUFSIZE);
pabBufRetAddr [cbData] = 0;
cbData = GetAllText (hwnd, idAddr,
MLE_BUFSIZE);
pabBufAddr [cbData] = 0;
/* Set up temporary print file */
strcpy (szTempFilename, pszTempTemplate);
mktemp (szTempFilename);
pfPrint = fopen (szTempFilename, "w");
if (! pfPrint)
{
WinMessageBox (HWND_DESKTOP, HWND_DESKTOP,
"Can not open temporary print file",
"Printing Error", 1, MB_OK | MB_MOVEABLE);
return;
}
/* Print return address */
fprintf( pfPrint,
"\x01b" "E\x1b&l1O\x1b&l3H\x1b&l15E" );
fprintf( pfPrint, "\x1b&a1r&a15L" );
fprintf( pfPrint, pabBufRetAddr );
/* Print address */
fprintf( pfPrint, "\x1b&a11R" ); /* Line position */
fprintf( pfPrint, "\x1b&a58L" ); /* Column position */
fprintf( pfPrint, pabBufAddr );
fprintf( pfPrint, "\f\x01b" "E" );
/* Close temp file, copy to prn and delete */
fclose (pfPrint);
sprintf (szCommand, "copy %s prn", szTempFilename);
system (szCommand);
unlink (szTempFilename);
}
/* ----------------------------------------------------------------- */
static HWND InitializeHelp (HAB hab, HWND hwndFrame)
{
HELPINIT hmiHelpData; /* Help initialization structure */
HWND hwndHelpInstance;
CHAR szMsg[100];
memset (&hmiHelpData, 0, sizeof (HELPINIT));
hmiHelpData.cb = sizeof (HELPINIT);
hmiHelpData.phtHelpTable = (PVOID) (0xffff0000 | DID_DLG);
hmiHelpData.pszHelpWindowTitle = "Print Envelope Help Window";
hmiHelpData.pszHelpLibraryName = "PMHPENV.HLP";
hwndHelpInstance = WinCreateHelpInstance (hab, &hmiHelpData);
if (hwndHelpInstance && hmiHelpData.ulReturnCode)
{
WinDestroyHelpInstance (hwndHelpInstance);
hwndHelpInstance = 0;
}
if (!hwndHelpInstance)
{
sprintf (szMsg, "WinCreateHelpInstance failed, rc = %lx. "
"Program will continue without help.",
hmiHelpData.ulReturnCode);
WinMessageBox (HWND_DESKTOP, HWND_DESKTOP, szMsg,
(PSZ) "Help Creation Error", 1,
MB_OK | MB_APPLMODAL | MB_MOVEABLE);
}
else
WinAssociateHelpInstance (hwndHelpInstance, hwndFrame);
return hwndHelpInstance;
}
/* ----------------------------------------------------------------- */
static MRESULT ProcessHmMessages (HWND hwndHelpInstance,
USHORT msg, MPARAM mp1, MPARAM mp2)
{
switch (msg)
{
case HM_ERROR:
if (hwndHelpInstance && LONGFROMMP(mp1) == HMERR_NO_MEMORY)
{
WinMessageBox (HWND_DESKTOP, HWND_DESKTOP,
(PSZ) "Help Terminated Due to Error",
(PSZ) "Help Error",
1,
MB_OK | MB_APPLMODAL | MB_MOVEABLE);
WinDestroyHelpInstance (hwndHelpInstance);
}
else
{
CHAR szMsg[ 50 ];
sprintf (szMsg, "Help Error %lx Occurred",
LONGFROMMP (mp1));
WinMessageBox (HWND_DESKTOP, HWND_DESKTOP,
szMsg, "Help Error", 0,
MB_OK | MB_APPLMODAL | MB_MOVEABLE);
}
return (MRESULT) 0;
}
return (MRESULT) 0;
}
/*********************************************************************/
/* */
/* FUNCTION : CenterDlgBox */
/* */
/* Positions the dialog box in the center of the screen */
/* */
/*********************************************************************/
static VOID CenterDlgBox( HWND hwnd )
{
SHORT ix, iy;
SHORT iwidth, idepth;
SWP swp;
/* Query width and depth of screen device */
iwidth = (SHORT)WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );
idepth = (SHORT)WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );
/* Query width and depth of dialog box */
WinQueryWindowPos( hwnd, (PSWP)&swp );
/* Center dialog box within the screen */
ix = ( iwidth - swp.cx ) / 2;
iy = ( idepth - swp.cy ) / 2;
WinSetWindowPos( hwnd, HWND_TOP, ix, iy, 0, 0, SWP_MOVE );
}
/*********************************************************************/
/* */
/* FUNCTION: SetSystemMenu */
/* */
/* Edit items in the system menu to leave "Move", "Close", and */
/* "Switch to Task Manager". */
/* */
/*********************************************************************/
static VOID SetSystemMenu( HWND hwndDlg )
{
HWND hwndSysMenu; /* sys menu pull-down handle */
MENUITEM miTemp; /* menu item template */
SHORT sItemId; /* system menu item ID */
SHORT sItemIndex; /* system menu item index */
/*******************************************************************/
/* Get the handle of the system menu pull-down. */
/*******************************************************************/
hwndSysMenu = WinWindowFromID( hwndDlg, FID_SYSMENU );
WinSendMsg( hwndSysMenu,
MM_QUERYITEM,
MPFROM2SHORT( SC_SYSMENU, FALSE ),
MPFROMP( (PSZ)&miTemp ));
hwndSysMenu = miTemp.hwndSubMenu;
/*******************************************************************/
/* Remove all items from the system menu pull-down that are no */
/* longer wanted. */
/*******************************************************************/
for ( sItemIndex = 0, sItemId = 0; sItemId != MIT_ERROR; sItemIndex++)
{
sItemId = SHORT1FROMMR (WinSendMsg( hwndSysMenu,
MM_ITEMIDFROMPOSITION,
MPFROMSHORT( sItemIndex ),
(MPARAM) 0 ));
if ( sItemId != MIT_ERROR &&
sItemId != SC_MOVE &&
sItemId != SC_CLOSE &&
sItemId != SC_TASKMANAGER )
{
WinSendMsg( hwndSysMenu,
MM_DELETEITEM,
MPFROM2SHORT( sItemId, FALSE ),
(MPARAM)NULL );
sItemIndex--;
}
}
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/