(CStringList)...folder_list.Find(...) problem.

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 )
{
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 :-)
0
geoff (60)
4/3/2006 2:46:01 AM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
926 Views

Similar Articles

[PageSpeed] 50

On Sun, 2 Apr 2006 19:46:01 -0700, Geoff <Geoff@discussions.microsoft.com>
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
0
dsh (2498)
4/3/2006 2:51:13 PM
Reply:

Similar Artilces:

chart printing problem
Hi, I have a student trying to print chart in excel. His instructor wants a scatter chart with smooth lines. However, we print the chart which looks fine on the screen and in print preview, only one of the chart lines prints. Pick any of the other scatter chart options and it prints correctly. This has happened on different printers, as well as with pdf printer. Any ideas? Thanks, Jennifer ...

Input mask/combo box/query problem
I have a phone number column, data is stored as 9999999999 and displayed with input mask (999) 999-9999. The data can be typed in or selected via a combo box (as one column of many) and combo box uses a query that does not format the phone number. When a record is selected, it displays fine. However in the combo box selection column it is displayed unformatted. If the query formats it, when I transfer the column to the control with the input mask, the number is messed up as it tries to format it twice. How to get around this so I have it formatted in the combo box column and in the res...

Unable to populate a CStringList with data from another CStringLis
I am not able to populate a CStringList with data from another CStringList in an MFC application using VC++ 6.0. Any help would be appreciated. This is the MFC code from the view. It captures multiple file names from a File Open dialog and stores them in a local CStringList. The view then passes a reference to the CStringList to the document. void CVSD_INPUTSView::OnWetdep() { CStringList fileNames; POSITION pos; char* title = "Wet Deposition File Open Dialog"; CString filter = "DATA FILES (*.prn) |*.prn;| ALL FILES (*.*) |*.*; ||\0"; CWet_File openWetDep...

Find Replace Number Starting with 0
I am trying to find and replace a list of numbers that begin with zero. I can't get replacement function in this code to display the zero. Sub FindReplace() Columns("J:J").Select FindReplaceDPT 144, 141 FindReplaceDPT 147, 151 FindReplaceDPT 149, 151 End Sub Sub FindReplaceDPT(Find, Replace) Selection.Replace What:=Find, Replacement:=Replace, LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False End Sub ...

problem with bookmark links in email sent as message, pub 2007
when i send a publisher document as an email message, most of the 'bookmark' links do not function in several email programs. oddly, some of the bookmark style links will work, and all of the external hyperlinks work, but most of the links to locations on page do not work at all. I have the same page put up as a webpage, (which works perfectly), so folks can click to that if they have problems viewing the email, but i'd really like the original email to function properly. i am sending the email using outlook express, as my version of outlook is too old for use with pub. 200...

MessageBox Problem
Using Visual Studio 2008, here's what I did: File | New | Project Selected MFC and MFC Application Name: Play In Application Wizard, selected Dialog based Deleted OK, Cancel, and TODO. Inserted Button Added event handler for button. Chose Bn_Clicked event Under void CPlayDlg:OnBnClickedButton() replaced TODO with MessageBox("Gordon:); Tried to build - response was Error 2664 Edited MessageBox(L"Gordon:); Build successful. Run Message box displayed "Button1" I expected the message box to display "Gordon" Obviously there's much I don't understand about...

SendKeys problem with wdDialogInsertCrossReference
I have some code that works fine in Word 2003 for displaying notorious Insert Cross Reference dialog. This is to display the dialog so as to insert a cross reference to a Figure caption. With Dialogs(wdDialogInsertCrossReference) SendKeys "%t{home}ff" SendKeys "{enter}" SendKeys "%r" SendKeys "{down}" SendKeys "{enter}" SendKeys "%w" 'move to list of references rtn = .Display End With This code does not work in Word 2...

Create Combo Box to Find a Record
I would like to create a combo box based on two fields on my form that will list each [CertificateNo] that is marked [Registered (Yes)]. Registered column is Yes/No. I made a query but the wizard will not let me find the record based on the query. I tried changing the Row Source in Properties to my query named [Registered Certificates] but, alas no luck. Is there anyone who can help me with this problem? Much appreciated. -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200911/1 Hi Uschi, in the header of almost e...

problems with HQ connections
Hi . I am starting to have some problems in one of my clients. They have a location that run 18 stores running HQ r 1.2. Suddenly for some odd reason everytime the stores connect, create an incredible amount of connections (sometimes reaching 200 connections process) giving a hige degradation of performance. Does somebody know something about this?..... Thks in advance for your help Rodrigo ...

Problem with keeping lines together
In my file (Word 2007), I can normally keep lines together by checking the Window/Orphan control, Keep with next and Keep Lines together. At some point in my file, it quits working. I have bulleted items that normally would stay together and have the above items checked in the Line and Page Breaks tab of Paragraph. But later in the file it quits working event if I uncheck them and recheck them. Not sure what is cause this. Tom If you're trying to use "Keep lines together" to keep bullet points together, it won't work. KLT is for the lines in a sing...

Problem to change the default font in Propherty Pages.
I chaged the default font to arial 8 on all the templates of the property pages of a property sheet. Every page of the property sheet always displays the default font, san serif 8. I have tried call SetFont() in the OnInitDialog() for each property page, and the propery sheet. It did not work. Calling SetFont() in the OnPaint() did not seem to help either. Calling SetFont for a individual control on the page works fine. But I have more than a dozen pages and each has many controls. Are there esay ways to set a non default font for a property sheet? Thanks in advance Z SetFont should...

OWA Shared Calendar problem #2
I have a new Exchange 2003 SP1 server behind ISA. OWA works fine when opening your own mailbox. You can open another users shared calendar using https://server.domain.com/exchange/MAILBOX/FOLDER but you cannot edit even with owner permissions configured in Outlook.Users can edit the calendar when on the network in Office Outlook but not in OWA weather on the network or not. Any suggestions? I think Q821900 applies to you. See if it helps. -- This posting is provided "AS IS" with no warranties, and confers no rights. Please do not send email to this address, post a reply to ...

find replace VBA
I have a list of addresses that I want to standardize. For example, I have this list in column A: 100 Randlett Steet 450 Park Str Apt 5 Park Sreet Park Streeet Apt B5 I want to standardize all the versions of 'street' to "St". There are approximately 300 similar replacements, like Aveenue to Ave, Roade to Rd, Northgate to 399 N 7th St. I have compiled all the misspelled words, put them in column B, and the "correct" version next to it, in Column C. I have done all this work because I want to be able to use this list as we continue to receive address data with simil...

email forward problem
I am using outlook xp now; when I forward my mail to friend, some of origin content had disappear, I need to copy again from origin mail, so do anybody know why? Thanks!!! JY ...

Profile migration problems (outlook 2003)
Hello, I have a computer that arrived from a different domain to ours. I had to migrate a user profile from that domain. Since he only wanted his Outlook (2003) data, I just copied the PST file to the new user's directory. Unfortunately, when I imported the PST file, there were no Contacts, Calendar and Tasks. Mail, along with all the folders he created were transfered perfectly. I can't logon the old user, because the computer no longer belongs to the old domain. (If I could logon I'd export them to a csv file or something....) My question is: Where are the Contacts etc......

problem emailing attachment with COD method
Hello I am using the following code to email contents with attachments. There is no problem when I use an email "TO" that belong to the exchange server domain I am using. The problem exists when I try to email to an email such as "yahoo.com" or "someotherDomain.com". What am I doing wrong ? is there something I need to change maybe on the exchange server to allow it to work ? Thank you My code : '''USING CDO Dim lobj_cdomsg As CDO.Message Set lobj_cdomsg = New CDO.Message 'Add the Project Reference Miscros...

Find a vlaue, shade another cell
I would like to search column c in an excel sheet for any number that starts with '46'. all the numbers in the column will be 7 digits long (eg. 4634567) once found I would like to turn the font blue in the cell 10 columns to the right of this 46 cell. the macro should loop down column c until it can find no further values. any ideas if this is possible? Hi, Try this Sub Sonic() lastRow = Cells(Cells.Rows.Count, "C").End(xlUp).Row Set MyRange = Range("C1:C" & lastRow) For Each c In MyRange If Left(c.Value, 2) = "46" Then ...

Find Command
I have a form where I'm filtering to find records by last name. To avoid having to click on the command button, I tried to put this code in the On Focus hoping that when the user tabs to the command button the records would be found. It does bring in the records,however now the navigation button doesn't work to view additional records with the same last name. How can I get the tab to work, then allow the use of navigation buttons to view the additonal records found. Thank you DoCmd.ApplyFilter , "[LastName]= '" & txtLastName & "'" Try t...

Compile error: Can't find project or library
i get this error even after pasting in tried and true code. I am trying to paste this code in a workbook I got from someone else. I am not sure why it doesn't work (something disabled?) seems like it doesn't like "Visual Basic for Applications" functions. what do i need to do to make this work? THANKS!! Melanie When in the VBE go to Tools>References and see if any references are marked as missing. You may want to post your code here for trouble-shooting. Gord Dibben MS Excel MVP On Mon, 17 Aug 2009 12:33:01 -0700, Melanie <Melanie@discussions.microsoft.co...

Problem with Expose corners
I love using my expose corners in Panther to minimize all my windows or show them all to me so I can switch them quickly. Sometimes, however, when I'm in various office applications when I switch windows the window I've selected has all the buttons grayed out and unusable. The usual solution is to minimize and then bring the window back up, in which case all the buttons are available. Anyone else have this problem and/or a solution? Jesse Garner On 2004-02-14 15:55:45 -0700, Jesse Garner <riverjack@hotmail.com> said: > I love using my expose corners in Panther to minimize ...

Advanced Find
Hi All, Does anyone know how the advanced find utility can be used to create "OR" sql queries? Currently, issuing multiple criteria in V1.2 results in an "AND" query only. TIA... Hi! The only possibility for you is to seperate the values with ";" for example: field1 = "a" or field1 ="b" "a;b" but you can not search for field1 = "a" or field2 = "b" -- Christian support@mscrm-addons.com www.mscrm-addons.com Your company for MS-CRM ADD-ONS! GroupCalendar for MSCRM Related Documents for MS...

Slight problem making electronic payments
I am using Microsoft Money Premium 2007. I use this program to instruct my bank to send payments from my checking account. My bank actually mails a paper check to whomever I specify, and draws the funds from my checking account. This has been working well for monthes. Recently, I upgraded my web browser to Internet Explorer 7. At about the same time, Microsoft Money upgraded itself to version #. Now, after I instruct Microsoft Money to send out checks, I always see a web browser screen that says "Navigation to the webpage was canceled. The web browser screen has a URL field that reads r...

Subtotal problem
Col for Date name amount But the names are listed as following Jack (food) Jack(TV) Jack (supplies) Jill (house) Jill (Water) John(food) John (garage) John (house) Trying to subtotal each name by amount, but of course the name field has TOO much data in it. Any easy way to run subtotals on this or have to do one of those =left(??) formulas.. Any help appreciated as it is a long list! Yep. I'd insert two formulas in adjacent cells. To get everything before the first open paren: =TRIM(LEFT(A2,SEARCH("(",A2&"(")-1)) To get everything from the...

Need to Copy and Paste results of Find All
When I use the Edit/Find All dialog in Excel, I would like to be able to copy/paste and print the resulting lists of references. Does anyone know a way to do so? How about a macro? Saved from a previous post... But you could use a macro... Option Explicit Sub testme01() Dim curWkbk As Workbook Dim wks As Worksheet Dim RptWks As Worksheet Dim oRow As Long Dim FoundCell As Range Dim FirstAddress As String Dim FindWhat As String FindWhat = InputBox(Prompt:="Find What?") If FindWhat = "" Then Exit Sub End If ...

Where to find emails
I came in to work this moring and found the message "Windows could not load the locally stored profile." --- ACK! All my stuff is as if Windows has been installed freshly! Anyway, I'm in the process of restoring everything to howI had it, but where can I find my old Outlook Express emails stored to import them? In WinXP, Win2K & Win2K3, the OE user files (DBX and WAB) are by default marked as hidden. To view these files in Windows Explorer, you must enable Show Hidden Files and Folders under Start | Control Panel | Folder Options Icon | View, or in Wind...