• C

Printing a string in graphic mode

I have a problem in printing a string, that include non-latin letters to printer. I have to do it in a graphic mode and not in DOS. If I use CreateFile and give as a parameter, printer destination, I get pseudo-graphics, because it prints in DOS mode. If I use a middle .doc file and then print it, it prints ok, but after each string, it makes form feed.
My current application program is resident console application in C. It sits in a tray and wait for specific system messages.When it gets the right message, it must send it to printer. All messages may contain non-english(latin) letters. If there exist any API or something else, that may be used for my purpose ? Thank you in advance
Who is Participating?
AlexVirochovskyConnect With a Mentor Commented:
I send you example of Printing:
Example of Printing:

#include <windows.h>
HDC GetPrinterDC (void)
     PRINTER_INFO_5 pinfo5[3] ;
     DWORD          dwNeeded, dwReturned ;

     if (EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 5, (LPBYTE) pinfo5,
                       sizeof (pinfo5), &dwNeeded, &dwReturned))
          return CreateDC (NULL, pinfo5[0].pPrinterName, NULL, NULL) ;

     return 0 ;            // EnumPrinters failed, so return null hdc

void PageGDICalls (HDC hdcPrn, int cxPage, int cyPage)
     static char szTextStr[] = "Hello, Printer!" ;

     Rectangle (hdcPrn, 0, 0, cxPage, cyPage) ;

     MoveToEx (hdcPrn, 0, 0, NULL) ;
     LineTo   (hdcPrn, cxPage, cyPage) ;
     MoveToEx (hdcPrn, cxPage, 0, NULL) ;
     LineTo   (hdcPrn, 0, cyPage) ;

     SaveDC (hdcPrn) ;

     SetMapMode       (hdcPrn, MM_ISOTROPIC) ;
     SetWindowExtEx   (hdcPrn, 1000, 1000, NULL) ;
     SetViewportExtEx (hdcPrn, cxPage / 2, -cyPage / 2, NULL) ;
     SetViewportOrgEx (hdcPrn, cxPage / 2,  cyPage / 2, NULL) ;

     Ellipse (hdcPrn, -500, 500, 500, -500) ;

     SetTextAlign (hdcPrn, TA_BASELINE | TA_CENTER) ;

     TextOut (hdcPrn, 0, 0, szTextStr, sizeof (szTextStr) - 1) ;

     RestoreDC (hdcPrn, -1) ;

BOOL PrintMyPage (HWND hwnd) //print 1 page, you can make loop for all
     static DOCINFO di     = { sizeof (DOCINFO), "Print1: Printing", NULL } ;
     BOOL           bError = FALSE ;
     HDC            hdcPrn ;
     int            xPage, yPage ;

     if (NULL == (hdcPrn = GetPrinterDC ()))
          return TRUE ;

     xPage = GetDeviceCaps (hdcPrn, HORZRES) ;
     yPage = GetDeviceCaps (hdcPrn, VERTRES) ;

     if (StartDoc (hdcPrn, &di) > 0)
          if (StartPage (hdcPrn) > 0)
               PageGDICalls (hdcPrn, xPage, yPage) ; //print page

               if (EndPage (hdcPrn) > 0)
                    EndDoc (hdcPrn) ;
                    bError = TRUE ;
          bError = TRUE ;

     DeleteDC (hdcPrn) ;
     return bError ;

I hope, it helps. Alex
Hi a_mazal,

assuming it's for windows you can create a printer device context (i.e. PrintDlg with PD_RETURNDEFAULT flag), create a font for the character set you need (i.e. with CreateFont() ) and print the text with TextOut().

hope that helps,

Why you use CreateFile for Printing?
There are specific Printing API:
OpenPrint, OpenPage, ...
If you want, i can send you full
example of printing(write you EMail).
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.