Func _ScreenCapture_CaptureWnd($sFileName, $hWnd, $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $fCursor = True)
Local $tRect = _WinAPI_GetWindowRect($hWnd)
Local $aWinClientSize, $aWinPos, $iBorder
If BitAND(WinGetState($hWnd), 32) Then ;window is maximized
$aWinClientSize = WinGetClientSize($hWnd)
$aWinPos = WinGetPos($hWnd)
If Not @error Then $iBorder = ($aWinPos[2] - $aWinClientSize[0]) / 2
EndIf
$iLeft += DllStructGetData($tRect, "Left") + $iBorder
$iTop += DllStructGetData($tRect, "Top") + $iBorder
If $iRight = -1 Then $iRight = DllStructGetData($tRect, "Right") - DllStructGetData($tRect, "Left") - $iBorder
If $iBottom = -1 Then $iBottom = DllStructGetData($tRect, "Bottom") - DllStructGetData($tRect, "Top") - $iBorder
$iRight += DllStructGetData($tRect, "Left")
$iBottom += DllStructGetData($tRect, "Top")
If $iLeft > DllStructGetData($tRect, "Right") Then $iLeft = DllStructGetData($tRect, "Left")
If $iTop > DllStructGetData($tRect, "Bottom") Then $iTop = DllStructGetData($tRect, "Top")
If $iRight > DllStructGetData($tRect, "Right") Then $iRight = DllStructGetData($tRect, "Right")
If $iBottom > DllStructGetData($tRect, "Bottom") Then $iBottom = DllStructGetData($tRect, "Bottom")
Return _ScreenCapture_Capture($sFileName, $iLeft, $iTop, $iRight, $iBottom, $fCursor)
EndFunc