How to Print a Single Line Without FormfeedLast reviewed: July 23, 1997Article ID: Q124649 |
|
3.10
WINDOWS
kbprint kbcode
The information in this article applies to:
SUMMARYThis article shows by example how to have an application print one line at a time without a formfeed. Windows does not inherently provide this ability because it is in direct conflict with the design philosophy of a multitasking operating system. One method of single-line printing, including sample code, is provided here. This method uses the combination of the RAW.DRV sample printer driver and the PASSTHROUGH escape, and supports printing over a network. It has the following limitations:
MORE INFORMATIONIf you are sure no other application will use the same printer, you can have your application print one line at a time to a dot matrix printer without issuing a formfeed. Use the RAW.DRV sample printer driver and the PASSTHROUGH escape to accomplish this. Follow these steps:
MSG msg;
while(PeekMessage(&msg, NULL, 0, 0, TRUE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return TRUE;
}
// The function that prints one line without formfeedBOOL PrintLineNow( char *pData, WORD cbBytes ) { #define LINEBUFFER_LENGTH 80 //or dynamically alloc enough space
HDC hDC;
char pOutput[LINEBUFFER_LENGTH+sizeof(WORD)];
DOCINFO di;
ABORTPROC lpfnAbortProc;
// Buffer size is LINEBUFFER_LENGTH bytes
if( cbBytes > LINEBUFFER_LENGTH )
return FALSE;
// Get the DC using the RAW.DRV driver
if( (hDC = CreateDC( "RAW", NULL, "LPT1", NULL ) ) == NULL )
return FALSE;
// Set up an Abort Procedure
if((lpfnAbortProc = MakeProcInstance(AbortProc, hInst)) == NULL)
{
DeleteDC( hDC );
return FALSE;
}
if( SetAbortProc( hDC, lpfnAbortProc ) <= 0 )
{
DeleteDC( hDC );
FreeProcInstance( lpfnAbortProc );
return FALSE;
}
// Start a Document
di.cbSize = sizeof( DOCINFO );
di.lpszDocName = "MyDoc";
di.lpszOutput = NULL;
if( StartDoc( hDC, &di ) <= 0 )
{
DeleteDC( hDC );
FreeProcInstance( lpfnAbortProc );
return FALSE;
}
// The start of a page
if( StartPage( hDC ) <= 0 )
{
DeleteDC( hDC );
FreeProcInstance( lpfnAbortProc );
return FALSE;
}
// Put data in the buffer and send to the printer
*(WORD *)pOutput = cbBytes;
memcpy( &(pOutput[sizeof(WORD)]), pData, cbBytes );
if( Escape( hDC, PASSTHROUGH, 0, pOutput, NULL ) <= 0 )
{
DeleteDC( hDC );
FreeProcInstance( lpfnAbortProc );
return FALSE;
}
// The end of the page
if( EndPage( hDC ) < 0 )
{
DeleteDC( hDC );
FreeProcInstance( lpfnAbortProc );
return FALSE;
}
// End the Document
if( EndDoc( hDC ) < 0 )
{
DeleteDC( hDC );
FreeProcInstance( lpfnAbortProc );
return FALSE;
}
// Clean up
DeleteDC( hDC );
FreeProcInstance( lpfnAbortProc );
return TRUE; // Success
}
|
Additional reference words: 3.10 NEWFRAME FF Mailing Label Form Feed
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |