Solved

Printing a string in graphic mode

Posted on 2000-03-06
3
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 2595268
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
ID: 2596578
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
ID: 2604070
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

729 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