VCPP 6 - TUTORIAL - LESSON #5 - DHTML (c) Artur Marques, 03 September 1999
*You are supposed to have read Lesson #1 ; Lesson #2 ; Lesson #3 ; Lesson #4
Exercise #1 - try to build the FFiF application, just by reading the previous lessons, experiencing how it works, and try to easy your task, by using the proposed ANSI C code.
Conditions of use * YOU MUST READ AND ACCEPT THIS, BEFORE USING THE PROGRAM!
How to start - high level overview
Suggested C code for a list of strings [file names], part 1**
Suggested C code for a list of strings [file names], part 2**
A: There is C code in this project, just because it will be ported to C for CGI, when the CGI tutorial debuts.
|
FFiF main dialog. Click on the picture to enlarge it. The file properties dialog. This dialog shows all the details the OS can track about the file, that will be used as a starting point to the search. Details include "last write", "last access", 9 attributes, data in both numerical and string representations. The about dialog, states the program version and the author. Me, sure. |
FFiF 0.1A stands for "Fast Find in Files", version 0.1 ALPHA. About FFiF FFiF is a very small, very simple, yet somehow interesting software, that searches a requested file or all files in a folder, for whatever you want. FFiF can also display the properties of a single file, including some unsual attributes that your operating system might track, and that are usually not addressed by most file applications. Conditions of use This software is absolutely FREE. You can distribute it in any media, without my written consent, as long as you do not modify it in ANY way, and you CLEARLY state that it comes from www.ArturMarques.com. You must also accept that I will not be responsable for any consequences that might come from the program usage. Bug[s] Despite being version 0.1A, I did only spot one bug in FFiF. If you try to do a search on all files of a folder, where there is a file that the Operating System is using, but not signaled as being used, FFiF will crash, doing NO damage to any file. This is an extremely rare situation and the program tries his best to prevent such scenary, by NOT considering any hidden or system files. Please report any bugs. How to start - high level overview In order to program a FFiF clone in Visual C++ 6.0, you will be creating a new dialog-based MFC application. Design the dialog boxes. Associate member variables to most non static controls. Use a struct _stat and a _stat call to retrieve information about a single file, in "standard C" fashion. Use a CFileFind object to retrieve file information, in MFC fashion. Use a CFileDialog object, for the browse action. The struct _stat and the CFileFind objects should be enough to retrieve a directory list. Build a list of file names; do the search on each file name; display the results in a CListBox object. Use a CProgressCtrl object to track the search progression. Its easy if you undertand the C code that follows and if you use the VC++ help system wisely. |
The tp_lofn is a new datatype, declared in CFfifDlg.h, in my case:
typedef struct _tp_node_lofn{
char *filename;
struct _tp_node_lofn *next;
} tp_node_lofn;
typedef tp_node_lofn* tp_lofn
Suggested C code for a list of strings [file names], part 2
The following code, handles a dynamic list of strings. I wrote it in the main dialog's class [CFfifDlg.cpp in my case].
This code is not indented, because of HTML limitations.
//inits to NULL a tp_lofn entity (pointer to a list of filenames
tp_lofn lofn_init (void){return NULL; }//function ends
/*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
//inserts a string @ the tail of any list of file names
void lofn_insert_filename_tail (tp_lofn *l, const char *filename){
tp_lofn new_node=(tp_lofn)malloc (sizeof (tp_node_lofn)), aux=*l;
if (new_node){ new_node->filename=strdup(filename); new_node->next=NULL; };
if (aux){
while (aux->next) aux=aux->next;
aux->next=new_node;
} else *l=new_node;
}//function ends
/*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
int lofn_count (tp_lofn l){
int ireturn=0;
while (l){ ireturn++; l=l->next; };
return ireturn;
}//function ends
/*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
char *lofn_dump2string (tp_lofn l){
int ibytes_required=0; tp_lofn aux=l; char *str_return=NULL;
//compute the memory required for the return string
while (aux){ ibytes_required+=strlen(aux->filename); aux=aux->next; };
ibytes_required+=lofn_count(l);
aux=l;
str_return=(char*)malloc(sizeof(char)*ibytes_required);
str_return[0]='\0';//extreme importance! for the correct working of strcat
//build the return string
while (aux){
strcat(str_return, aux->filename);
strcat(str_return,"\n"); aux=aux->next; };
return str_return;
}//function ends
/*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
int lofn_dump2listbox (CListBox *lb, tp_lofn l){
while (l){ (*lb).AddString(l->filename); l=l->next; };
return TRUE;
};//function ends
The executable [ZIP - 6K]