Announcement

Collapse
No announcement yet.

IMGButton bug?

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

  • IMGButton bug?

    It seems to me the GDI memory fairly fast evaporates when changing the images in image buttons.
    Here is a little test program:
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    #RESOURCE "Test.PBR"

    GLOBAL hDlg AS LONG
    GLOBAL tTimer AS LONG
    GLOBAL counter AS LONG
    $Image1 = "EmptyWhite"
    $Image2 = "EmptyBlack"
    DECLARE CALLBACK FUNCTION DlgProc
    FUNCTION PBMAIN () AS LONG
    #REGISTER NONE

    DIALOG NEW %NULL, "Test", ,, 340, 230, %WS_MINIMIZEBOX OR %DS_3DLOOK OR %DS_CENTER OR %DS_MODALFRAME OR %WS_SYSMENU, 0 TO hDlg

    CONTROL ADD IMGBUTTON, hDlg, 1001, $Image1, 0, 0, 30, 28, %BS_FLAT
    CONTROL ADD IMGBUTTON, hDlg, 1002, $Image2, 30, 0, 30, 28, %BS_FLAT
    CONTROL ADD LABEL, hDlg, 1003, "Counter: 0", 250, 65, 48, 14

    DIALOG SHOW MODAL hDlg CALL DlgProc
    END FUNCTION

    CALLBACK FUNCTION DlgProc
    SELECT CASE CBMSG
    CASE %WM_INITDIALOG
    tTimer = SetTimer(0, 0, 100, CODEPTR( ThinkingProc ))
    CASE %WM_DESTROY
    IF tTimer > 0 THEN
    KillTimer 0, tTimer
    END IF
    END SELECT
    END FUNCTION
    SUB ThinkingProc(BYVAL hWnd AS LONG, BYVAL uMsg AS LONG, BYVAL idEvent AS LONG, BYVAL lngSysTime AS LONG)
    DIM txt AS STRING
    'switch images
    INCR counter
    IF counter MOD 2 = 0 THEN
    CONTROL SET IMGBUTTON hDlg, 1001, $Image2
    CONTROL SET IMGBUTTON hDlg, 1002, $Image1
    ELSE
    CONTROL SET IMGBUTTON hDlg, 1001, $Image1
    CONTROL SET IMGBUTTON hDlg, 1002, $Image2
    END IF
    txt = "Counter: " & FORMAT$(counter)
    CONTROL SET TEXT hDlg, 1003, txt
    END SUB

    The Test.rc file looks like:
    #INCLUDE "resource.h"
    EmptyBlack BITMAP C:\Bmp\EmptyBlack.bmp
    EmptyWhite BITMAP C:\Bmp\EmptyWhite.bmp

    where the two images are two squares with the size of the button, in different colors.

    On my machine using Windows'98 about at 340 counter value the program consumes all the GDI memory (the colors will no longer change).

    Unloading the program from memory releases the memory.
    What is the workaround?


    Sincerely,


    Peter Redei


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

  • #2
    Peter;

    If I remember correctly, the DDT Image commands "load" a Bitmap
    each time you use them and you are not simply toggling between
    Bitmaps, but loading a new instance of the Bitmap everytime.

    If your toggling of the images continue, you are loading hundreds
    of instances of the bitmaps (big GDI drain).

    What you need to do, is either destroy (deleteobject) the previous bitmap
    after the new one is loaded or load the bitmaps one time and then
    use SendMessage to send the control the new Bitmap Handle.

    DDT is loading the Bitmap again and again. Bitmaps should be
    loaded once and then only the "handle" being passed to the
    control, which DDT does not do.

    You simply must resort to the API to attach the Bitmap to a control.



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

    Comment


    • #3
      this has been covered a few times here before... take a look at http://www.powerbasic.com/support/pb...ead.php?t=1826


      ------------------
      lance
      powerbasic support
      mailto:[email protected][email protected]</a>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Thank you Lance and Chris.
        Lance, your "trick" seems to work fine with an Image control.
        It also worked with the the IMGBUTTON control using %BM_GETIMAGE instead of %STM_GETIMAGE..

        Using Chris advise the CONTROL SEND hDlg, 1001, %BM_SETIMAGE, %IMAGE_BITMAP, hBmp
        also a good solution.

        Thank you for both.

        Sincerely,


        Peter Redei



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

        Comment

        Working...
        X