VERSION 5.00
Begin VB.Form BitBltExample2 
   Caption         =   "BitBlt() Example 2"
   ClientHeight    =   6975
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4710
   LinkTopic       =   "Form1"
   ScaleHeight     =   6975
   ScaleWidth      =   4710
   StartUpPosition =   3  'Windows Default
   Begin VB.PictureBox srcPicture 
      Height          =   1695
      Index           =   2
      Left            =   120
      ScaleHeight     =   1635
      ScaleWidth      =   1875
      TabIndex        =   6
      Top             =   3720
      Width           =   1935
   End
   Begin VB.PictureBox srcPicture 
      Height          =   1695
      Index           =   1
      Left            =   120
      ScaleHeight     =   1635
      ScaleWidth      =   1875
      TabIndex        =   5
      Top             =   1920
      Width           =   1935
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Do the BitBlt"
      Height          =   375
      Left            =   120
      TabIndex        =   4
      Top             =   6480
      Width           =   2295
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Draw a Random Image"
      Height          =   375
      Left            =   120
      TabIndex        =   3
      Top             =   6000
      Width           =   2295
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Load Image"
      Height          =   375
      Left            =   120
      TabIndex        =   2
      Top             =   5520
      Width           =   2295
   End
   Begin VB.PictureBox dstPicture1 
      Height          =   5295
      Left            =   2640
      ScaleHeight     =   5235
      ScaleWidth      =   1875
      TabIndex        =   1
      Top             =   120
      Width           =   1935
   End
   Begin VB.PictureBox srcPicture 
      Height          =   1695
      Index           =   0
      Left            =   120
      ScaleHeight     =   1635
      ScaleWidth      =   1875
      TabIndex        =   0
      Top             =   120
      Width           =   1935
   End
   Begin VB.PictureBox CommonDialog1 
      Height          =   480
      Left            =   0
      ScaleHeight     =   420
      ScaleWidth      =   1140
      TabIndex        =   7
      Top             =   0
      Width           =   1200
   End
End
Attribute VB_Name = "BitBltExample2"
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 lastPictureBoxDone As Long

Private Sub Command1_Click()
    With CommonDialog1
        .ShowOpen
        If Not .FileName = "" Then
            srcPicture(lastPictureBoxDone).Picture = LoadPicture(.FileName)
            lastPictureBoxDone = (lastPictureBoxDone + 1) Mod 3
        End If
    End With
End Sub

Private Sub Command2_Click()
    Dim i As Long, j As Long
    For i = 0 To srcPicture(lastPictureBoxDone).ScaleWidth
        For j = 0 To srcPicture(lastPictureBoxDone).ScaleHeight
            srcPicture(lastPictureBoxDone).PSet (i, j), RGB(256 * Rnd, 256 * Rnd, 256 * Rnd)
        Next
    Next
    srcPicture(lastPictureBoxDone).Refresh
    lastPictureBoxDone = (lastPictureBoxDone + 1) Mod 3
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

    Dim i As Long
    For i = 0 To 2
        BitBlt dstPicture1.hDC, 0, (srcPicture(i).ScaleHeight * i) + (10 * i), dstPicture1.ScaleWidth, dstPicture1.ScaleHeight, _
                srcPicture(i).hDC, 0, 0, vbSrcCopy
    Next
    dstPicture1.Refresh
End Sub

Private Sub Form_Load()
    Show
    MsgBox "Welcome to this BitBlt() example" & vbCrLf & vbCrLf & _
            "To see the BitBlt, load up three images, be they" & vbCrLf & _
            "random or otherwise. The first time you press either" & vbCrLf & _
            "of the image buttons, the first picturebox is referenced," & vbCrLf & _
            "the second time; the second picturebox, third time; third." & vbCrLf & _
            "If you press either button again, they will reference the" & vbCrLf & _
            "first box again and so on." & vbCrLf & _
            "This is acheived simply through use of the Mod() function" & vbCrLf & vbCrLf & _
            "Once you have loaded your images, then hit 'Do the BitBlt()'"
    
    Dim i As Long
    For i = 0 To 2
        srcPicture(i).AutoRedraw = True
        srcPicture(i).ScaleMode = 3
    Next
    dstPicture1.AutoRedraw = True: dstPicture1.ScaleMode = 3
End Sub
