Search the Community
Showing results for tags '2003 GDI GDIPLUS'.
-
I have a program that takes a screenshot (Part of the Tesseract AutoIT project). The trouble is in the CaptureToTIFF function BUT ONLY on Windows Server 2003. Everything works great on XP or 7. I've put the function in its entirety below but I know where, in particular, the problem lies. To start: I can get the handle to the screenshot with either of these commands... $hBitmap2 = _ScreenCapture_CaptureWnd("", $hwnd2, 0, 0, -1, -1, False) $hBitmap3 = _ScreenCapture_CaptureWnd(@MyDocumentsDir & "\GDIPlus_Image.jpg", $hwnd2,0, 0, -1, -1, False) The problem occurs here: $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap3) On Windows Server 2003, the function fails to return a handle to the Bitmap object. It returns "0" every time. Can anyone tell me why this would be? Our server does have this patch installed but I don't know if it's related to the problem or not: http://support.microsoft.com/kb/958911 Thanks! Func CaptureToTIFF($win_title = "", $win_text = "", $ctrl_id = "", $sOutImage = "", $scale = 1, $left_indent = 0, $top_indent = 0, $right_indent = 0, $bottom_indent = 0) ;MsgBox(0,"","TIFF Scale: " & $scale) Local $hWnd, $hwnd2, $hDC, $hBMP, $hImage1, $hGraphic, $CLSID, $tParams, $pParams, $tData, $i = 0, $hImage2, $pos[4] Local $Ext = StringUpper(StringMid($sOutImage, StringInStr($sOutImage, ".", 0, -1) + 1)) ;Local $giTIFColorDepth = 24 Local $giTIFColorDepth = 24 Local $giTIFCompression = $GDIP_EVTCOMPRESSIONNONE ;MsgBox(0,"Looking for this window title1",$win_title) ; If capturing a control if StringCompare($ctrl_id, "") <> 0 Then $hwnd2 = ControlGetHandle($win_title, $win_text, $ctrl_id) $pos = ControlGetPos($win_title, $win_text, $ctrl_id) Else ; If capturing a window ;MsgBox(0,"Looking for this window title2",$win_title) if StringCompare($win_title, "") <> 0 Then $hwnd2 = WinGetHandle($win_title, $win_text) MsgBox(0,"","window handle is " & $hwnd2) $pos = WinGetPos($win_title, $win_text) Else ; If capturing the desktop $hwnd2 = "" $pos[0] = 0 $pos[1] = 0 $pos[2] = @DesktopWidth $pos[3] = @DesktopHeight EndIf EndIf ; Capture an image of the window / control if IsHWnd($hwnd2) Then $winactval = WinActivate($win_title, $win_text) MsgBox(0,"$winactval",$winactval) MsgBox(0,"winhan",$hwnd2) ;THE TROUBLE IS HERE! $hBitmap2 = _ScreenCapture_CaptureWnd("", $hwnd2, 0, 0, -1, -1, False) $hBitmap3 = _ScreenCapture_CaptureWnd(@MyDocumentsDir & "\GDIPlus_Image.jpg", $hwnd2,0, 0, -1, -1, False) msgbox(0,"$hBitmap2",$hBitmap2) msgbox(0,"$hBitmap3",$hBitmap3) Else $hBitmap2 = _ScreenCapture_Capture("", 0, 0, -1, -1, False) EndIf _GDIPlus_Startup () ; Convert the image to a bitmap $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap3) MsgBox(0,"","$hImage2 value -Failed if 0- : " & $hImage2) $hWnd = _WinAPI_GetDesktopWindow() $hDC = _WinAPI_GetDC($hWnd) $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, ($pos[2] * $scale) - ($right_indent * $scale), ($pos[3] * $scale) - ($bottom_indent * $scale)) _WinAPI_ReleaseDC($hWnd, $hDC) $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hBMP) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1) _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage2, 0 - ($left_indent * $scale), 0 - ($top_indent * $scale), ($pos[2] * $scale) + $left_indent, ($pos[3] * $scale) + $top_indent) $CLSID = _GDIPlus_EncodersGetCLSID($Ext) ; Set TIFF parameters $tParams = _GDIPlus_ParamInit(2) $tData = DllStructCreate("int ColorDepth;int Compression") DllStructSetData($tData, "ColorDepth", $giTIFColorDepth) DllStructSetData($tData, "Compression", $giTIFCompression) _GDIPlus_ParamAdd($tParams, $GDIP_EPGCOLORDEPTH, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "ColorDepth")) _GDIPlus_ParamAdd($tParams, $GDIP_EPGCOMPRESSION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Compression")) If IsDllStruct($tParams) Then $pParams = DllStructGetPtr($tParams) ; Save TIFF and cleanup _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID, $pParams) if FileExists($debugdir&"debug.txt") then Msgbox(0,"",$hImage1&"====="&$sOutImage&"====="&$CLSID&"====="&$pParams) EndIf _GDIPlus_ImageDispose($hImage1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_GraphicsDispose ($hGraphic) _WinAPI_DeleteObject($hBMP) ;added this. _WinAPI_DeleteObject($hBitmap2) _WinAPI_DeleteObject($hBitmap3) _GDIPlus_Shutdown() EndFunc