By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,448 Members | 866 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,448 IT Pros & Developers. It's quick & easy.

Bitmap.GetHIcon leaking GDI resources?

P: n/a
when I do this code
Dim HIcon As IntPtr = bmp.GetHicon to convert a Bitmap which is just a 16x16
image I pulled from a resource originally as an icon (16x16x32bit) then
converted into a bitmap to draw on it's surface then wanted to convert back
to an icon... but when I do the other two commands

Using bmp As Bitmap = My.Resources.bell.ToBitmap
Using g As Graphics = Graphics.FromImage(bmp)
end using
end using

GDI resources are released when they leave the using block. when I put the
HIcon IntPtr in there my GDI Object could is a never ending increment...
(this executes once a second to update the image, basically an animated
image when its used).. So this code causes a GDI leak

Using bmp As Bitmap = My.Resources.bell.ToBitmap
Using g As Graphics = Graphics.FromImage(bmp)
Dim HIcon As IntPtr = bmp.GetHicon
end using
end using

why? The only other code that is left after that leak is this

Using bmp As Bitmap = My.Resources.bell.ToBitmap
Using g As Graphics = Graphics.FromImage(bmp)
Dim HIcon As IntPtr = bmp.GetHicon
Using NewIcon As Icon = Icon.FromHandle(HIcon)

' Place onto drawing surface that requres an icon now...
end using
end using
end using
Oct 19 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Smokey Grindel" <no****@nospam.comschrieb
when I do this code
Dim HIcon As IntPtr = bmp.GetHicon to convert a Bitmap which is just
a 16x16 image I pulled from a resource originally as an icon
(16x16x32bit) then converted into a bitmap to draw on it's surface
then wanted to convert back to an icon... but when I do the other
two commands

Using bmp As Bitmap = My.Resources.bell.ToBitmap
Using g As Graphics = Graphics.FromImage(bmp)
end using
end using

GDI resources are released when they leave the using block. when I
put the HIcon IntPtr in there my GDI Object could is a never ending
increment... (this executes once a second to update the image,
basically an animated image when its used).. So this code causes a
GDI leak
You have to call DestroyIcon (API function) to destroy the icon. Have a look
at the example in the help for GetHIcon method.
Armin

Oct 19 '07 #2

P: n/a
that would be exactly what I missed. thanks!

"Armin Zingler" <az*******@freenet.dewrote in message
news:uW**************@TK2MSFTNGP04.phx.gbl...
"Smokey Grindel" <no****@nospam.comschrieb
>when I do this code
Dim HIcon As IntPtr = bmp.GetHicon to convert a Bitmap which is just
a 16x16 image I pulled from a resource originally as an icon
(16x16x32bit) then converted into a bitmap to draw on it's surface
then wanted to convert back to an icon... but when I do the other
two commands

Using bmp As Bitmap = My.Resources.bell.ToBitmap
Using g As Graphics = Graphics.FromImage(bmp)
end using
end using

GDI resources are released when they leave the using block. when I
put the HIcon IntPtr in there my GDI Object could is a never ending
increment... (this executes once a second to update the image,
basically an animated image when its used).. So this code causes a
GDI leak

You have to call DestroyIcon (API function) to destroy the icon. Have a
look at the example in the help for GetHIcon method.
Armin

Oct 19 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.