Solved

What causes tree controls and bitmaps to stop repainting?

Posted on 2000-03-31
6
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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…
Suggested Courses

734 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