Microsoft KB Archive/99874

= How To Print Text Sideways in Picture Control with WIN16 API =

Article ID: 99874

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q99874



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.



Step-by-Step Example
 Start Visual Basic. Form1 is created by default. Draw a large picture box (Picture1) on the form.  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 &quot;GDI&quot; (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 &quot;GDI&quot; (lplogfont As LOGFONT) As Integer Declare Function selectobject Lib &quot;GDI&quot; (ByVal hdc%, ByVal object%) As Integer Declare Function textout Lib &quot;GDI&quot; (ByVal hdc%, ByVal x%, ByVal y%,     ByVal text$, ByVal ncount%) As Integer Declare Sub deleteobject Lib &quot;GDI&quot; (ByVal object%) Declare Function getdevicecaps Lib &quot;GDI&quot; (ByVal hdc%, ByVal nindex%) As Integer Declare Function gettextface Lib &quot;GDI&quot; (ByVal hdc As Integer,     ByVal ncount As Integer, ByVal lpname As String) As Integer

Global Const PROOF_QUALITY = 2 Global Const FW_NORMAL = 400

  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 = &quot;Courier New&quot; + 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

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

Additional query words: 1.00 2.00 3.00

Keywords: kbhowto KB99874

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.