Which HICON Should be Destroyed???
Which HICON Should be Destroyed???
// I create a custom draw listbox in my popup window,
// and there's a memory leak somewhere.
void DrawFunction()
{
HICON hIcon0 = (HICON)::SendMessage(hWndOfThisProcess, WM_GETICON,
ICON_SMALL, 0);
HICON hIcon1 = (HICON)::SendMessage(hWndOfOtherProcess, WM_GETICON,
ICON_SMALL, 0);
HICON hIcon2 = (HICON)::GetClassLong(hWndOfThisProcess, GCL_HICONSM);
HICON hIcon3 = (HICON)::GetClassLong(hWndOfOtherProcess, GCL_HICONSM);
...
// afer draw the icon, should I release these icons or not?
// maybe win2000 should destory, win98 shoud not,
// can you give me a final answer? thx!!!
//
}
Remarks of MSDN:
It is only necessary to call DestroyIcon for icons and cursors
created with the following functions: CreateIconFromResourceEx
(if called without the LR_SHARED flag), CreateIconIndirect,
and CopyIcon. Do not use this function to destroy a shared
icon. A shared icon is valid as long as the module from which
it was loaded remains in memory. The following functions
obtain a shared icon.
LoadIcon
LoadImage (if you use the LR_SHARED flag)
CopyImage (if you use the LR_COPYRETURNORG flag and the hImage parameter
is a shared icon)
CreateIconFromResource
CreateIconFromResourceEx (if you use the LR_SHARED flag)