Solved

Rotated Text & Graphics

Posted on 2000-03-22
4
246 Views
Last Modified: 2010-05-02
Here is sample code to print(on paper)  rotated text.  I want to print lines and graphics, on the SAME page. I am having trouble, can anyone help?

This is right from the VISUAL BASIC HELP


Code Example
Create a Standard EXE project in Visual Basic. Form1 is created by default.


Add 2 CommandButtons to Form1.


Add the following code to the General Declarations section of Form1:



   Option Explicit

   Private Const LF_FACESIZE = 32

   Private Type LOGFONT
      lfHeight As Long
      lfWidth As Long
      lfEscapement As Long
      lfOrientation As Long
      lfWeight As Long
      lfItalic As Byte
      lfUnderline As Byte
      lfStrikeOut As Byte
      lfCharSet As Byte
      lfOutPrecision As Byte
      lfClipPrecision As Byte
      lfQuality As Byte
      lfPitchAndFamily As Byte
      lfFaceName As String * LF_FACESIZE
   End Type

   Private Type DOCINFO
      cbSize As Long
      lpszDocName As String
      lpszOutput As String
      lpszDatatype As String
      fwType As Long
   End Type

   Private Declare Function CreateFontIndirect Lib "gdi32" Alias _
   "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long

   Private Declare Function SelectObject Lib "gdi32" _
   (ByVal hdc As Long, ByVal hObject As Long) As Long

   Private Declare Function DeleteObject Lib "gdi32" _
   (ByVal hObject As Long) As Long

   Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" _
   (ByVal lpDriverName As String, ByVal lpDeviceName As String, _
   ByVal lpOutput As Long, ByVal lpInitData As Long) As Long

   Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) _
   As Long

   Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" _
   (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, _
   ByVal lpString As String, ByVal nCount As Long) As Long ' or Boolean

   Private Declare Function StartDoc Lib "gdi32" Alias "StartDocA" _
   (ByVal hdc As Long, lpdi As DOCINFO) As Long

   Private Declare Function EndDoc Lib "gdi32" (ByVal hdc As Long) _
   As Long

   Private Declare Function StartPage Lib "gdi32" (ByVal hdc As Long) _
   As Long

   Private Declare Function EndPage Lib "gdi32" (ByVal hdc As Long) _
   As Long

   Const DESIREDFONTSIZE = 12     ' Could use variable, TextBox, etc.

   Private Sub Command1_Click()
   ' Combine API Calls with the Printer object
      Dim OutString As String
      Dim lf As LOGFONT
      Dim result As Long
      Dim hOldfont As Long
      Dim hPrintDc As Long
      Dim hFont As Long

      Printer.Print "Printer Object"
      hPrintDc = Printer.hdc
      OutString = "Hello World"

      lf.lfEscapement = 1800
      lf.lfHeight = (DESIREDFONTSIZE * -20) / Printer.TwipsPerPixelY
      hFont = CreateFontIndirect(lf)
      hOldfont = SelectObject(hPrintDc, hFont)
      result = TextOut(hPrintDc, 1000, 1000, OutString, Len(OutString))
      result = SelectObject(hPrintDc, hOldfont)
      result = DeleteObject(hFont)

      Printer.Print "xyz"
      Printer.EndDoc
   End Sub

   Private Sub Command2_Click()
   ' Print using API calls only
      Dim OutString As String  'String to be rotated
      Dim lf As LOGFONT        'Structure for setting up rotated font
      Dim temp As String       'Temp string var
      Dim result As Long       'Return value for calling API functions
      Dim hOldfont As Long     'Hold old font information
      Dim hPrintDc As Long     'Handle to printer dc
      Dim hFont As Long        'Handle to new Font
      Dim di As DOCINFO        'Structure for Print Document info

      OutString = "Hello World"   'Set string to be rotated

   ' Set rotation in tenths of a degree, i.e., 1800 = 180 degrees
      lf.lfEscapement = 1800
      lf.lfHeight = (DESIREDFONTSIZE * -20) / Printer.TwipsPerPixelY
      hFont = CreateFontIndirect(lf)  'Create the rotated font
      di.cbSize = 20                  ' Size of DOCINFO structure
      di.lpszDocName = "My Document" ' Set name of print job (Optional)

   ' Create a printer device context
      hPrintDc = CreateDC(Printer.DriverName, Printer.DeviceName, 0, 0)

      result = StartDoc(hPrintDc, di) 'Start a new print document
      result = StartPage(hPrintDc)    'Start a new page

   ' Select our rotated font structure and save previous font info
      hOldfont = SelectObject(hPrintDc, hFont)

   ' Send rotated text to printer, starting at location 1000, 1000
      result = TextOut(hPrintDc, 1000, 1000, OutString, Len(OutString))

   ' Reset font back to original, non-rotated
      result = SelectObject(hPrintDc, hOldfont)

   ' Send non-rotated text to printer at same page location
      result = TextOut(hPrintDc, 1000, 1000, OutString, Len(OutString))

      result = EndPage(hPrintDc)      'End the page
      result = EndDoc(hPrintDc)       'End the print job
      result = DeleteDC(hPrintDc)     'Delete the printer device context
      result = DeleteObject(hFont)    'Delete the font object
   End Sub

   Private Sub Form_Load()
      Command1.Caption = "API with Printer object"
      Command2.Caption = "Pure API"
   End Sub
 
Run the Project and click API with Printer object. This will print a single page to the current default printer with "Printer Object" and "xyz" printed normally and "Hello World" printed rotated 180 degrees.


Click Pure API. This will print a single page to the current default printer with "Hello World" printed normally and rotated 180 degrees.



Additional query words: sideways angle sp2


Keywords          : kbAPI kbGDI kbPrinting KbVBA kbVBp500 kbVBp600 kbVS97sp2 kbVS97sp3 kbDSupport
Version           : WINDOWS:5.0,6.0,97,97sp2,97sp3
Platform          : WINDOWS
Issue type        : kbprb
 


Last  

0
Comment
Question by:pentomino
  • 2
4 Comments
 
LVL 1

Expert Comment

by:bpoff
ID: 2645039
What exactly is the problem?  Does this sample not work?  What is happening?
0
 
LVL 1

Author Comment

by:pentomino
ID: 2645670
The sample works and prints out "Hello World" upside down, as it is supposed to.  I want to know what code to add that would also print out a straight line, and a graphic on the same page.
0
 

Accepted Solution

by:
FONATURE earned 100 total points
ID: 2647806
I dont know if this is what you want but it sounds like it .Well here is what I did with command1. You have to add a picture box Picture1
Set the auto sizes to true
Load a picture in it
 
Heres the sample


Private Sub Command1_Click()
' Combine API Calls with the Printer object
Dim OutString As String
Dim lf As LOGFONT
Dim result As Long
Dim hOldfont As Long
Dim hPrintDc As Long
Dim hFont As Long

Printer.Print "Printer Object"
hPrintDc = Printer.hdc
OutString = "Hello World"
lf.lfEscapement = 1800
lf.lfHeight = (DESIREDFONTSIZE * -20) / Printer.TwipsPerPixelY
hFont = CreateFontIndirect(lf)
hOldfont = SelectObject(hPrintDc, hFont)
result = TextOut(hPrintDc, 1000, 1000, OutString, Len(OutString))
result = SelectObject(hPrintDc, hOldfont)
result = DeleteObject(hFont)
Printer.Print "xyz"
Printer.DrawWidth = 5
'Heres the line
Printer.Line (1000, 4000)-(10000, 4000)
'Heres the Picture from picture1
Printer.PaintPicture Picture1, 5000, _ 5000, Picture1.Width, Picture1.Height
Printer.EndDoc
End Sub

'Hope this Helps you Out CHEERS

0
 
LVL 1

Author Comment

by:pentomino
ID: 2649353
Thanks FONATURE

I thought I tried that, but always got two pages, one with the text, the other with the graphics.  Don't know what I was doing wrong.  Some how the new page command must have been executed.  Anyway this is EXACTLY what I wanted..

Thank you so much.

Email me if you want to correspond futher.
pentomino@juno.com
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 61
using Access 8 83
VB6 ListBox Question 4 55
odbc driver manager data source name not found and no default driver specified 9 25
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

735 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