Results 1 to 4 of 4

Thread: Slow Print vs. Fast API call?

  1. #1

    Thread Starter
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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?

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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:
    1. 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)
    2. Dim tRect As RECT
    3. Dim Q As SIZE
    4. Dim hOldFont As Long
    5. Dim hNewFont As Long
    6.  
    7.     GetTextExtentPoint32 hDestDC, Text, Len(Text), Q
    8.    
    9.     With tRect
    10.         If dwFlags And TDP_RIGHT Then
    11.             .Left = x - (Q.cx + 5)
    12.             .Right = x
    13.         ElseIf dwFlags And TDP_HCENTRE Then
    14.             .Left = x - (Q.cx / 2)
    15.             .Right = x + (Q.cx / 2)
    16.         Else
    17.             .Left = x
    18.             .Right = x + (Q.cx - 1)
    19.         End If
    20.         If dwFlags And TDP_BOTTOM Then
    21.             .Top = Y - (Q.cy + 5)
    22.             .Bottom = Y
    23.         ElseIf dwFlags And TDP_VCENTRE Then
    24.             .Top = Y - (Q.cy / 2)
    25.             .Bottom = Y + (Q.cy / 2)
    26.         Else
    27.             .Top = Y
    28.             .Bottom = Y + (Q.cy - 1)
    29.         End If
    30.     End With
    31.  
    32.     hNewFont = CreateMyFont(TextPoint, TextFace)
    33.     hOldFont = SelectObject(hDestDC, hNewFont)
    34.    
    35.     SetTextColor hDestDC, TextColour
    36.     DrawText hDestDC, Text, Len(Text), tRect, 0
    37.    
    38.     Call DeleteObject(SelectObject(hDestDC, hOldFont))
    39.    
    40. End Function
    41. Public Function CreateMyFont(nSize As Integer, sFace As String) As Long  'FROM ALL-API.NET, MODIFIED
    42.     'Create a specified font
    43.     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)
    44. End Function
    And, the declarations:
    VB Code:
    1. Public Enum TEXTDRAWPARAM
    2.     TDP_LEFT = 0
    3.     TDP_RIGHT = 1
    4.     TDP_HCENTRE = 2
    5.     TDP_TOP = 4
    6.     TDP_BOTTOM = 8
    7.     TDP_VCENTRE = 16
    8. End Enum
    9.  
    10. Public Const FW_DONTCARE = 0
    11. Public Const FW_THIN = 100
    12. Public Const FW_EXTRALIGHT = 200
    13. Public Const FW_LIGHT = 300
    14. Public Const FW_NORMAL = 400
    15. Public Const FW_MEDIUM = 500
    16. Public Const FW_SEMIBOLD = 600
    17. Public Const FW_BOLD = 700
    18. Public Const FW_EXTRABOLD = 800
    19. Public Const FW_HEAVY = 900
    20. Public Const FW_BLACK = FW_HEAVY
    21. Public Const FW_DEMIBOLD = FW_SEMIBOLD
    22. Public Const FW_REGULAR = FW_NORMAL
    23. Public Const FW_ULTRABOLD = FW_EXTRABOLD
    24. Public Const FW_ULTRALIGHT = FW_EXTRALIGHT
    25. Public Const ANSI_CHARSET = 0
    26. Public Const DEFAULT_CHARSET = 1
    27. Public Const SYMBOL_CHARSET = 2
    28. Public Const SHIFTJIS_CHARSET = 128
    29. Public Const HANGEUL_CHARSET = 129
    30. Public Const CHINESEBIG5_CHARSET = 136
    31. Public Const OEM_CHARSET = 255
    32. Public Const OUT_CHARACTER_PRECIS = 2
    33. Public Const OUT_DEFAULT_PRECIS = 0
    34. Public Const OUT_DEVICE_PRECIS = 5
    35. Public Const CLIP_DEFAULT_PRECIS = 0
    36. Public Const CLIP_CHARACTER_PRECIS = 1
    37. Public Const CLIP_STROKE_PRECIS = 2
    38. Public Const DEFAULT_QUALITY = 0
    39. Public Const DRAFT_QUALITY = 1
    40. Public Const PROOF_QUALITY = 2
    41. Public Const DEFAULT_PITCH = 0
    42. Public Const FIXED_PITCH = 1
    43. Public Const VARIABLE_PITCH = 2
    44. Public Const OPAQUE = 2
    45. Public Const TRANSPARENT = 1
    46. Public Const LOGPIXELSY = 90
    47. Public Const OBJ_BITMAP = 7
    48. Public Const DT_RIGHT = &H2
    49. Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    50. Public Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
    51. 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
    52. 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
    53. Public Declare Function MulDiv Lib "kernel32" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long
    54. Public Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
    55. 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
    56. 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)

  3. #3

    Thread Starter
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    I get compile error on this point:

    VB Code:
    1. 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

  4. #4

    Thread Starter
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    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
  •  



Click Here to Expand Forum to Full Width