Builder 6, affichage de l'explorateur avec treeview URGENT

yuka_605 Messages postés 15 Date d'inscription mercredi 15 décembre 2004 Statut Membre Dernière intervention 3 février 2005 - 26 janv. 2005 à 10:19
tibob51 Messages postés 268 Date d'inscription vendredi 30 avril 2004 Statut Membre Dernière intervention 13 mai 2013 - 26 janv. 2005 à 10:42
salut à tous,
je voudrais afficher l'arborescence des répertoires et fichiers comme dans l"explorateur de windows.Pour ceci j'utilise le treeview de c++ builder 6. Mais je n'y arrive pas .
est ce que quelqu'un aurait un code source la dessus?

J'ai trouvé plusieurs codes mais ca ne marche pas, au début il y'avait des erreurs, je les ai corrigé, y'a plus d'erreurs mais ca ne m'affiche toujours rien..C'est le code que j'ai récupéré, mis il ne m'affiche qu'un treeview vide...

#include <vcl.h>
#pragma hdrstop
#include <string.h>
#include <stdio.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
void main();
void AddChild(TTreeNode *Node1, char *NomDir);
void AddNode(TTreeNode *Node1, char *NomDir);
char *Bondir(char *rep);
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void AddChild(TTreeNode *Node1, char *NomDir)
{


TTreeNode *Node2;
WIN32_FIND_DATA FileData;
HANDLE hSearch;


char szNewPath[MAX_PATH];
char szHome[MAX_PATH];
sprintf(szHome, "%s\\*.*", NomDir) ;
strcpy(szNewPath, Bondir(szHome));
BOOL fFinished = FALSE;


hSearch = FindFirstFile(szNewPath, &FileData);
if (hSearch == INVALID_HANDLE_VALUE)
{
return;
}
while (!fFinished)
{
if (((FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY )
&& FileData.cFileName[0] != '.')
{


Node2 = Form1->TreeView1->Items->AddChild(Node1, FileData.cFileName);
sprintf(szNewPath, "%s\\%s", NomDir,FileData.cFileName);
AddChild(Node2, szNewPath);
}
if (!FindNextFile(hSearch, &FileData))
fFinished = TRUE;
}
FindClose(hSearch);
}
//------------------------------------------------------------------------------
void main()
{
AddNode(NULL, "mes doc");
}
//------------------------------------------------------------------------------
void AddNode(TTreeNode *Node1, char *NomDir)
{
WIN32_FIND_DATA FileData;
TTreeNode *Node2;
HANDLE hSearch;
char szNewPath[MAX_PATH];
char szHome[MAX_PATH];
sprintf(szHome, "%s\\*.*", NomDir) ;
strcpy(szNewPath, Bondir(szHome));
BOOL fFinished = FALSE;


hSearch = FindFirstFile(szNewPath, &FileData);
if (hSearch == INVALID_HANDLE_VALUE)
{
return;
}


while (!fFinished)
{
if (((FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY )
&& FileData.cFileName[0] != '.')
{
Node2 = Form1->TreeView1->Items->Add(Node1, FileData.cFileName);
sprintf(szNewPath, "%s\\%s", NomDir, FileData.cFileName);
AddChild(Node2, szNewPath);
}
if (!FindNextFile(hSearch, &FileData))
fFinished = TRUE;
}
FindClose(hSearch);
}
//------------------------------------------------------------------------------


char *Bondir(char *rep)
{
// chemin absolu du reprtoire passé en argument
//static char chemin[MAX_PATH];
// repertoire d'installation de données de mon application,
// obtenu par lecture dans la base de registre; il y a une initialisation que je ne donne pas ici
static char chemin[MAX_PATH];
char *repertoire;


strcpy(chemin, repertoire);
strcat(chemin, rep);
return chemin;
}

1 réponse

tibob51 Messages postés 268 Date d'inscription vendredi 30 avril 2004 Statut Membre Dernière intervention 13 mai 2013 2
26 janv. 2005 à 10:42
Salut a toi,une question.
void main()
{
AddNode(NULL, "mes doc");
}

Tu ne fait pas d'appel vers cette fonction!!!
Quelle est cette fonction,attend tu quelle s'execute au début de ton programme?
Car ici ce ne sera pas le cas.
0
Rejoignez-nous