I found the source of the GDI memory leak.
The root-cause was not in destroying the controls but setting their fonts.
The function:
Code: Select all
control_setfont........
creates a font object locally but does not destroy it!
I have split the function into 3 sub / functions that 1 create a font object, 2 assigns a font to a control and 3 deletes the font object!
Code: Select all
'=============================================================================================
function control_createfont(font as string, _
h as long = 16, _
w as long = 8, _
wt as long = 0, _
it as long = False, _
ul as long = False, _
so as long = False) as HFONT
'<-----Set font for a control. Parameters:
'<-----Control hWnd = Handle to the control
'<-----Font = e.g. "Courier New", "Arial", "New Times Roman"
'<-----h = Logical height of the font
'<-----w = Logical average width of font
'<-----wt = Font weight (e.g. FW_THIN, FW_NORMAL, FW_BOLD)
'<-----it = Italic: True = yes
'<-----ul = Underline: True = yes
'<-----so = Strikout: True = yes
return CreateFont(h, _
w, _
0, _
0, _
wt, _
it, _
ul, _
so, _
ANSI_CHARSET, _
FALSE, _
FALSE, _
DEFAULT_QUALITY, _
DEFAULT_PITCH or FF_ROMAN, _
font)
end function
'=============================================================================================
sub control_deletefont(hfont as HFONT)
DeleteObject(hfont)
end sub
'=============================================================================================
sub control_setfont(hwnd as HWND, hfont as HFONT)
SendMessage(hwnd, WM_SETFONT, cast(WPARAM, hfont), true)
end sub
The GDI memory leak is now gone!