精華區beta Programming 關於我們 聯絡資訊
On Fri, 08 Jan 1999 16:42:19 +0800, SuperZergs <superfu@i.am> wrote: >請問,如何將磁碟[目錄][檔案]結構讀入TreeView ? >弄了好久....都不行. >需要一次完整讀入,不要邊選邊讀. >高手請解答,謝謝. 剛好寫完還未修整,自已慢慢看 void TDirDialog::CreateNode(TTreeNode *Tnode,char *path,int p,int s) { int done; char path1[256]; char path2[256]; struct ffblk fileinfo; Tnode->ImageIndex=p; Tnode->SelectedIndex=s; wsprintf(path1,"%s%s",path,"\\*.*"); done = findfirst(path1,&fileinfo,FA_DIREC); while (!done) { if (fileinfo.ff_attrib==FA_DIREC) { if ((strcmp(fileinfo.ff_name,".")!=0) &(strcmp(fileinfo.ff_name,"..")!=0)) { wsprintf(path2,"%s%s%s",path,"\\",fileinfo.ff_name); CreateNode(TreeView1->Items->AddChild(Tnode,fileinfo.ff_name),path2,1,2); } } done = findnext(&fileinfo); } } void __fastcall TDirDialog::FormActivate(TObject *Sender) { char THDD[5]; unsigned long int ldrive; unsigned long int mask=4; int x; int THD=66; ldrive=(unsigned long int)GetLogicalDrives(); //ldrive=GetLogicalDrives(); TTreeNode *root=TreeView1->TopItem; for (x=1;x<=10;x++) { THD++; if (ldrive & mask) { wsprintf(THDD,"%c%s",(char)THD,":"); //if(GetDriveType(THDD)& DRIVE_REMOTE) if(!(GetDriveType(THDD) & DRIVE_REMOTE)) { //TreeView1->Items->AddChild(root,THDD) CreateNode(TreeView1->Items->AddChild(root,THDD),THDD,0,2); //Application->MessageBox("HD Find ",THDD, MB_OK); } } mask=mask*2; } } //--------------------------------------------------------------------------- void __fastcall TDirDialog::OKBtnClick(TObject *Sender) { if (TreeView1->Selected == NULL) return; selectedpath[0]='\0'; TTreeNode *pItem = TreeView1->Selected; Getnodepath(pItem); //Application->MessageBox("HD Find ",selectedpath, MB_OK); } //--------------------------------------------------------------------------- void TDirDialog::Getnodepath(TTreeNode *Tnode) { if (Tnode->Parent==NULL) { wsprintf(selectedpath,"%s%s",selectedpath,Tnode->Text.c_str()); return; } Getnodepath(Tnode->Parent); wsprintf(selectedpath,"%s%s%s",selectedpath,"\\",Tnode->Text.c_str()); }