Solved

What causes tree controls and bitmaps to stop repainting?

Posted on 2000-03-31
6
256 Views
Last Modified: 2013-12-03
I am writing some software that has a main dialog with a couple of tree controls and some bitmaps. The app works fine for 15 or 20 minutes of use at a time and then the controls and bitmaps stop getting repainted properly. For example, if I click on the tree control to expand a branch it appears to be doing it but instead of it appearing on the screen the rectangle that would contain the updated painted region gets painted gets erased. From then on any activity that causes a region to be repainted gets erased. For example, if I bring another window to the top, covering the app, then bring the app back to the top all of the tree graphics and the bitmaps on the dialog are erased. No errors are displayed. If I exit the code and start it up again the erased sections are still erased. Nothing short of rebooting has cleared up the problem. Any ideas?

Thanks!!

Don
0
Comment
Question by:nelsond
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2675549
I am guessing you are running on 98 or 95 and if that is the case I suspect you are running out of GDI resources.

Make sure you tidy up properly all your pens, brushes, device contexts, bitmaps, fonts  etc etc etc .
0
 

Expert Comment

by:bertp
ID: 2676336
Are you, by chance, using a directory tree control from the codeguru?... I had a similar problem so if you are using the same control I used I can tell you how I fixed my problem
0
 

Author Comment

by:nelsond
ID: 2680600
Yes, although I have added a few minor changes specific to the app I am developing, the tree control is basically the codeguru tree control. I would appreciate it if you would tell me about the problem you found and fixed.

Don
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Accepted Solution

by:
bertp earned 50 total points
ID: 2680716
Below is my quick fix to the cool dir tree control posted by Michael Hofer. I have altered his AddItem function to delete icons returned from SHGetFileInfo.

  My program was locking-up if the user used my program long enough.. a quick look through heapwalker revealed a bezillion small memory allocations.. Stepping through the code while watching heapwalker showed be exactly where the allocations were coming from ;-)



HTREEITEM CDirTreeCtrl::AddItem(HTREEITEM hParent, LPCTSTR strPath)
{
// Adding the Item to the TreeCtrl with the current Icons
SHFILEINFO shFinfo;
int iIcon, iIconSel;
CString strTemp = strPath;

HTREEITEM hRet;
HICON hIcon, hIconSel;

if ( strTemp.Right(1) != '\\' )
strTemp += "\\";
if ( !SHGetFileInfo( strTemp,
0,
&shFinfo,
sizeof( shFinfo ),
SHGFI_ICON |
SHGFI_SMALLICON ) )
{
m_strError = "Error Gettting SystemFileInfo!";
return NULL;
}

iIcon = shFinfo.iIcon;
hIcon = shFinfo.hIcon;

if ( !SHGetFileInfo( strTemp,
0,
&shFinfo,
sizeof( shFinfo ),
SHGFI_ICON | SHGFI_OPENICON |
SHGFI_SMALLICON ) )
{
m_strError = "Error Gettting SystemFileInfo!";
return NULL;
}

iIconSel = shFinfo.iIcon;
hIconSel = shFinfo.hIcon;

if ( strTemp.Right(1) == "\\" )
strTemp.SetAt( strTemp.GetLength() - 1, '\0' );

if ( hParent == TVI_ROOT )
hRet = InsertItem( strTemp, iIcon, iIconSel, hParent );
else
hRet = InsertItem( GetSubPath( strTemp ), iIcon, iIconSel, hParent );

DestroyIcon(hIcon);
DestroyIcon(hIconSel);
return hRet;
}


HTH
Bert
0
 

Author Comment

by:nelsond
ID: 2680772
Yes, although I have added a few minor changes specific to the app I am developing, the tree control is basically the codeguru tree control. I would appreciate it if you would tell me about the problem you found and fixed.

Don
0
 

Author Comment

by:nelsond
ID: 2680883
Your solution solved my problem indirectly - I was overriding the OnPaint() function for the tree to add checkboxes to the tree items and had forgotten to delete the bitmap object and the dc when I was through with them. Thanks for your assistance! Works great now.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now