home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 19 Printer
/
19-Printer.zip
/
PRNT32.ZIP
/
PRNT32.C
< prev
next >
Wrap
Text File
|
1992-07-17
|
11KB
|
287 lines
/**************************************************************************/
/*------------------------------- PRNT32.C -------------------------------*/
/* */
/* PRINTING TEXT TO THE DEFAULT OS/2 2.0 PRINTER */
/* */
/* You can use the Splxxx or Devxxx calls to print text to the printer. */
/* This program shows how to use both. It is conditionally compiled */
/* depending on the DEV macro in the makefile. It is conditionally linked */
/* using the PROGTYPE macro which is dependent on the DEV macro. */
/* */
/* To make this program use Splxxx calls, comment out the DEV macro in */
/* the makefile like this: #DEV=-DDEV */
/* This will undefine DEV. */
/* */
/* To make this program use Devxxx calls, change the DEV macro in the */
/* make file to be DEV=-DDEV */
/* */
/* NOTES: This program is set up as a PM program if it is compiled to use */
/* the DevXxx calls since DevOpenDC needs an anchor block handle. */
/* If you use the Splxxx Calls, it does not need to be a PM */
/* program. The make file controls whether or not it is a PM */
/* program by the PROGTYPE macro which is automatically set by the */
/* defining or not defining of the DEV macro. */
/* */
/* Rick Fishman */
/* Code Blazers, Inc. */
/* 4113 Apricot */
/* Irvine, CA 92720 */
/* CIS ID: 72251,750 */
/* */
/*------------------------------------------------------------------------*/
/**************************************************************************/
#define INCL_DEV
#define INCL_SPL
#define INCL_SPLDOSPRINT
#define INCL_WINERRORS
#define INCL_WINMESSAGEMGR
#define INCL_WINSHELLDATA
#include <os2.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
INT main ( VOID );
USHORT DoDevCalls ( VOID );
USHORT DoSplCalls ( VOID );
VOID DisplayMessage( PSZ szFormat, ... );
#define DOCNAME "Testdoc.Ric"
#define MESSAGE_SIZE 1024
#ifdef DEV // Turn off WinMessageBox if nonPM program
#define Msg DisplayMessage
#else
#define Msg printf
#endif
// Default settings
DEVOPENSTRUC dop = { "LPT1Q", "IBM4201", 0, "PM_Q_RAW", 0, 0, 0, 0, 0 };
CHAR szMessage[] = "This text looks alright to me!\n";
CHAR szBuf[ 256 ];
/**********************************************************************/
/*------------------------------ main --------------------------------*/
/* */
/* PROGRAM ENTRYPOINT */
/* */
/* INPUT: nothing */
/* */
/* 1. */
/* */
/* OUTPUT: nothing */
/* */
/*--------------------------------------------------------------------*/
/**********************************************************************/
INT main()
{
PPRQINFO3 pprq3 = NULL;
USHORT usSize = (SHORT) PrfQueryProfileString( HINI_PROFILE,
SPL_INI_SPOOLER, "QUEUE", NULL, szBuf,
(LONG) sizeof( szBuf ) );
if( usSize )
{
ULONG cbNeeded, ulRC;
PCH pchDot;
szBuf[ usSize - 2 ] = 0; // get rid of terminating semicolon
dop.pszLogAddress = szBuf; // default queue
SplQueryQueue( NULL, szBuf, 3, NULL, 0, &cbNeeded );
pprq3 = (PPRQINFO3) malloc( cbNeeded );
if( !pprq3 )
Msg( "Out of memory" );
ulRC = SplQueryQueue( NULL, szBuf, 3, pprq3, cbNeeded, &cbNeeded );
if( ulRC )
Msg( "SplQueryQueue RC: %u", ulRC );
pchDot = strchr( pprq3->pszDriverName, '.' );
if( pchDot )
*pchDot = 0;
dop.pszDriverName = pprq3->pszDriverName;
dop.pdriv = pprq3->pDriverData;
}
else
Msg( "PrfQueryProfileString for default queue failed\n" );
#ifdef DEV
DoDevCalls();
#else
DoSplCalls();
#endif
if( pprq3 )
free( pprq3 );
return 0;
}
/**********************************************************************/
/*--------------------------- DoDevCalls -----------------------------*/
/* */
/* DO Dev API CALLS TO PRINT STUFF. */
/* */
/* INPUT: nothing */
/* */
/* 1. */
/* */
/* OUTPUT: nothing */
/* */
/*--------------------------------------------------------------------*/
/**********************************************************************/
USHORT DoDevCalls( )
{
HDC hdc;
LONG lBytes;
HAB hab = WinInitialize( 0 );
HMQ hmq;
if( !hab )
DosBeep( 100, 100 );
else
hmq = WinCreateMsgQueue( hab, 0 );
if( !hmq )
DosBeep( 100, 100 );
// Create a printer device context for the print queue
if( !(hdc = DevOpenDC( hab, OD_QUEUED, "*", 4L,
(PDEVOPENDATA) &dop, (HDC) NULL )) )
Msg( "DevOpenDC failed. RC=%x\n", (USHORT) WinGetLastError( 0 ) );
// Start the spool file and name it
if( DEV_OK != DevEscape( hdc, DEVESC_STARTDOC, strlen( DOCNAME ),
DOCNAME, &lBytes, NULL ) )
Msg( "DevEscape STARTDOC failed. RC=%x\n",
(USHORT) WinGetLastError( 0 ) );
// Write data to the spool file
if( DEV_OK != DevEscape( hdc, DEVESC_RAWDATA, strlen( szMessage ),
(PBYTE) szMessage, &lBytes, NULL ) )
Msg( "DevEscape RAWDATA failed. RC=%x\n",
(USHORT) WinGetLastError( 0 ) );
// Close the spool file and start it printing
if( DEV_OK != DevEscape( hdc, DEVESC_ENDDOC, 0, NULL, &lBytes, NULL ) )
Msg( "DevEscape ENDDOC failed. RC=%x\n",
(USHORT) WinGetLastError( 0 ) );
// Close the device context
if( DEV_ERROR == (HMF) DevCloseDC( hdc ) )
Msg( "DevCloseDC failed. RC=%x\n", (USHORT) WinGetLastError( 0 ) );
WinDestroyMsgQueue( hmq );
WinTerminate( hab );
return 0;
}
/**********************************************************************/
/*--------------------------- DoSplCalls -----------------------------*/
/* */
/* DO Spl API CALLS TO PRINT STUFF. */
/* */
/* INPUT: nothing */
/* */
/* 1. */
/* */
/* OUTPUT: nothing */
/* */
/*--------------------------------------------------------------------*/
/**********************************************************************/
USHORT DoSplCalls( )
{
HSPL hspl;
// Open the Print Manager
if( !(hspl = SplQmOpen( "*", 4L, (PQMOPENDATA) &dop )) )
Msg( "SplQmOpen failed\n" );
// Start the spool file and name it
if( !(SplQmStartDoc( hspl, DOCNAME )) )
Msg( "SplQmStartDoc failed\n" );
// Write to the spool file
if( !SplQmWrite( hspl, strlen( szMessage ), szMessage ) )
Msg( "SplQmWrite failed\n" );
// End the spool file. This starts it printing.
if( !SplQmEndDoc( hspl ) )
Msg( "SplQmEndDoc failed\n" );
// Close the Print Manager
if( !SplQmClose( hspl ) )
Msg( "SplQmClose failed\n" );
return 0;
}
/**********************************************************************/
/*------------------------- DisplayMessage ---------------------------*/
/* */
/* INPUT: a message in printf format with its parms */
/* */
/* DISPLAY A MESSAGE TO THE USER. */
/* */
/* 1. Format the message using vsprintf. */
/* 2. Sound a warning sound. */
/* 3. Display the message in a message box. */
/* */
/* OUTPUT: nothing */
/* */
/*--------------------------------------------------------------------*/
/**********************************************************************/
VOID DisplayMessage( PSZ szFormat,... )
{
PSZ szMsg;
va_list argptr;
if( (szMsg = (PSZ) malloc( MESSAGE_SIZE )) == NULL )
{
DosBeep( 1000, 1000 );
return;
}
va_start( argptr, szFormat );
vsprintf( szMsg, szFormat, argptr );
va_end( argptr );
szMsg[ MESSAGE_SIZE - 1 ] = 0;
WinAlarm( HWND_DESKTOP, WA_WARNING );
WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, szMsg,
"prnt32.exe", 1, MB_OK | MB_MOVEABLE );
free( szMsg );
}