Re: (CStringList)...folder_list.Find(...) problem.



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
.



Relevant Pages

  • Re: How can I use C# GUI component in my MFC application.
    ... Here's some stuff I had written on this topic for my book (Extending MFC ... Using a .NET control in an MFC dialog ... we have seen how Windows Forms makes GUI development slightly easier ... BOOL Create(CWnd* pWnd, int x, int y, int cx, int cy); ...
    (microsoft.public.dotnet.languages.vc)
  • Re: MFC Migration/Integration
    ... I cross post my somewhat frustrated question on MFC ... Check Box, Edit Control, Combo Box, ... List Box, Group Box, Radio Button, Static Text, Picture Control, ... object-oriented techniques (MFC Version 8 with Windows Forms??). ...
    (microsoft.public.vc.mfc)
  • Re: Simple Input In a MFC application
    ... You can't put it in a DLL and have it statically bound; ... Yes, it takes longer than InputBox to write, but as already established, ... as AfxMessageBox is used by most MFC programers ... Place an edit control on the dialog ...
    (microsoft.public.vc.mfc)
  • Re: MFC 7.1 als Container für .NET Controls
    ... Um ehrlich zu sein kenne ich mich mit der MFC und COM-Interop noch zu wenig aus um es zu glauben bzw. nicht zu glauben. ... Internet Explorer simply loads the Windows Forms control itself and treats it as a COM control. ... Damit es als ActiveX in den entsprechenden Auswahldialogen diverser Anwendungen ...
    (microsoft.public.de.vc)
  • Re: Dont Administrators have access to everything?
    ... returning the folders to the Shared Documents folder, ... NO owner and no one has access to the files (not ... account had been granted Full Control, ... Owner's and Administrators' permissions. ...
    (microsoft.public.windowsxp.security_admin)