Sign in to follow this  
Followers 0
jim read

GDIPlus an Vmware

2 posts in this topic

I am trying to display tiff files with the data that is associated with it on the screen at the same time.

This appears to work ok on my windows 7 computer and another windows xp computer but stopes after displaying the object around 10-12 times on a XP machine that is a vmware client.

I can not figure out why this is the case. In the reproducer i have included here there are only two tiff files click down then up and repeat the process there is a list box that shows the number of times you have done this. On the VMware xp computer is works 10 - 12 times then does not display the image. Any insite would be apreciated.

#Include <GuiListView.au3>

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
;#include <WinAPI.au3>



#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("sNiceName", 1002, 702, 192, 124)
$ListView1 = GUICtrlCreateListView("Seq #|Account Number|Amount", 140, 380, 353, 281, -1, BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
$ListView1_0 = GUICtrlCreateListViewItem("1|Tiff 1| Image ", $ListView1)
$ListView1_1 = GUICtrlCreateListViewItem("2|Tiff 2| Image ", $ListView1)
$Input1 = GUICtrlCreateInput("", 512, 408, 121, 21)
$UP = GUICtrlCreateButton("UP", 652, 395, 75, 25, $WS_GROUP)
$Down = GUICtrlCreateButton("Down", 652, 420, 75, 25, $WS_GROUP)
$ct= GUICtrlCreateLabel("", 502, 520, 75, 25)
$file_in_use = GUICtrlCreateLabel("", 16, 672, 961, 17, $SS_SUNKEN)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
guictrlsetdata($ct,0)
$cnt = 0
Dim $AccelKeys[2][2] = [["{UP}", $UP],["{DOWN}", $Down]]
GUISetAccelerators($AccelKeys)
$cLine = 0
$imagenumber =1
Dim $XYarray[2]
$XYarray[0] = 0
$XYarray[1] = 0

$XYarray = _MainImage("Tiff1.tif", $Form1, $XYarray)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $UP
            If $cLine >= 1 Then
                $cnt = $cnt + 1
                _GUICtrlListView_SetItemSelected($ListView1, $cLine, False, False)
                $cLine = $cLine - 1
                _GUICtrlListView_SetItemSelected($ListView1, $cLine, True, True)
                $oldAmount = _GUICtrlListView_GetItemText($ListView1, $cLine, 2)
                $imagenumber = $imagenumber - 1
                $XYarray = _MainImage("Tiff" & $imagenumber & ".tif", $Form1, $XYarray)
                GUICtrlSetData($file_in_use, "Tiff" & $imagenumber & ".tif")
                GUICtrlSetData($Input1, "UP")
                GUICtrlSetState($Input1, $GUI_FOCUS)
                guictrlsetdata($ct,$cnt)
            EndIf
        Case $Down
            ConsoleWrite(@cr & "Down cline is " &$cline & "ITem count is " & _GUICtrlListView_GetItemCount($ListView1))
            ConsoleWrite(@cr & "Image number is " & $imagenumber )

            If $cLine < _GUICtrlListView_GetItemCount($ListView1) - 1 Then

                _GUICtrlListView_SetItemSelected($ListView1, $cLine, False, False)
                $cLine = $cLine + 1
                _GUICtrlListView_SetItemSelected($ListView1, $cLine, True, True)
                $oldAmount = _GUICtrlListView_GetItemText($ListView1, $cLine, 2)
                $imagenumber = $imagenumber + 1
                $XYarray = _MainImage("Tiff" & $imagenumber & ".tif", $Form1, $XYarray)
                GUICtrlSetData($file_in_use, "Tiff" & $imagenumber & ".tif")
                GUICtrlSetData($Input1, "Down")
                GUICtrlSetState($Input1, $GUI_FOCUS)
                $cnt = $cnt + 1
                guictrlsetdata($ct,$cnt)
            EndIf
    EndSwitch
WEnd










Func _MainImage($sFile, $hGUI, $XYarray)
    Local $hBMP, $hBitmap, $hImage, $iX, $iY, $hClone, $aGS ;$hGraphic,
    ;local $XYarray[2]
    ; Create GUI
    ; $hGUI = GUICreate("GDI+", 800, 400)
    ;GUISetState()
    ConsoleWrite(@CR & " Main Image  File is " & $sFile & " hGui is " & $hGUI)
    ConsoleWrite(@CR & " $XYarray[0] " & $XYarray[0] & " $XYarray[1] " & $XYarray[1])
    ; Initialize GDI+ library
    _GDIPlus_Startup()
    $aGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
        
    $hBrush1 = _GDIPlus_BrushCreateSolid()
    _GDIPlus_BrushSetSolidColor($hBrush1, 0xFFF0F0F0)
    $gdiResult = _GDIPlus_GraphicsFillRect($aGraphic, 0, 0, $XYarray[0], $XYarray[1], $hBrush1)
    ConsoleWrite(@CR & "GDI RESULT  _GDIPlus_GraphicsFillRect($aGraphic, 0, 0, $XYarray[0], $XYarray[1], $hBrush1) " & $gdiResult)
    _GDIPlus_BrushDispose($hBrush1)
    _GDIPlus_GraphicsDispose($aGraphic)




    ; Draw bitmap to GUI
    $hBitmap = _GDIPlus_BitmapCreateFromFile($sFile)
    $iX = _GDIPlus_ImageGetWidth($hBitmap)
    $iY = _GDIPlus_ImageGetHeight($hBitmap)
    ;$XYarray[0]=$iX
    ;$XYarray[1]=$iY
    ; MsgBox(0,"","X = " & $iX & @cr & "Y = " & $iY)
    $aGS = _GetScale($iX, $iY, 800)
    ;  _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage,0, 0, $aGS[2], $aGS[3])
    $XYarray[0] = $aGS[2]
    $XYarray[1] = $aGS[3]
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    ConsoleWrite(@CR & "hGraphic " & $hGraphic)
    ;_GDIPlus_GraphicsDrawImage ($hGraphic, $hBitmap, 0, 0)
    $gdiResult = _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $aGS[2], $aGS[3])
    ConsoleWrite(@CR & "GDI RESULT  _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $aGS[2], $aGS[3]) " & $gdiResult)
    ConsoleWrite(@CR & "  $aGS[2], $aGS[3] " & $aGS[2] & " - " & $aGS[3])
    ; Clean up resources
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_BitmapDispose($hBitmap)
    



    ; Shut down GDI+ library
    _GDIPlus_Shutdown()

    ; Loop until user exits
    ;   Do
    ;   Until GUIGetMsg() = $GUI_EVENT_CLOSE

    Return $XYarray
EndFunc   ;==>_MainImage

Func _GetScale($iW, $iH, $iWH)
    Local $aRet[4]
    If $iW <= $iWH And $iH <= $iWH Then
        $aRet[2] = $iW
        $aRet[3] = $iH
        $aRet[0] = ($iWH - $aRet[2]) / 2
        $aRet[1] = ($iWH - $aRet[3]) / 2
    ElseIf $iW > $iH Then
        $aRet[2] = $iWH
        $aRet[3] = $iH / ($iW / $iWH)
        $aRet[0] = 0
        $aRet[1] = ($iWH - $aRet[3]) / 2
    ElseIf $iW < $iH Then
        $aRet[2] = $iW / ($iH / $iWH)
        $aRet[3] = $iWH
        $aRet[0] = ($iWH - $aRet[2]) / 2
        $aRet[1] = 0
    ElseIf $iW = $iH Then
        $aRet[2] = $iWH
        $aRet[3] = $iWH
        $aRet[0] = 0
        $aRet[1] = 0
    EndIf
    Return $aRet
EndFunc   ;==>_GetScale

GDI- Vmware.zip

Share this post


Link to post
Share on other sites



I SOLVED IT....

Thanks for looking but the problem was that Hardware Acceleration needed to be turned off on the VMware client (Windows XP) and the script started displaying properly

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0