 |
|
 |
Hi Ilya,
I don't know if you are still maintaining this control but I figured I'd drop you a line just incase. There is a small bug in the current version of this control that causes it to leak GDI objects. You can check this by running the demo app, opening windows task manager and enabling the "GDI objects" column there. If you start browsing your hard drive with the file tree control you will see the amount of allocated GDI objects for this process will skyrocket and it just keeps climbing as you open more directories (especially directories containing a lot of items).
The problem lies in the GetIconIndex() and GetSelIconIndex() methods, which invoke SHGetFileInfo() with the SHGFI_ICON flag set. This causes SHGetFileInfo() to return an icon handle for each file which is stored in the hIcon member of the local instance of the SHFILEINFO struct but which is never actually freed (and since the sfi variable goes out of scope you lose the handle eventhough it remains allocated).
int CWtlFileTreeCtrl::GetIconIndex( const std::string sFilename )
{
SHFILEINFO sfi;
ZeroMemory(&sfi, sizeof(SHFILEINFO));
if( SHGetFileInfo( sFilename.c_str(), 0, &sfi, sizeof(SHFILEINFO), SHGFI_ICON|SHGFI_SMALLICON ) == 0 )
return -1;
return sfi.iIcon;
}
It should either be freed with DestroyIcon() or better yet the flags should be changed so that it no longer generates icon handles in the first place since the handles aren't actually used anywhere. I've changed it to the following line of code myself:
if (SHGetFileInfo(sFilename.c_str(), 0, &sfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON ) == 0 )
The same needs to be done for GetSelIconIndex(). Hope this is helpful to someone.
Regards,
-Leon
|
|
|
|
 |
|
 |
Hello, Dear Ilya.
I have some problems in this code :
std::string CFileFind::GetFilePath() const
{
if( m_hContext == NULL)
return FALSE;
std::string strResult = m_strRoot;
if (strResult[strResult.size()-1] != '\\' &&
strResult[strResult.size()-1] != '/')
strResult += m_chDirSeparator;
strResult += GetFileName();
return strResult;
}
If m_strRoot == "" - this code do something as strResult[-1] and spring up error.
Thanks.
|
|
|
|
 |
|
 |
This is one of those postings that likely caused hours of confusion over 6 years now? I found it maybe 6 years after the original?
There are 2 bugs in this CFileFind. The first, as indicated above, is that 'm_strRoot' is set incorrectly in CFileFind::FindFile() at the end of the 'else' block started by comment // find the last forward or backward whack. Fix is:
m_strRoot = pstrRoot; //"";
where the "" was incorrect, and replaced by 'pstrRoot' so that 'm_strRoot' has valid data, the path root string that is before the filename that is found.
Second bug: If you call FindFirst(), then GetFilePath(), you don't get the path to the first file in the directory. Actually the fix is just to remove 'm_pFoundInfo' and just use one structure 'm_pNextInfo'. For some reason Ilya thought two were needed and did a swap in 'FindNextFile()' but the way to fix it, is to remove the 2, and just use 1, that's all!
Also, note that there is a BOOL variable that is not used: m_bGotLast = FALSE;
So by removing some code (and data) the class works!
I hope this explanation is sufficient! Thanks Code Project for keeping this code available!
|
|
|
|
 |
|
 |
Also there is code in FileFile.cpp that is not used so does not cause errors. like this:
std::string CFileFind::GetFileURL() const
{
if( m_hContext == NULL)
return FALSE;
....
is this valid?
|
|
|
|
 |
|
 |
To make this great project compile you'll have to do three things:
1.- include WtlFileTreeCtrl.cpp and FileFind.cpp to the sample project
2.- line 109 of FileFind.cpp, reads:
m_strRoot = "";
should be:
m_strRoot = (char*)pstrRoot;
3.- line 354 of WtlFileTreeCtrl.cpp, reads:
_splitpath_s( DirectoryPaths[i].c_str(), NULL, 0, NULL, 0, fname, _MAX_FNAME, ext, _MAX_EXT);
should be:
_splitpath_s( FilePaths[i].c_str(), NULL, 0, NULL, 0, fname, _MAX_FNAME, ext, _MAX_EXT);
Is the author lazy or just jocking?
-- modified at 6:05 Tuesday 6th March, 2007
|
|
|
|
 |
|
 |
:(hi ,i downloaded this source and i obtain the following error:
FileTree.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall CWtlFileTreeCtrl::SubclassWindow(struct HWND__ *)" (?SubclassWindow@CWtlFileTreeCtrl@@UAEHPAUHWND__@@@Z)
FileTree.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall CWtlFileTreeCtrl::PreTranslateMessage(struct tagMSG *)" (?PreTranslateMessage@CWtlFileTreeCtrl@@UAEHPAUtagMSG@@@Z)
FileTree.obj : error LNK2001: unresolved external symbol "public: __thiscall CSystemImageList::~CSystemImageList(void)" (??1CSystemImageList@@QAE@XZ)
FileTree.obj : error LNK2001: unresolved external symbol "public: __thiscall CSystemImageList::CSystemImageList(void)" (??0CSystemImageList@@QAE@XZ)
FileTree.obj : error LNK2001: unresolved external symbol "public: long __thiscall CWtlFileTreeCtrl::OnItemExpanding(int,struct tagNMHDR *,int &)" (?OnItemExpanding@CWtlFileTreeCtrl@@QAEJHPAUtagNMHDR@@AAH@Z)
FileTree.obj : error LNK2001: unresolved external symbol "public: long __thiscall CWtlFileTreeCtrl::OnPopulateTree(unsigned int,unsigned int,long,int &)" (?OnPopulateTree@CWtlFileTreeCtrl@@QAEJIIJAAH@Z)
FileTree.obj : error LNK2001: unresolved external symbol "public: long __thiscall CWtlFileTreeCtrl::OnLButtonDblClick(unsigned int,unsigned int,long,int &)" (?OnLButtonDblClick@CWtlFileTreeCtrl@@QAEJIIJAAH@Z)
Debug/FileTree.exe : fatal error LNK1120: 7 unresolved externals
Error executing link.exe.
please if you can help me to resolve this problem because i really need a filetree for wtl
|
|
|
|
 |
|
 |
Try to include WtlFileTreeCtrl.cpp file to your project. Or please, look at demo project.
Best regards,
iLYA
|
|
|
|
 |
|
 |
file: WtlFileTreeCtrl.cpp, line: 431
original:
sSearch = sSearch.substr( sSearch.size() - nFound - 1 );
need to:
sSearch = sSearch.substr( nFound + 1 );
|
|
|
|
 |
|