Solved

Printing a string in graphic mode

Posted on 2000-03-06
3
191 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 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get time_t value that is a week old 6 168
Passing command line arguments in C 10 90
smtp c source code 7 69
delete-remove 14 86
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

770 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