[DEVINTERN]
Stretch-COPY-Bitmap: always produces a copy (even if small enough)
Stretch-????-Bitmap: SUB instead of function? always discards old bitmap, returns old handle if small enough etc?

[API]
GetObjectA
GetDC
CreateCompatibleBitmap
ReleaseDC
CreateCompatibleDC
SelectObject
SetStretchBltMode
BitBlt
StretchBlt
DeleteDC
DeleteObject

[CODE]
Public Function StretchCopyBitmap(ByVal hBmpSource As Long, ByVal DesiredMaxWidth As Long, ByVal DesiredMaxHeight As Long, ByRef RealHeight As Long, ByRef RealWidth As Long) As Long
  Dim xLongA1(6) As Long
  Dim hDC1 As Long
  Dim hBmp1 As Long
  Dim hBmpOld1 As Long
  Dim hDC2 As Long
  Dim hBmpOld2 As Long
  Dim JustCopy As Boolean

  If Not GetObjectA(hBmpSource, 28&, ByVal VarPtr(xLongA1(0))) = 0& Then
    If xLongA1(1) > 0& And xLongA1(2) > 0& Then
      If xLongA1(1) > DesiredMaxWidth Or xLongA1(2) > DesiredMaxHeight Then
        If DesiredMaxWidth / DesiredMaxHeight > xLongA1(1) / xLongA1(2) Then
          RealWidth = DesiredMaxWidth
          RealHeight = DesiredMaxWidth * xLongA1(2) / xLongA1(1)
          Else
          RealHeight = DesiredMaxHeight
          RealWidth = DesiredMaxHeight * xLongA1(1) / xLongA1(2)
          End If
        Else
        RealWidth = DesiredMaxWidth
        RealHeight = DesiredMaxHeight
        JustCopy = True
        End If
      If RealWidth > 0& And RealHeight > 0& Then
        hDC1 = GetDC(0&)
        If Not hDC1 = 0& Then
          hBmp1 = CreateCompatibleBitmap(hDC1, RealWidth, RealHeight)
          Call ReleaseDC(0&, hDC1)
          If Not hBmp1 = 0& Then
            hDC1 = CreateCompatibleDC(0&)
            If Not hDC1 = 0& Then
              hBmpOld1 = SelectObject(hDC1, hBmp1)
              If Not hBmpOld1 = 0& Then
                hDC2 = CreateCompatibleDC(0&)
                If Not hDC2 = 0& Then
                  hBmpOld2 = SelectObject(hDC2, hBmpSource)
                  If Not hBmpOld2 = 0& Then
                    If JustCopy Then
                      If Not BitBlt(hDC1, 0&, 0&, RealWidth, RealHeight, hDC2, 0&, 0&, vbSrcCopy) = 0& Then
                        StretchCopyBitmap = hBmp1
                        End If
                      Else
                      Call SetStretchBltMode(hDC1, 4&)
                      If Not StretchBlt(hDC1, 0&, 0&, RealWidth, RealHeight, hDC2, 0&, 0&, xLongA1(1), xLongA1(2), vbSrcCopy) = 0& Then
                        StretchCopyBitmap = hBmp1
                        End If
                      Call SetStretchBltMode(hDC1, 3&)
                      End If
                    Call SelectObject(hDC2, hBmpOld2)
                    End If
                  Call DeleteDC(hDC2)
                  End If
                Call SelectObject(hDC1, hBmpOld1)
                End If
              Call DeleteDC(hDC1)
              End If
            If StretchCopyBitmap = 0& Then
              Call DeleteObject(hBmp1)
              End If
            End If
          End If
        End If
      End If
    End If
  End Function
