Solved

Printing a string in graphic mode

Posted on 2000-03-06
3
189 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:a_mazal
  • 2
3 Comments
 
LVL 30

Expert Comment

by:Zoppo
Comment Utility
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,

ZOPPO
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
Comment Utility
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).
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 50 total points
Comment Utility
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
                       //pages
     {
     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) ;
               else
                    bError = TRUE ;
               }
          }
     else
          bError = TRUE ;

     DeleteDC (hdcPrn) ;
     return bError ;
     }

I hope, it helps. Alex
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now