Solved

What causes tree controls and bitmaps to stop repainting?

Posted on 2000-03-31
6
262 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sameEnds challenge 3 180
withoutTen challenge 14 132
Message not shown 5 67
"Black Box" Testing of Control System Software 2 72
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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…

830 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