Results 1 to 2 of 2

Thread: [VB6] - How apture a window or Picturebox?

  1. #1
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    [VB6] - How apture a window or Picturebox?

    i have seen very api functions for capture a window or picturebox, but all are slow for animation.
    anyone knows any function that can do it with some speed?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    PowerPoster joaquim's Avatar
    Join Date
    Apr 07
    Posts
    2,494

    Re: [VB6] - How apture a window or Picturebox?

    ok... i found 1 nice way(these code is in module):
    Code:
    Option Explicit
    
    
    'This call gives us the hWnd (window handle) of the screen
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    
    'This call assigns an hDC (handle of device context) from an hWnd
    Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
    
    'BitBlt lets us draw an image from a hDC to another hDC (in our case, from an hDC of the screen capture to the hDC of a VB picture box)
    Private Declare Function BitBlt Lib "gdi32" (ByVal hDC 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 opCode As Long) As Long
    
    'ReleaseDC will be used to clear out the hDC we generate for the screen capture.
    Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
    
    'Sample: PrintWindowWithControls picturedestany.hdc, picturesource.hwnd, 0, 0, picturesource.width, picturesource.width
    Public Sub PrintWindowWithControls(PictureDestany As Long, PictureSource As Long, Optional PositionX As Long = 0, Optional PositionY As Long = 0, Optional Width As Long = 0, Optional Height As Long = 0)
        'PictureDestany.Picture = Nothing
        'Get the hWnd of the screen
        Dim scrHwnd As Long
        scrHwnd = PictureSource
        
        'Now, assign an hDC to the hWnd we generated
        Dim shDC As Long
        shDC = GetDC(scrHwnd)
        
        'Determine the size of the screen
        'Dim screenWidth As Long, screenHeight As Long
        'screenWidth = Screen.Width \ Screen.TwipsPerPixelX
        'screenHeight = Screen.Height \ Screen.TwipsPerPixelY
       
        'Copy the pixel data from the screen into our form
        BitBlt PictureDestany, PositionX, PositionY, Width, Height, shDC, 0, 0, vbSrcCopy
            
        'Release our hold on the screen DC
        ReleaseDC scrHwnd, shDC
        
    End Sub
    heres how we use it:
    PrintWindowWithControls picturedestany.hdc, picturesource.hwnd, 0, 0, picturesource.width, picturesource.width
    (the code isn't completed, but works)
    i have 2 questions:
    1 - what it's the diference between these bitblt() to normal\standard bitblt()?
    2 - instead bitblt(), can i use the Stritchblt() or Transparentblt() api functions?
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •