How to Print Text Sideways in Picture Control with Windows API

Last reviewed: June 21, 1995
Article ID: Q99874
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 2.0 and 3.0
- Microsoft Visual Basic for Windows, version 1.0

SUMMARY

The example below shows how to print text sideways in a picture control using Windows API function calls. The text prints vertically in the picture control, rotated by 90 degrees.

MORE INFORMATION

Step-by-Step Example

1. Start Visual Basic. Form1 is created by default.

  1. Draw a large picture box (Picture1) on the form.

  2. From the File menu, choose New Module to create a new module. Put the following code in the module:

    DefInt A-Z global Const LF_FACESIZE = 32 Type LOGFONT

          lfheight As Integer
          lfwidth As Integer
          lfescapement As Integer
          lforientation As Integer
          lfweight As Integer
          lfitalic As String * 1
          lfunderline As String * 1
          lfstrikeout As String * 1
          lfcharset As String * 1
          lfoutprecision As String * 1
          lfclipprecision As String * 1
          lfquality As String * 1
          lfpitchandfamily As String * 1
          lffacename As String * LF_FACESIZE
    
    End Type

       ' Enter each of the following 7 Declare statement on one, single line:
       Declare Function CreateFont% Lib "GDI" (ByVal h%, ByVal w%, ByVal e%,
          ByVal o%, ByVal n%, ByVal i%, ByVal u%, ByVal s%, ByVal c%,
          ByVal op%, ByVal cp%, ByVal q%, ByVal j%, ByVal f$)
       Declare Function createfontindirect Lib "GDI" (lplogfont As LOGFONT)
          As Integer
       Declare Function selectobject Lib "GDI" (ByVal hdc%, ByVal object%)
          As Integer
       Declare Function textout Lib "GDI" (ByVal hdc%, ByVal x%, ByVal y%,
          ByVal text$, ByVal ncount%) As Integer
       Declare Sub deleteobject Lib "GDI" (ByVal object%)
       Declare Function getdevicecaps Lib "GDI" (ByVal hdc%, ByVal nindex%)
          As Integer
       Declare Function gettextface Lib "GDI" (ByVal hdc As Integer,
          ByVal ncount As Integer, ByVal lpname As String) As Integer
    
       Global Const PROOF_QUALITY = 2
       Global Const FW_NORMAL = 400
    
    

  3. Add the following code to the Form_Click event:

    picture1.Cls Dim hfont As Integer, holdfont As Integer Dim font As LOGFONT nvalue = getdevicecaps(picture1.hDC, 34) font.lfheight = 12 font.lfwidth = 0 font.lfescapement = 900 font.lforientation = 900

       font.lfweight = 400    'This is normal
       font.lfitalic = Chr$(0)
       font.lfunderline = Chr$(0)
       font.lfstrikeout = Chr$(0)
       font.lfcharset = Chr$(0)
       font.lfoutprecision = Chr$(0)
       font.lfclipprecision = Chr$(0)
       font.lfquality = Chr$(2)
       font.lfpitchandfamily = Chr$(33)
       font.lffacename = "Courier New" + Chr$(0)
    
       hfont = createfontindirect(font)
       holdfont = selectobject(picture1.hDC, hfont)
       szfacename$ = Space$(80)
       retval% = gettextface(picture1.hDC, 79, szfacename$)
    
       nchars = Len(sometext$)
       picture1.CurrentX = 200
       picture1.CurrentY = 2000
       picture1.Print Left$(RTrim$(szfacename$), Len(RTrim$(szfacename$)) - 1)
       deleteobject hfont
    
    

  4. Run the program. Click the form, not the picture. You'll see the phrase "Courier New" print sideways in the picture control, from the lower left to the upper left.


Additional reference words: 1.00 2.00 3.00
KBCategory: kbprint kbprg kbcode
KBSubcategory: APrgPrint APrgWindow


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.