VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form StretchBltExample 
   Caption         =   "StretchBlt() Example"
   ClientHeight    =   3465
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6510
   LinkTopic       =   "Form1"
   ScaleHeight     =   3465
   ScaleWidth      =   6510
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command3 
      Caption         =   "Do the stretch"
      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          =   3255
      Left            =   2640
      ScaleHeight     =   3195
      ScaleWidth      =   3675
      TabIndex        =   1
      Top             =   120
      Width           =   3735
   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 = "StretchBltExample"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Declare Function StretchBlt 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 nSrcWidth As Long, ByVal nSrcHeight 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 StretchBlt() function ;
    ''
    ''  (excerpt from MSDN (GDI: Platform SDK))
    ''    HDC hdcDest,      // handle to destination device context
    ''    int nXOriginDest, // x-coordinate of upper-left corner of dest. rectangle
    ''    int nYOriginDest, // y-coordinate of upper-left corner of dest. rectangle
    ''    int nWidthDest,   // width of destination rectangle
    ''    int nHeightDest,  // height of destination rectangle
    ''    HDC hdcSrc,       // handle to source device context
    ''    int nXOriginSrc,  // x-coordinate of upper-left corner of source rectangle
    ''    int nYOriginSrc,  // y-coordinate of upper-left corner of source rectangle
    ''    int nWidthSrc,    // width of source rectangle
    ''    int nHeightSrc,   // height of source rectangle
    ''    DWORD dwRop       // raster operation code
    StretchBlt Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, _
                Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, vbSrcCopy
    Picture2.Refresh
End Sub

Private Sub Form_Load()
    Show
    MsgBox "Welcome to this StretchBlt() example" & vbCrLf & vbCrLf & _
            "To see a sample stretch, 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 stretched" & vbCrLf & vbCrLf & _
            "After you have an image in the first PictureBox, hit the" & vbCrLf & _
            "last button to do the stretch"
    Picture1.AutoRedraw = True: Picture1.ScaleMode = 3
    Picture2.AutoRedraw = True: Picture2.ScaleMode = 3
End Sub
