|
-
Nov 18th, 2002, 09:14 PM
#1
Slow Print vs. Fast API call?
So I wonder if there's a fast API call that does the same as Print. Or is the speed-difference so small when using a bigger font that it's all the same what way you use?
-
Nov 18th, 2002, 10:47 PM
#2
Good Ol' Platypus
TextOut is the API call you want... There's another one, called DrawText, which I always use... but anyway, this function I made should help you out:
VB Code:
Public Function TextBlt(ByVal hDestDC As Long, ByVal x As Long, ByVal Y As Long, ByVal Text As String, ByVal TextColour As Long, ByVal TextPoint As Integer, ByVal TextFace As String, ByVal dwFlags As TEXTDRAWPARAM)
Dim tRect As RECT
Dim Q As SIZE
Dim hOldFont As Long
Dim hNewFont As Long
GetTextExtentPoint32 hDestDC, Text, Len(Text), Q
With tRect
If dwFlags And TDP_RIGHT Then
.Left = x - (Q.cx + 5)
.Right = x
ElseIf dwFlags And TDP_HCENTRE Then
.Left = x - (Q.cx / 2)
.Right = x + (Q.cx / 2)
Else
.Left = x
.Right = x + (Q.cx - 1)
End If
If dwFlags And TDP_BOTTOM Then
.Top = Y - (Q.cy + 5)
.Bottom = Y
ElseIf dwFlags And TDP_VCENTRE Then
.Top = Y - (Q.cy / 2)
.Bottom = Y + (Q.cy / 2)
Else
.Top = Y
.Bottom = Y + (Q.cy - 1)
End If
End With
hNewFont = CreateMyFont(TextPoint, TextFace)
hOldFont = SelectObject(hDestDC, hNewFont)
SetTextColor hDestDC, TextColour
DrawText hDestDC, Text, Len(Text), tRect, 0
Call DeleteObject(SelectObject(hDestDC, hOldFont))
End Function
Public Function CreateMyFont(nSize As Integer, sFace As String) As Long 'FROM ALL-API.NET, MODIFIED
'Create a specified font
CreateMyFont = CreateFont(-MulDiv(nSize, GetDeviceCaps(GetDC(0), LOGPIXELSY), 72), 0, 0, 0, FW_NORMAL, False, False, False, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH, sFace)
End Function
And, the declarations:
VB Code:
Public Enum TEXTDRAWPARAM
TDP_LEFT = 0
TDP_RIGHT = 1
TDP_HCENTRE = 2
TDP_TOP = 4
TDP_BOTTOM = 8
TDP_VCENTRE = 16
End Enum
Public Const FW_DONTCARE = 0
Public Const FW_THIN = 100
Public Const FW_EXTRALIGHT = 200
Public Const FW_LIGHT = 300
Public Const FW_NORMAL = 400
Public Const FW_MEDIUM = 500
Public Const FW_SEMIBOLD = 600
Public Const FW_BOLD = 700
Public Const FW_EXTRABOLD = 800
Public Const FW_HEAVY = 900
Public Const FW_BLACK = FW_HEAVY
Public Const FW_DEMIBOLD = FW_SEMIBOLD
Public Const FW_REGULAR = FW_NORMAL
Public Const FW_ULTRABOLD = FW_EXTRABOLD
Public Const FW_ULTRALIGHT = FW_EXTRALIGHT
Public Const ANSI_CHARSET = 0
Public Const DEFAULT_CHARSET = 1
Public Const SYMBOL_CHARSET = 2
Public Const SHIFTJIS_CHARSET = 128
Public Const HANGEUL_CHARSET = 129
Public Const CHINESEBIG5_CHARSET = 136
Public Const OEM_CHARSET = 255
Public Const OUT_CHARACTER_PRECIS = 2
Public Const OUT_DEFAULT_PRECIS = 0
Public Const OUT_DEVICE_PRECIS = 5
Public Const CLIP_DEFAULT_PRECIS = 0
Public Const CLIP_CHARACTER_PRECIS = 1
Public Const CLIP_STROKE_PRECIS = 2
Public Const DEFAULT_QUALITY = 0
Public Const DRAFT_QUALITY = 1
Public Const PROOF_QUALITY = 2
Public Const DEFAULT_PITCH = 0
Public Const FIXED_PITCH = 1
Public Const VARIABLE_PITCH = 2
Public Const OPAQUE = 2
Public Const TRANSPARENT = 1
Public Const LOGPIXELSY = 90
Public Const OBJ_BITMAP = 7
Public Const DT_RIGHT = &H2
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Public Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As SIZE) As Long
Public Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal H As Long, ByVal W As Long, ByVal E As Long, ByVal O As Long, ByVal W As Long, ByVal I As Long, ByVal u As Long, ByVal S As Long, ByVal C As Long, ByVal OP As Long, ByVal CP As Long, ByVal Q As Long, ByVal PAF As Long, ByVal F As String) As Long
Public Declare Function MulDiv Lib "kernel32" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long
Public Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Public Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Nov 20th, 2002, 03:24 AM
#3
I get compile error on this point:
VB Code:
Public Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As [color=red]Size[/color]) As Long
-
Nov 20th, 2002, 03:32 AM
#4
Oh forget it, I found the right API things...just that there's one little thing: it's far slower than Print! When I continuously changed it, Windows 2000 Task Manager's "processor usage" reached 100%, whilst on Print it stayed under 80% - this when using a huge font.
So, the problem isn't kind of solved atm. Thanks for your help anyways
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|