Solved

What causes tree controls and bitmaps to stop repainting?

Posted on 2000-03-31
6
253 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Accepted Solution

by:
bertp earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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…

762 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

6 Experts available now in Live!

Get 1:1 Help Now