|
|
|
Click here to copy the following block |
Option Explicit
Private Const LF_FACESIZE = 32 Private Const LOGPIXELSY = 90
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(LF_FACESIZE - 1) As Byte End Type
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 CreateFontIndirect Lib "gdi32" Alias _ "CreateFontIndirectA" (lpLogFont As LOGFONT) 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 Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, _ ByVal nIndex As Long) As Long
Private mobjDevice As Object Private mfSX1 As Single Private mfSY1 As Single Private mfXRatio As Single Private mfYRatio As Single Private lfFont As LOGFONT Private mnAngle As Integer
Property Let Angle(nAngle As Integer) mnAngle = nAngle End Property Property Get Angle() As Integer Angle = mnAngle End Property
Public Sub PrintText(sText As String) Dim lFont As Long Dim lOldFont As Long Dim lRes As Long Dim byBuf() As Byte Dim nI As Integer Dim sFontName As String Dim mobjDevicehdc As Long Dim mobjDeviceCurrentX As Single Dim mobjDeviceCurrentY As Single mobjDevicehdc = mobjDevice.hdc mobjDeviceCurrentX = mobjDevice.CurrentX mobjDeviceCurrentY = mobjDevice.CurrentY sFontName = mobjDevice.Font.Name byBuf = StrConv(sFontName & Chr$(0), vbFromUnicode) For nI = 0 To UBound(byBuf) lfFont.lfFaceName(nI) = byBuf(nI) Next nI lfFont.lfHeight = mobjDevice.Font.Size * GetDeviceCaps(mobjDevicehdc, _ LOGPIXELSY) \ 72 If mobjDevice.Font.Italic = True Then lfFont.lfItalic = 1 Else lfFont.lfItalic = 0 End If If mobjDevice.Font.Underline = True Then lfFont.lfUnderline = 1 Else lfFont.lfUnderline = 0 End If If mobjDevice.Font.Strikethrough = True Then lfFont.lfStrikeOut = 1 Else lfFont.lfStrikeOut = 0 End If lfFont.lfWeight = mobjDevice.Font.Weight lfFont.lfEscapement = CLng(mnAngle * 10#) lfFont.lfOrientation = lfFont.lfEscapement lFont = CreateFontIndirect(lfFont) lOldFont = SelectObject(mobjDevicehdc, lFont) lRes = TextOut(mobjDevicehdc, XtoP(mobjDeviceCurrentX), _ YtoP(mobjDeviceCurrentY), sText, Len(sText)) lFont = SelectObject(mobjDevicehdc, lOldFont) DeleteObject lFont End Sub
Property Set Device(objDevice As Object) Dim fSX2 As Single Dim fSY2 As Single Dim fPX2 As Single Dim fPY2 As Single Dim nScaleMode As Integer Set mobjDevice = objDevice With mobjDevice nScaleMode = .ScaleMode mfSX1 = .ScaleLeft mfSY1 = .ScaleTop fSX2 = mfSX1 + .ScaleWidth fSY2 = mfSY1 + .ScaleHeight .ScaleMode = vbPixels fPX2 = .ScaleWidth fPY2 = .ScaleHeight If nScaleMode = 0 Then mobjDevice.Scale (mfSX1, mfSY1)-(fSX2, fSY2) Else mobjDevice.ScaleMode = nScaleMode End If mfXRatio = fPX2 / (fSX2 - mfSX1) mfYRatio = fPY2 / (fSY2 - mfSY1) End With End Property
Private Function XtoP(fX As Single) As Long XtoP = (fX - mfSX1) * mfXRatio End Function
Private Function YtoP(fY As Single) As Long YtoP = (fY - mfSY1) * mfYRatio End Function |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|