VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form BitBltExample 
   Caption         =   "BitBlt() Example"
   ClientHeight    =   3465
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4710
   LinkTopic       =   "Form1"
   ScaleHeight     =   3465
   ScaleWidth      =   4710
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command3 
      Caption         =   "Do the BitBlt"
      Height          =   375
      Left            =   120
      TabIndex        =   4
      Top             =   3000
      Width           =   2295
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Draw a Random Image"
      Height          =   375
      Left            =   120
      TabIndex        =   3
      Top             =   2520
      Width           =   2295
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Load Image Into Above PBox"
      Height          =   375
      Left            =   120
      TabIndex        =   2
      Top             =   2040
      Width           =   2295
   End
   Begin VB.PictureBox Picture2 
      Height          =   1695
      Left            =   2640
      ScaleHeight     =   1635
      ScaleWidth      =   1875
      TabIndex        =   1
      Top             =   120
      Width           =   1935
   End
   Begin VB.PictureBox Picture1 
      Height          =   1695
      Left            =   120
      ScaleHeight     =   1635
      ScaleWidth      =   1875
      TabIndex        =   0
      Top             =   120
      Width           =   1935
   End
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   0
      Top             =   0
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
End
Attribute VB_Name = "BitBltExample"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

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

Private Sub Command1_Click()
    With CommonDialog1
        .ShowOpen
        If Not .FileName = "" Then
            Picture1.Picture = LoadPicture(.FileName)
        End If
    End With
End Sub

Private Sub Command2_Click()
    Dim i As Long, j As Long
    For i = 0 To Picture1.ScaleWidth
        For j = 0 To Picture1.ScaleHeight
            Picture1.PSet (i, j), RGB(256 * Rnd, 256 * Rnd, 256 * Rnd)
        Next
    Next
End Sub

Private Sub Command3_Click()
    '' Parameters for BitBlt() function ;
    ''
    ''  (excerpt from MSDN (GDI: Platform SDK))
    ''    HDC hdcDest,      // handle to destination device context
    ''    int nXDest,       // x-coordinate of destination rectangle's upper-left corner
    ''    int nYDest,       // y-coordinate of destination rectangle's upper-left corner
    ''    int nWidth,       // width of destination rectangle
    ''    int nHeight,      // height of destination rectangle
    ''    HDC hdcSrc,       // handle to source device context
    ''    int nXSrc,        // x-coordinate of source rectangle's upper-left corner
    ''    int nYSrc,        // y-coordinate of source rectangle's upper-left corner
    ''    DWORD dwRop       // raster operation code

    BitBlt Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, _
            Picture1.hdc, 0, 0, vbSrcCopy
    Picture2.Refresh
End Sub

Private Sub Form_Load()
    Show
    MsgBox "Welcome to this BitBlt() example" & vbCrLf & vbCrLf & _
            "To see a sample BitBlt, select either of the first two" & vbCrLf & _
            "buttons. The first will allow you to select a file from" & vbCrLf & _
            "your drive to load, and the second will draw a random" & vbCrLf & _
            "image in the PictureBox." & vbCrLf & vbCrLf & _
            "note: Only a portion of the image up to the size of the" & vbCrLf & _
            "left hand PictureBox will be visible, and therefore only" & vbCrLf & _
            "that section will be blitted" & vbCrLf & vbCrLf & _
            "After you have an image in the first PictureBox, hit the" & vbCrLf & _
            "last button to do the blit"
    Picture1.AutoRedraw = True: Picture1.ScaleMode = 3
    Picture2.AutoRedraw = True: Picture2.ScaleMode = 3
End Sub
