﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
1655	GUICtrlSetImage issue on static controls	trancexx		"This function causes a memory leak (GDI objects) in combination with STM_SETIMAGE or STM_SETICON messages send directly to the control.
Seems this function destroys images assigned '''only''' by a previous call to itself (or those set when creating the control).
If some image is set with GUICtrlSendMsg it won't be destroyed. 
I guess there is nothing wrong with that logic except it's, in described situation, setting new image without destroying the old one, therefore incrementing overall ''GDI Objects'' count only because it's not aware of the already assigned image.
More proper would be to destroy previously assigned image regardless of how it's set.

This can be concluded by carefully(!) examining the effects of e.g. this code:
{{{
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
Opt(""GUIOnEventMode"", 1)


Global $hIconNew, $hIconOld

Global $hGUI = GUICreate(""GUICtrlCreateIcon"")

GUISetOnEvent($GUI_EVENT_CLOSE, ""_Quit"")
Global $hIcoControl = GUICtrlCreateIcon("""", """", 20, 75, 32, 32) ; no icon
GUISetState()




While 1

	$hIconNew = _GetIcon(""shell32.dll"", 8, 32)
	ConsoleWrite(""$hIconNew = "" & $hIconNew & @CRLF)
	;GUICtrlSendMsg($hIco, 368, $hIcon, 0) ; STM_SETICON version, or:
	$hIconOld = GUICtrlSendMsg($hIcoControl, 370, 1, $hIconNew) ; STM_SETIMAGE
	ConsoleWrite(""$hOld = "" & Ptr($hIconOld) & @CRLF)
	; _WinAPI_DestroyIcon($hIconOld) ; I can omit this because GUICtrlSetImage will do it for me on the next call

	Sleep(700)

	;_WinAPI_DestroyIcon(GUICtrlSendMsg($hIcoControl, 369, 0, 0)) ; STM_GETICON. Ommiting this on the other hand causes a leak
	; Btw, that's the same as:
	;_WinAPI_DestroyIcon($hIconNew)

	ConsoleWrite(""Assigned icon before GUICtrlSetImage = "" & Ptr(GUICtrlSendMsg($hIcoControl, 369, 0, 0)) & @CRLF) ; STM_GETICON
	ConsoleWrite(""GUICtrlSetImage returns "" & GUICtrlSetImage($hIcoControl, ""shell32.dll"", 5) & @CRLF)
	ConsoleWrite(""Assigned icon after GUICtrlSetImage = "" & Ptr(GUICtrlSendMsg($hIcoControl, 369, 0, 0)) & @CRLF) ; STM_GETICON

	ConsoleWrite(@CRLF)

	Sleep(700)

WEnd



Func _GetIcon($sModule, $iName, $iSize) ; for loaded modules
	Local $hModule = _WinAPI_GetModuleHandle($sModule)
	If @error Then Return SetError(1, 0, 0)
	Local $hIcon = _WinAPI_LoadImage($hModule, $iName, 1, $iSize, $iSize, 0) ; IMAGE_ICON, LR_DEFAULTCOLOR
	If @error Then Return SetError(2, 0, 0)
	Return $hIcon
EndFunc   ;==>_GetIcon

Func _Quit()
	Exit
EndFunc   ;==>_Quit
}}}

GDI Objects count can be monitored with task manager."	Bug	closed		AutoIt	3.3.6.0	None	No Bug		
