Sign in to follow this  
Followers 0
vtr

GDI error "a required resource was" [unavailable?]

1 post in this topic

#1 ·  Posted (edited)

I am trying to automate an application which lets me select items from a number of comboxes and syslistviews and then print out the resulting selection.

this worked reasonably well until i also tried to automate the print options using PrintWithOptions() below

For each such selection, PrintWithOptions() loops through all permutations of a number of checkboxes - done by setARLCheckbox() which checkboxes i cannot seem to address programmatically, so i resorted to pixelsearch to query their ischecked-status).

after a relatively small number of iterations (i counted as few as 66, depending on which computer this is running on), this fails with a #32770 popup stating ""a required resource was"". the application's controls do not get redrawn properly, as well as the controls of other applications' and of the os, including e.g. the taskbar (this is on windows xp sp 2).

a websearch reveals this to be a gdi message in mfc/vc programming (which, as other error messages seem to reveal, this application is based on) and the presumed cause leaking of GDI objects (brushes, pens, bitmaps and the like) which should be freed with deleteobject() (?)

i know nothing about gdi and mfc programming, but am wondering whether there is something i can improve in my autoit code to work around this (short from trying to intercept this #32770 popup and restarting the application to the desired selection which is what i am currently attempting with PrintWithOptionsResourceFailureChecker - adlibenable would not seem to work for me with this).

Thanks in advance,

Func PrintWithOptions($stlvalue, $translationlanguageIndex, $printDriver, $filename)
    Local $arrStlValues
    $filename = $filename & "_stl=" & $stlvalue
    $arrStlValues = StringSplit($stlvalue, "")
    setARLCheckbox($windowtitleTT, $CheckboxPrintsolutionsClassnameNN, Number($arrStlValues[1]))
    Sleep(500)
    setARLCheckbox($windowtitleTT, $CheckboxPrintTranslationsClassnameNN, Number($arrStlValues[2]))
    Sleep(500)
    setARLCheckbox($windowtitleTT, $CheckboxPrintGrammarlinksClassnameNN, Number($arrStlValues[3]))
    Sleep(500)
    $ret = ControlCommand($windowtitleTT, "", $DropdownTranslationLanguageClassnameNN, "SetCurrentSelection", $translationlanguageIndex)

    MouseClick("left", 40, 70)
    $ret = WinWaitActive($windowtitleprint, "", 6)
    If $ret == 0 Then
        $ret = WinWaitActive($windowtitleprint, "", 6)
        If $ret == 0 Then
            PrintWithOptionsResourceFailureChecker($currentLessonLanguageIndex, $currentLessonFamilyIndex, $currentContentTypeIndex, $currentActivityOrUnitOrCultureIndex, $currentSelectionIndex, True, $ret, $windowtitleprint, "mouseclick")
            MouseClick("left", 40, 70)
            $ret = WinWaitActive($windowtitleprint, "", 6)
        EndIf
    EndIf

    $ret = ControlCommand($windowtitleprint, "", "ComboBox1", "SelectString", $printDriver)
    If @error = 1 Then
        $ret = ControlCommand($windowtitleprint, "", "ComboBox1", "SelectString", $printDriver)
        If @error = 1 Then
            PrintWithOptionsResourceFailureChecker($currentLessonLanguageIndex, $currentLessonFamilyIndex, $currentContentTypeIndex, $currentActivityOrUnitOrCultureIndex, $currentSelectionIndex, False, @error, $windowtitleprint, "ComboBox1" & " " & "SelectString")
            MouseClick("left", 40, 70)
            $ret = WinWaitActive($windowtitleprint, "", 6)
            $ret = ControlCommand($windowtitleprint, "", "ComboBox1", "SelectString", $printDriver)
        EndIf
    EndIf

; more print dialogues code omitted for clarity

    Sleep(2000)
    $ret = WinActivate($windowtitleTT)
    $ret = WinWaitActive($windowtitleTT, "", 19)
    If $ret == 0 Then
        $windowText = WinGetText("")
        If StringInStr($windowText, "Do you want to replace it") > 0 Then
            $ret3 = ControlClick($windowtitlePDFSave, "", "Button2")
            If $ret3 = 0 Then
                Sleep(500)
                $ret3 = ControlClick($windowtitlePDFSave, "", "Button2")
            EndIf
            Sleep(500)
            $ret1 = WinWaitActive($windowtitlePDFSave, "", 2)
            If $ret1 = 1 Then
                $ret = ControlSetText($windowtitlePDFSave, "", "Edit1", "error" & $errorcounter)
            EndIf
        EndIf
        $ret = WinActivate($windowtitleTT)
        $ret = WinWaitActive($windowtitleTT, "", 59)
        If $ret == 0 Then
            PrintWithOptionsResourceFailureChecker($currentLessonLanguageIndex, $currentLessonFamilyIndex, $currentContentTypeIndex, $currentActivityOrUnitOrCultureIndex, $currentSelectionIndex, True, $ret, $windowtitleTT, "not coming up")
            $ret = WinActivate($windowtitleTT)
        EndIf
    EndIf
EndFunc   ;==>PrintWithOptions

Func setARLCheckbox($strWindowTitle, $ControlName, $isCheckedDesiredstatus)
    Local $PixelsearchError
    Local $absMaxX
    Local $absMaxY
    Local $absMinX
    Local $absMinY
    Local $aintCoord
    Local $blackcoord
    Local $isChecked
    Local $ret

    $ret = WinActivate($strWindowTitle, "")
    If $ret == 0 Then
        Exit
    EndIf

    $aintCoord = ControlGetPos($strWindowTitle, "", $ControlName)
    $absMinX = $aintCoord[0] + 3
    $absMinY = $aintCoord[1] + 3 + 26
    $absMaxX = $aintCoord[0] + 9
    $absMaxY = $aintCoord[1] + 9 + 26

    $isChecked = True
    $blackcoord = PixelSearch($absMinX, $absMinY, $absMaxX, $absMaxY, 0x000000)

    $PixelsearchError = @error
    If $PixelsearchError = 1 Then
        $isChecked = False
    EndIf

    If $isCheckedDesiredstatus <> $isChecked Then
        If $PixelsearchError = 1 Then
            ControlClick($strWindowTitle, "", $ControlName)
        Else
            MouseClick("left", $blackcoord[0], $blackcoord[1])
        EndIf
    EndIf
    $PixelsearchError = ""
    $absMaxX = ""
    $absMaxY = ""
    $absMinX = ""
    $absMinY = ""
    $aintCoord = ""
    $blackcoord = ""
    $isChecked = ""
    $ret = ""
EndFunc   ;==>setARLCheckbox
Edited by vtr

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