![]() |
CXTPControl SetCustomIcon and icon copy |
Post Reply
|
| Author | |
fishy
Newbie
Joined: 26 October 2005 Status: Offline Points: 17 |
Post Options
Thanks(0)
Quote Reply
Topic: CXTPControl SetCustomIcon and icon copyPosted: 18 January 2006 at 5:11pm |
|
Hello,
If i use CXTPControl::SetCustomIcon (in place of SetIconId in an example similar to DynamicPopups -- see CControlShell) it appears that the HICON is being copied (m_hIcon.CopyHandle(..) in CXTPImageManagerIcon::SetIcon(CXTPImageManagerIconHandle hIcon) to be exact). However, I do not see how this copied handle is being destroyed. Whenever my submenu that uses SetCustomIcon is displayed, the icons are copied and not deleted - resulting in a handle leak. I am sure I am missing something here but what is the correct way to use SetCustomIcon? - fish |
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 19 January 2006 at 12:00am |
|
yes, it is copied. it will be destroyed automatically in Clear method: void CXTPImageManagerIconHandle::Clear() }
|
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
fishy
Newbie
Joined: 26 October 2005 Status: Offline Points: 17 |
Post Options
Thanks(0)
Quote Reply
Posted: 19 January 2006 at 9:11am |
|
Again, I think I am missing something here but look at the code for
CXTPControl::SetCustomIcon(HICON hIcon). It calls
AddCustomIcon(hIcon) on the CXTPImageManager (which copies the icon)
and assigns the returned icon id to the m_nCustomIconId variable.
Now, when the CXTPControl is deleted, the m_nCustomIconId is never
removed from the ImageManager, and thus never cleared.
How would I go about deleting the icon that is allocated from SetCustomIcon call in CXTPControl? Should I manually delete it by calling clear on the ImageManager? Let me give you my situation to help you understand the problem. I am trying to make a dynamic menu that is populated with the names and icons of all the currently running applications. I have accomplished this (minus the icons) by creating my own CXTPControlButton in OnCreateControl. In the CXTPControlButton's OnCalcDynamicSize I create a CXTPControlButton for each running application. This works great. The problem is that when I assign an icon to the CXTPControlButton, the icon is copied and displayed (this also works) but is never deleted. The next time the menu is displayed the icon is copied again, and not deleted again, etc.. etc... leaking icon handles every time you click on the menu. I'm sure there is a way to do this correctly. - fishy |
|
![]() |
|
fishy
Newbie
Joined: 26 October 2005 Status: Offline Points: 17 |
Post Options
Thanks(0)
Quote Reply
Posted: 23 January 2006 at 9:41am |
|
Any ideas here? I would like a good solution for this. I have a temporary solution for this problem but there is still a small issue with my solution. My solution is to derive a class from the CXTPControlButton and remove the custom icon in its destructor. I have the following code in the destructor of the derived class: // Cleanup the custom icon if it exists Now, when the menu is displayed the custom icons are assigned and copied (internally in CXTPImageManagerIcon::SetIcon). The next time the menu is clicked I remove all all the CXTPControlButtons in the menu (which deletes them and causes my destructor to be called, deleting the custom icons). However, this solution keeps the icons allocated between calls to OnCalcDynamicSize. If, for example, the user clicks the menu only once, then the icons won't be deleted until the window is closed. In fact, the icons created by the last click of the menu won't be deleted until the window is closed. (Because OnCalcDynamicSize isn't called again). So, is there a way to detect when the menu is closing so that I can delete the CXTPControlButtons there and not in the OnCalcDynamicSize call? I believe that would solve this issue. ..Waiting for a response.. - fishy
|
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 24 January 2006 at 1:46pm |
|
ok, I see problem, right Icons collected in array and destroyed in application exit. you have right idea about destructor things, but you can delete all controls when popup closed: BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
|
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
fishy
Newbie
Joined: 26 October 2005 Status: Offline Points: 17 |
Post Options
Thanks(0)
Quote Reply
Posted: 08 February 2006 at 2:09pm |
|
Perfect. That was the key. Thank you very much Oleg!
|
|
![]() |
|
Post Reply
|
|
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |