Re: (CStringList)...folder_list.Find(...) problem.
- From: "Doug Harrison [MVP]" <dsh@xxxxxxxx>
- Date: Mon, 03 Apr 2006 09:51:13 -0500
On Sun, 2 Apr 2006 19:46:01 -0700, Geoff <Geoff@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
Hello all,
I hope this is in the right place this time.... MFC.
I am trying to create a basic app with a treeview control that displays just
the folders of the hard drive... This part i have achieved but with bugs
(sort of) so far i have only been iterating through the HDD contents with a
simple while loop but i really need to test against the drives contents - so
i don't repeat the folders in my list - It displays about 50 Windows and
Westwood Folders at the end of the list.
Im trying to use:
<CStringList variable>.Find(.....); to test weather or not the folder that
is about to be applied is valid (i.e. is it allready thier).
ok... here's the embarasing part - My code...(Im not trying to make it
perfect rather im trying to get the very basics working .... For Now)
void CLeftView::FillDirectory(LPCTSTR lp_drive,LPCTSTR is_drive, HTREEITEM
hChild, HTREEITEM hParent )
Based on what you have below, hChild should be a local variable, not a
function parameter.
{
int i=0; // Be sure to anitialize all variables... or.... like this one it
// can cause a hang on the application - (Learned the hard way lol)
CString s_folder; // Ready to store the folder in here and Move to
//next file/folder then
CFile c_file; // store a fresh file/folder name here again
CFileFind find_folders; // Using so i can iterate through the
directories/files
CStringList folder_list; //Attempting to put a list of the directory in here
to
//test against it-self.
if((folder_list.Find(s_folder=find_folders.GetFileName())!=NULL))
{
//A folder is Found so add it to the TreeViewCtrl :-)
hChild =
CTreeView::GetTreeCtrl().InsertItem(s_folder=find_folders.GetFileName(),
hParent, TVI_LAST);
}
Can anyone give me some relavent pointer/s as to how i could takcle this
problem
I figured its my datatypes thats causing me trouble... Type conversion has
failed (The method i have been using) i.e.
(LPCTSTR)s_folder=find.... or ...
(LPTSTR)(LPCTSTR)s_folder=find........
In Advance Thank you :-)
The casts are not your problem and should be deleted. Don't ever try to
"cast" the code into correctness; if you don't know why you're casting,
you'll get into trouble. I don't understand your code. You never call
CFileFind::FindFile, so you'll never find anything. I also don't understand
why you're concerned about duplicates. It's somewhat bad style to embed
assignments inside statements, as with:
folder_list.Find(s_folder=find_folders.GetFileName())
You should either say:
folder_list.Find(find_folders.GetFileName())
or more likely this, since you call GetFileName a second time, and it will
return the same result, which you can reuse later:
s_folder = find_folders.GetFileName();
See the example here for the right way to use CFileFind:
CFileFind::IsDirectory
http://msdn2.microsoft.com/en-us/library/scx99850(VS.80).aspx
Experiment with the console program presented there before trying to get
everything into a tree control.
P.S. Your "c_" prefix often means a member variable that is an MFC control,
while "s_" means a static member variable. They're not used for local
variables.
--
Doug Harrison
Visual C++ MVP
.
- Prev by Date: Re: Localization and some basic questions on getting started........
- Next by Date: Re: List Control Images
- Previous by thread: Re: Capturing key press combination
- Next by thread: Re: Changing background color on multiple child dialog
- Index(es):
Relevant Pages
|