Final revision of DrawImageToDC function. Leaned to only necessary code.
Note: This change is already incorporated into the final download version in the original post.
Code:Public Function DrawImageToDC(ByVal nHdc As Long, ByVal nImage As Long, Optional ByVal dX As Single, _ Optional ByVal dY As Single, Optional ByVal dW As Single, _ Optional ByVal dH As Single, Optional ByVal sX As Single, _ Optional ByVal sY As Single, Optional ByVal sW As Single, _ Optional ByVal sH As Single) '- Draws passed image at specified x, y coordinates '- and at specified width & height. '- Returns zero if successful. Dim ImGraphics As Long Dim lRet As Long If (dW = 0) Then dW = m_Width If (dH = 0) Then dH = m_Height If (sW = 0) Then sW = m_Width If (sH = 0) Then sH = m_Height lRet = GdipCreateFromHDC(nHdc, ImGraphics) If lRet <> 0 Then Exit Function '- Can't create graphics object so bail out lRet = GdipDrawImageRectRectI(ImGraphics, nImage, dX, dY, dW, dH, sX, sY, sW, sH, 2) If lRet = 0 Then '- No error DrawImageToDC = 0 Else '- Something went wrong GdipDeleteGraphics (ImGraphics) GdipDisposeImage nImage DrawImageToDC = lRet End If '- Clean up If ImGraphics Then GdipDeleteGraphics ImGraphics End Function




Reply With Quote