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
------------------
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
------------------
Comment