Results 1 to 3 of 3

Thread: How to use BitBlt

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    Shannon, Quebec, Canada
    Posts
    251

    Question How to use BitBlt

    Hi,

    I want to be able to print a form in VB...In this form there is a SSTab with 2 tabs. I think I have to use BitBlt? But I need to know how to code that API. Is there somebody who wants to help me please?

    Thanks!

    Mel xxx
    Ça l'air que baiser enlève les maux de tête! Baisons!

    On se mets-tu tout nu?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Const FW_DONTCARE = 0
    2. Const FW_THIN = 100
    3. Const FW_EXTRALIGHT = 200
    4. Const FW_LIGHT = 300
    5. Const FW_NORMAL = 400
    6. Const FW_MEDIUM = 500
    7. Const FW_SEMIBOLD = 600
    8. Const FW_BOLD = 700
    9. Const FW_EXTRABOLD = 800
    10. Const FW_HEAVY = 900
    11. Const FW_BLACK = FW_HEAVY
    12. Const FW_DEMIBOLD = FW_SEMIBOLD
    13. Const FW_REGULAR = FW_NORMAL
    14. Const FW_ULTRABOLD = FW_EXTRABOLD
    15. Const FW_ULTRALIGHT = FW_EXTRALIGHT
    16. 'used with fdwCharSet
    17. Const ANSI_CHARSET = 0
    18. Const DEFAULT_CHARSET = 1
    19. Const SYMBOL_CHARSET = 2
    20. Const SHIFTJIS_CHARSET = 128
    21. Const HANGEUL_CHARSET = 129
    22. Const CHINESEBIG5_CHARSET = 136
    23. Const OEM_CHARSET = 255
    24. 'used with fdwOutputPrecision
    25. Const OUT_CHARACTER_PRECIS = 2
    26. Const OUT_DEFAULT_PRECIS = 0
    27. Const OUT_DEVICE_PRECIS = 5
    28. 'used with fdwClipPrecision
    29. Const CLIP_DEFAULT_PRECIS = 0
    30. Const CLIP_CHARACTER_PRECIS = 1
    31. Const CLIP_STROKE_PRECIS = 2
    32. 'used with fdwQuality
    33. Const DEFAULT_QUALITY = 0
    34. Const DRAFT_QUALITY = 1
    35. Const PROOF_QUALITY = 2
    36. 'used with fdwPitchAndFamily
    37. Const DEFAULT_PITCH = 0
    38. Const FIXED_PITCH = 1
    39. Const VARIABLE_PITCH = 2
    40. 'used with SetBkMode
    41. Const OPAQUE = 2
    42. Const TRANSPARENT = 1
    43.  
    44. Const LOGPIXELSY = 90
    45. Const COLOR_WINDOW = 5
    46. Const Message = "Hello !"
    47.  
    48. Private Type RECT
    49.     Left As Long
    50.     Top As Long
    51.     Right As Long
    52.     Bottom As Long
    53. End Type
    54.  
    55. Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
    56. Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    57. Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    58. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    59. Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
    60. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    61. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    62. Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    63. Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    64. Private Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal nHeight As Long, ByVal nWidth As Long, ByVal nEscapement As Long, ByVal nOrientation As Long, ByVal fnWeight As Long, ByVal fdwItalic As Boolean, ByVal fdwUnderline As Boolean, ByVal fdwStrikeOut As Boolean, ByVal fdwCharSet As Long, ByVal fdwOutputPrecision As Long, ByVal fdwClipPrecision As Long, ByVal fdwQuality As Long, ByVal fdwPitchAndFamily As Long, ByVal lpszFace As String) As Long
    65. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    66. 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
    67. Private Declare Function MulDiv Lib "kernel32" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long
    68. Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
    69. Private Declare Function GetSysColorBrush Lib "user32" (ByVal nIndex As Long) As Long
    70. Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
    71. Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    72. Dim mDC As Long, mBitmap As Long
    73. Private Sub Form_Click()
    74.     Unload Me
    75. End Sub
    76. Private Sub Form_Load()
    77.     'KPD-Team 1999
    78.     'URL: [url]http://www.allapi.net/[/url]
    79.     'E-Mail: [email][email protected][/email]
    80.     Dim mRGN As Long, Cnt As Long, mBrush As Long, R As RECT
    81.     'Create a device context, compatible with the screen
    82.     mDC = CreateCompatibleDC(GetDC(0))
    83.     'Create a bitmap, compatible with the screen
    84.     mBitmap = CreateCompatibleBitmap(GetDC(0), Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY)
    85.     'Select the bitmap nito the device context
    86.     SelectObject mDC, mBitmap
    87.     'Set the bitmap's backmode to transparent
    88.     SetBkMode mDC, TRANSPARENT
    89.     'Set the rectangles' values
    90.     SetRect R, 0, 0, Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY
    91.     'Fill the rect with the default window-color
    92.     FillRect mDC, R, GetSysColorBrush(COLOR_WINDOW)
    93.  
    94.     For Cnt = 0 To 350 Step 30
    95.         'Select the new font into the form's device context and delete the old font
    96.         DeleteObject SelectObject(mDC, CreateMyFont(24, Cnt))
    97.         'Print some text
    98.         TextOut mDC, (Me.Width / Screen.TwipsPerPixelX) / 2, (Me.Height / Screen.TwipsPerPixelY) / 2, Message, Len(Message)
    99.     Next Cnt
    100.  
    101.     'Create an elliptical region
    102.     mRGN = CreateEllipticRgn(0, 0, Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY)
    103.     'Set the window region
    104.     SetWindowRgn Me.hWnd, mRGN, True
    105.  
    106.     'delete our elliptical region
    107.     DeleteObject mRGN
    108. End Sub
    109. Function CreateMyFont(nSize As Integer, nDegrees As Long) As Long
    110.     'Create a specified font
    111.     CreateMyFont = CreateFont(-MulDiv(nSize, GetDeviceCaps(GetDC(0), LOGPIXELSY), 72), 0, nDegrees * 10, 0, FW_NORMAL, False, False, False, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH, "Times New Roman")
    112. End Function
    113. Private Sub Form_Paint()
    114.     'Copy the picture to the form
    115.     BitBlt Me.hdc, 0, 0, Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY, mDC, 0, 0, vbSrcCopy
    116. End Sub
    117. Private Sub Form_Unload(Cancel As Integer)
    118.     'clean up
    119.     DeleteDC mDC
    120.     DeleteObject mBitmap
    121. End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    Shannon, Quebec, Canada
    Posts
    251
    Hi Hack!

    The man of the situation!! I'll see your code that you give. What does this code do?

    See you later! XXX
    Ça l'air que baiser enlève les maux de tête! Baisons!

    On se mets-tu tout nu?

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