Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - GUI Resource Problem
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

GUI Resource Problem

 Post Reply Post Reply
Author
Message
Tsenoh View Drop Down
Groupie
Groupie
Avatar

Joined: 08 November 2006
Status: Offline
Points: 69
Post Options Post Options   Thanks (0) Thanks(0)   Quote Tsenoh Quote  Post ReplyReply Direct Link To This Post Topic: GUI Resource Problem
    Posted: 15 February 2007 at 10:08am
Hi!
 
In my application I am using Dialogs with ribbons. Dialogs are often opened and closed. Whenever I close a dialog I don't destroy it. I just destroy all elements in it. I use RemoveAllTabs to destroy Ribbon elements. This way I don't have to initialise dialog every time it is opened. I just recreate the child controls.
 
Problem occures when I open and close same dialog multiple times (10-15 times). Suddenly GUI goes crazy. No button can be drawn, all windows use default font, etc. It seems that GUI handles are not released when a control is destroyed.
 
Has anyone had similar problem?
 
Any ideas how I can solve this problem?
 
Thanks!
 
Bojan Hrnkas
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 15 February 2007 at 11:11am
Hi
May be you call InitCommandBars each time you show dialog or something.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
Tsenoh View Drop Down
Groupie
Groupie
Avatar

Joined: 08 November 2006
Status: Offline
Points: 69
Post Options Post Options   Thanks (0) Thanks(0)   Quote Tsenoh Quote  Post ReplyReply Direct Link To This Post Posted: 19 February 2007 at 11:12am
I did indeed. However that was not the problem. I am using SetCustomIcon() for my buttons. I figured out that there is a memory leak in that function, so I have around 700 leaks per dialog start. If those leaks are all icon handles, or any other gui handles, I understand the problem.
 
Is there something I have to do to destroy resources created by SetCustomIcon()?
Back to Top
kstowell View Drop Down
Admin Group
Admin Group


Joined: 25 January 2003
Location: MIchigan, USA
Status: Offline
Points: 496
Post Options Post Options   Thanks (0) Thanks(0)   Quote kstowell Quote  Post ReplyReply Direct Link To This Post Posted: 19 February 2007 at 12:37pm
HI Tsenoh,
 
You can try using CXTPImageManagerIconHandle instead of HICON. This will automatically clean up your icon resources when the object is destroyed.
 
Instead of:
HICON hIcon =

Use:
CXTPImageManagerIconHandle hIcon =

Hope this helps.
 
Regards,
Kirk Stowell
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 20 February 2007 at 2:03am
Hello,
SetCustomIcon each time reserves new Id for Icon. I very recommend yo use SetIcons method instead.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
Tsenoh View Drop Down
Groupie
Groupie
Avatar

Joined: 08 November 2006
Status: Offline
Points: 69
Post Options Post Options   Thanks (0) Thanks(0)   Quote Tsenoh Quote  Post ReplyReply Direct Link To This Post Posted: 20 February 2007 at 9:57am
If I understood corectly. When using SetIcons, icons are mapped through controll message id. We use our own message system, and the ID's are only unique within a dialog. Not within the application. That is why I use SetCustomIcon.
Back to Top
Tsenoh View Drop Down
Groupie
Groupie
Avatar

Joined: 08 November 2006
Status: Offline
Points: 69
Post Options Post Options   Thanks (0) Thanks(0)   Quote Tsenoh Quote  Post ReplyReply Direct Link To This Post Posted: 28 September 2007 at 11:07am
Hi!
I've now checked my application using following tool: http://www.download.com/DPusLight/3000-2218_4-10424495.html?tag=pdp_prod
 
It shows that resources created by CreateCompatibleBitmap are not freed untill I destroy the dialog. I am never calling CreateCompatibleBitmap myself for theese icons (in the tool there is an image of the resources in question), so it has to be somewhere in the XTP code.
However, those resources are not created each time I show the dialog, so it is not really a leak. It seems to me that is some kind of cache for the bitmaps that are to be drawn on the ribbon.
Is there a possibility to disable it? Since my application has hundreds of dialogs that are dynamicaly created, the GDI Resource count pretty soon reaches the magic number 10.000.
 
Any ideas?
 
Thanks!
Back to Top
Tsenoh View Drop Down
Groupie
Groupie
Avatar

Joined: 08 November 2006
Status: Offline
Points: 69
Post Options Post Options   Thanks (0) Thanks(0)   Quote Tsenoh Quote  Post ReplyReply Direct Link To This Post Posted: 28 September 2007 at 1:48pm

Hi, again!

Please consider following code:


void CXTPRibbonTheme::FillGroupPopupToolBar(CDC* pDC, CXTPRibbonGroup* pGroup, CXTPCommandBar* pCommandBar)
{
 pDC->SetBkMode(TRANSPARENT);

 CXTPClientRect rcRibbon(pCommandBar);

 pDC->FillSolidRect(rcRibbon, RGB(191, 219, 255));

 rcRibbon.InflateRect(3, 3);
 XTPRibbonTabContextColor tabColor = pGroup->GetParentTab()->GetContextColor();

 if (tabColor != xtpRibbonTabContextColorNone)
 {
  CXTPOffice2007Image* pImage = LoadImage(FormatName(_T("CONTEXTTAB%sCLIENT"), GetColorName(tabColor)));
  if (pImage) pImage->DrawImage(pDC, rcRibbon, pImage->GetSource(0, 1), CRect(8, 8, 8, 8));
 }
 else
 {
  CXTPOffice2007Image* pImage = LoadImage(FormatName(_T("RIBBONGROUPS")));
  if (pImage) pImage->DrawImage(pDC, rcRibbon, pImage->GetSource(0, 1), CRect(8, 8, 8, 8));
 }
}

pImage is never deleted. Is that a leak, or am I missing something and that objects are destroyed elsewhere? Thanks!
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 29 September 2007 at 1:54am
Hi,
 
Images are stored in CXTPOffice2007Images class and will be destroyed after skin changed or in destructor of this class.
 
Better attach code you use in your dialog, I will check where you forget to free resources.
Our library doesn't have memory leaks.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
Tsenoh View Drop Down
Groupie
Groupie
Avatar

Joined: 08 November 2006
Status: Offline
Points: 69
Post Options Post Options   Thanks (0) Thanks(0)   Quote Tsenoh Quote  Post ReplyReply Direct Link To This Post Posted: 01 October 2007 at 5:47am
I see. I know the problem now. We are not destroying the Dialog Object, so the CXTPOffice2007Images isn't destroyed as well. Is there a possibility to empty that map and destroy it's elements other than destroying the Object itself?
Thanks!
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 01 October 2007 at 5:59am
Hi,
Call
 
((CXTPOffice2007Theme*)pCommandBars->GetPaintManager())->GetImages()->RemoveAll();
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
Tsenoh View Drop Down
Groupie
Groupie
Avatar

Joined: 08 November 2006
Status: Offline
Points: 69
Post Options Post Options   Thanks (0) Thanks(0)   Quote Tsenoh Quote  Post ReplyReply Direct Link To This Post Posted: 01 October 2007 at 10:04am
Ok, that solved a part of the problem.
Thanks a lot!
Other leaks are probably in our code.
Some other thing, I see that Fonts are stored with each CXTPRibbonBar instance. Probably again in the Theme. They don't take up much space, but it would be nice if I could destroy them too.
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 01 October 2007 at 1:40pm
HI,
 
If you use CommandBars/PaintManager only with this dialog, you can free all PaintManager:
 
CXTPPaintManager::Done()
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.141 seconds.