Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

What causes tree controls and bitmaps to stop repainting?

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
nelsond
Asked:
nelsond
  • 3
  • 2
1 Solution
 
ShaunWildeCommented:
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
 
bertpCommented:
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
 
nelsondAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
bertpCommented:
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
 
nelsondAuthor Commented:
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
 
nelsondAuthor Commented:
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now