[Resolved] CButtonST question, Remove the residue of old icon while setting a new icon with SetIcon [modified]
-
I am maintaining the source code which uses CButtonST buttons as icon controls to display transparent and overlay icons (for the small arrow at the corner of the main icon) on the GUI. User can change the icon. When user is changing the icon, what I do in the code is to invoke
CButtonST::SetIcon
with anotherHICON
handle. But there is the residue of the old icon which is unwanted. The new icon overlaps on top of the old one. How to remove the old residue icon? Please advise. Thanks. According to the comment by the author of CButtonST, callingSetIcon(0, 0)
can remove any old icons from it. [ quote ]// Pass NULL to remove any icon from the button.
[ / quote ] But in fact this call makes the application crash! [Update] I found someone had added two lines in CButtonST::FreeResources to doDeleteDC()
andDeleteObject()
. This issue was caused by these two calls. The problem is fixed after removing them. :-DMaxwell Chen
modified on Wednesday, December 30, 2009 3:36 AM
-
I am maintaining the source code which uses CButtonST buttons as icon controls to display transparent and overlay icons (for the small arrow at the corner of the main icon) on the GUI. User can change the icon. When user is changing the icon, what I do in the code is to invoke
CButtonST::SetIcon
with anotherHICON
handle. But there is the residue of the old icon which is unwanted. The new icon overlaps on top of the old one. How to remove the old residue icon? Please advise. Thanks. According to the comment by the author of CButtonST, callingSetIcon(0, 0)
can remove any old icons from it. [ quote ]// Pass NULL to remove any icon from the button.
[ / quote ] But in fact this call makes the application crash! [Update] I found someone had added two lines in CButtonST::FreeResources to doDeleteDC()
andDeleteObject()
. This issue was caused by these two calls. The problem is fixed after removing them. :-DMaxwell Chen
modified on Wednesday, December 30, 2009 3:36 AM
Can you debug and see why SetIcon(0, 0) fails?
-
Can you debug and see why SetIcon(0, 0) fails?
Rejeesh.T.S wrote:
Can you debug and see why SetIcon(0, 0) fails?
There are 3 versions of
SetIcon
, one isSetIcon(int, int)
and the second isSetIcon(HICON, HICON)
. I think the compiler links it toSetIcon(int, int)
when I wroteSetIcon(NULL, NULL)
. So I casted it to force it invoke the correct version bySetIcon((HICON)NULL /* second arg has default val */)
. And it does not crash now. But there is still old residue icon. I just downloaded the demo source of CButtonST v3.9 from CodeProject, and modified the code to make it change icon dynamically. I do not see it have this problem. And I compared the source code of CButtonST between the demo source and my code. They look the same regarding the icon drawing portion. This is so weird ...Maxwell Chen