Announcement

Collapse
No announcement yet.

CONTROL SET IMAGE failes after repitions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • CONTROL SET IMAGE failes after repitions

    Howdy!

    I have a program that changes a series of images, all via DDT, in a dialog based on each record. After changing records a few times, the images quit updating.

    So, to reproduce the problem, I wrote a little 48 line tester, which for each button click, changes an image. It, too, fails, in this case after about 750 reps.

    Has anyone else had such a problem?

    If anyone is interested, the test program follows. It refers to a resource file, which contains two small BMP's.

    All this program does is present a simple dialog. Each time Increment is clicked, a number counts (so I can see how long it takes to fail) and the image toggles between two images. Holding down the Enter key, the number counts quickly and the image flickers between the two BMP's. After about 700 counts, the image just flatly quits changing.

    Have I reached some limitation in Win-doze? Perhaps I am doing something wrong.

    Any suggestions or ideas would be GREATLY appreciated!!!

    Thanks

    Dan

    {Filename: toggle.rc}
    31 BITMAP CIRCLE.bmp
    32 BITMAP OPENCIR.bmp

    {filename: toggle.bas}
    %d001count = 10000
    %d001incr = 10001
    %d001image = 10002
    %d001cancel = 10003

    #COMPILE EXE

    #RESOURCE "toggle.pbr"

    #INCLUDE "win32api.inc"
    #INCLUDE "commctrl.inc"

    GLOBAL handled001 AS LONG

    DECLARE CALLBACK FUNCTION callbackd001

    FUNCTION winmain (BYVAL hinstance AS LONG, BYVAL hprevinstance AS LONG, lpcmdline AS ASCIIZ PTR, BYVAL icmdshow AS LONG) AS LONG
    DIALOG NEW 0, "Toggle Screen", , , 100, 75, %WS_CAPTION + %WS_SYSMENU + %WS_THICKFRAME + %WS_MINIMIZEBOX, to handled001

    CONTROL ADD LABEL, handled001, %d001count, "1", 10, 10, 40, 14
    CONTROL ADD BUTTON, handled001, %d001incr, "Increment", 10, 30, 40, 14
    CONTROL ADD BUTTON, handled001, %d001cancel, "Cancel", 10, 50, 40, 14
    CONTROL ADD IMAGE, handled001, %d001image, "#32", 60, 10, 20, 20, %SS_REALSIZE + %SS_CENTERIMAGE

    DIALOG SHOW MODAL handled001, CALL callbackd001
    END FUNCTION

    CALLBACK FUNCTION callbackd001
    STATIC s AS STRING

    SELECT CASE CBMSG
    CASE %WM_COMMAND
    SELECT CASE CBWPARAM
    CASE %d001cancel
    DIALOG END handled001

    CASE %d001incr
    CONTROL GET TEXT handled001, %d001count TO s
    IF VAL(s) / 2 = VAL(s) \ 2 THEN
    CONTROL SET IMAGE handled001, %d001image, "#31"
    ELSE
    CONTROL SET IMAGE handled001, %d001image, "#32"
    END IF
    CONTROL SET TEXT handled001, %d001count, LTRIM$(STR$(VAL(s) + 1))
    DIALOG DOEVENTS
    END SELECT
    END SELECT
    END FUNCTION



  • #2
    Dan;

    I don't know exactly how DDT treats the Image, but it is possible that each time you use the Set Image command, a new "Instance" of the resource Image is created (a new handle).

    When you create a new Bitmap handle, the old one must be destroyed. If DDT isn't destroying the Images handle, then you are ending up with hundreds of handles.

    The GDI has this thing for "overloading" it with too many handles and Images and Icons can just disappear.

    You need to find a way of destroying the old Image handle after the new one is set to the control.

    Normally when using the API you would Load the Images one time and simply swap the handles. DDT is using the resources name (not the handle) as a parameter, which may mean it creates a new handle everytime.

    This is something only the guys at PB can explain to you, since only they know how DDT works under the hood.



    ------------------
    Chris Boss
    Computer Workshop
    Developer of "EZGUI"
    http://cwsof.com
    http://twitter.com/EZGUIProGuy

    Comment


    • #3
      Hi Dan.

      Why DIALOG DOEVENTS ?
      I tested Your code
      I have 100mb memory and I my test is 1100 times.
      You are correct -
      control image is lose...

      I think - the modification image control is happen don't correct,
      =don't clear memory at the change bitmap=.I have this problem
      earlier, but only with =brush=,when - I don't clear memory for
      new brush.

      Regard
      V.Shulakov




      ------------------
      Spherical Panorama Inc. Virtual Reality for: Real Estate, Tourism Advertisment.

      Comment


      • #4
        Guys --
        CONTROL SET IMAGE each time executes LoadImage.
        It's clear if to watch memory sizes in Windows Task Manager (NT)
        One possible solution:
        two CONTROL ADD IMAGE with different bitmaps, but with the same location.
        In callback for button show #1 / hide #2 and reverse, something like this:

        Code:
             #Compile Exe
             #Resource "toggle.pbr"
             #Include "win32api.inc"
             Global handled001&, hCtl1&, hCtl2&, s&
        
             CallBack Function callbackd001
                Select Case CbMsg
                   Case %WM_COMMAND
                     Select Case CbWparam
                        Case %d001cancel
                           Dialog End handled001
                        Case %d001incr
                           Incr s: ShowWindow hCtl1&, 1 - (s Mod 2): ShowWindow hCtl2&, (s Mod 2)
                           Control Set Text handled001, %d001count, Mid$(Str$(s), 2)
                     End Select
               End Select
            End Function
        
            Function WinMain (ByVal hinstance As Long, ByVal hprevinstance As Long, lpcmdline As Asciiz Ptr, ByVal icmdshow As Long) As Long
               Dialog New 0, "Toggle Screen", , , 100, 75, %WS_CAPTION + %WS_SYSMENU + %WS_THICKFRAME + %WS_MINIMIZEBOX, To handled001
               Control Add Label, handled001, %d001count, "1", 10, 10, 40, 14: s& = 1
               Control Add Button, handled001, %d001incr, "Increment", 10, 30, 40, 14
               Control Add Button, handled001, %d001cancel, "Cancel", 10, 50, 40, 14
               Control Add Image, handled001, %d001image1, "#31", 60, 10, 20, 20, %SS_REALSIZE + %SS_CENTERIMAGE
               Control Add Image, handled001, %d001image2, "#32", 60, 10, 20, 20, %SS_REALSIZE + %SS_CENTERIMAGE
               Control Handle handled001, %d001image1 To hCtl1&
               Control Handle handled001, %d001image2 To hCtl2&
               Dialog Show Modal handled001, Call callbackd001
            End Function
        [This message has been edited by Semen Matusovski (edited February 23, 2000).]

        Comment


        • #5
          CONTROL SET IMAGE does not release the previous image handle, that is the responsibility of the programmer. Afterall, it is possible you may be doing something else with the image... the compiler has no way of knowing and does not try to "guess".

          The solution to this "problem" is simple... release the image when it no longer required. Here is a rewrite of this "app", correctign the problem and "streamlining" one or two other minor points at the same time...

          Code:
          #COMPILE EXE
          #INCLUDE "win32api.inc"
          #RESOURCE "toggle.pbr"
           
          %d001count = 10000
          %d001incr = 10001
          %d001image = 10002
          %d001cancel = 10003
           
          DECLARE CALLBACK FUNCTION callbackd001
           
          FUNCTION WINMAIN (BYVAL hinstance AS LONG, BYVAL hprevinstance AS LONG, lpcmdline AS ASCIIZ PTR, BYVAL icmdshow AS LONG) AS LONG
          LOCAL handled001 AS LONG ' only local required, as CBHNDL is used in the callbacks.. easier than using a global...
          DIALOG NEW 0, "Toggle Screen", , , 100, 75, %WS_CAPTION + %WS_SYSMENU + %WS_THICKFRAME + %WS_MINIMIZEBOX, TO handled001
          
          CONTROL ADD LABEL, handled001, %d001count, "1", 10, 10, 40, 14
          CONTROL ADD BUTTON, handled001, %d001incr, "Increment", 10, 30, 40, 14
          CONTROL ADD BUTTON, handled001, %d001cancel, "Cancel", 10, 50, 40, 14
          CONTROL ADD IMAGE, handled001, %d001image, "#32", 60, 10, 20, 20, %SS_REALSIZE + %SS_CENTERIMAGE
          
          DIALOG SHOW MODAL handled001, CALL callbackd001
          END FUNCTION
           
          CALLBACK FUNCTION callbackd001
          STATIC s AS STRING  ' static not really required in this code
          LOCAL hBmp AS LONG 
           
          SELECT CASE CBMSG
              CASE %WM_COMMAND
                  SELECT CASE CBWPARAM
                      CASE %d001cancel
                          DIALOG END CBHNDL
          
                      CASE %d001incr
                          CONTROL GET TEXT CBHNDL, %d001count TO s
                          CONTROL SEND CBHNDL, %d001image, %STM_GETIMAGE, %IMAGE_BITMAP, 0 TO hBmp
                          IF VAL(s) / 2 = VAL(s) \ 2 THEN
                              CONTROL SET IMAGE CBHNDL, %d001image, "#31"
                          ELSE
                              CONTROL SET IMAGE CBHNDL, %d001image, "#32"
                          END IF
                          CONTROL SET TEXT CBHNDL, %d001count, FORMAT$((VAL(s) + 1))
                          DeleteObject hBmp
                  END SELECT
              END SELECT
          END FUNCTION

          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment


          • #6
            Thanks everyone! As always, the PowerBasic community comes through! Y'all are the greatest.

            Dan

            ------------------

            Comment

            Working...
            X