Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Show Off Your Open Source Projects (http://www.programmingforums.org/forum52.html)
-   -   my personal cd indexer :D (http://www.programmingforums.org/showthread.php?t=13127)

rsnd May 8th, 2007 5:41 AM

my personal cd indexer :D
 
Well, makes a list of all the file names in a cd and then saves them as a text file in a folder so I can use windows text search option to determine where a particular file is :D

:

#include "D:\n\n\nWindow\nwindows.h"
#include <windows.h>

nEdit name_textbox;

char tb[5000];
char tx[5000];

class MainWindow: public nWindow {
public:
        void on_open();
        void on_close(){
                terminate();
        }
}main;

#define CONTROL(p,x,y,dx,dy)\
        p.set_dimentions(dx,dy);\
        p.set_position(x,y);\
        controls.add(&p);

nListView file_list;


int i = 0;
void PopulateList(char * dir){

        //MessageBox(0,dir,0,0);

        WIN32_FIND_DATA FindFileData;
        HANDLE hFind = INVALID_HANDLE_VALUE;
        char DirSpec[5000];  // directory specification
        DWORD dwError;


        strncpy (DirSpec, dir, strlen(dir)+1);
        strncat (DirSpec, "\\*", 3);
       


        hFind = FindFirstFile(DirSpec, &FindFileData);

       

        if (hFind == INVALID_HANDLE_VALUE)    {
                char xxx[555];

                wsprintf(xxx, "Error %i", GetLastError());
                MessageBox(0,xxx,dir,0);

                //N_WINDOW_DEBUG();
   
        } else {

                if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
                        if (strcmp(FindFileData.cFileName,".")!=0 && strcmp(FindFileData.cFileName,"..")!=0){
                                file_list.add_row(FindFileData.cFileName,i++);
                               
                                char child[500];
                                wsprintf(child, "%s\\%s", dir,FindFileData.cFileName);
                               
                                //GetFullPathName(FindFileData.cFileName, 5000, tb, (char**)&tx);
                                //MessageBox(0,child,dir,0);
                                PopulateList(child);
                                //PopulateList(FindFileData.cFileName);
                        }
                } else {
                        file_list.add_row(FindFileData.cFileName,i++);       
                }
               
                       

                while (FindNextFile(hFind, &FindFileData) != 0)      {
                       
                        if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
                                if (strcmp(FindFileData.cFileName,".")==0 || strcmp(FindFileData.cFileName,"..")==0)
                                        continue;
                                char child[500];
                                wsprintf(child, "%s\\%s", dir,FindFileData.cFileName);
                               
                                //GetFullPathName(FindFileData.cFileName, 5000, tb, (char**)&tx);
                               
                                //MessageBox(0,child,dir,0);
                                PopulateList(child);

                                //PopulateList(FindFileData.cFileName);
                        }

                        file_list.add_row(FindFileData.cFileName,i++);
                       
                }
   
      dwError = GetLastError();
      FindClose(hFind);
      if (dwError != ERROR_NO_MORE_FILES)
      {
        N_WINDOW_DEBUG();
      }
  }

}





          void WriteList(){
                  char fname[500] = "D:\\n\\CDIndexer\\library\\";
                  char buf[500];
                  name_textbox.get_text(buf, 500);
                  strcat(fname, buf);
                  strcat(fname, ".txt");
                  //MessageBox(0,fname,0,0);
                  _lclose(_lcreat(fname, OF_CREATE));
                  HFILE h = _lopen(fname, OF_WRITE);

                  for (int x = 0; x<file_list.length();x++){
                          file_list.get_row(buf, 500, 0, x);
                          strcat(buf, "\r\n");
                          _lwrite(h, buf, strlen(buf));

                  }
                  _lclose(h);

                  //HANDLE h = CreateFile(fname, OF_WRITE, FILE_SHARE_READ, 0, CREATE_NEW|OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
                  //CloseHandle(h);
  }





class asdfasjkdhaksjdhk:public nButton{
        void on_click(){
                char buffer[5000];
                OPENFILENAME ofn;

                ofn.lStructSize = sizeof(ofn);
                ofn.hwndOwner = (HWND)main.get_handle();
                ofn.lpstrFile = buffer;

                ofn.lpstrFile[0] = '\0';
                ofn.nMaxFile = sizeof(buffer);

                ofn.lpstrFilter = "All\0*.*\0";
                ofn.nFilterIndex = 1;
                ofn.lpstrFileTitle = NULL;
                ofn.nMaxFileTitle = 0;
                ofn.lpstrInitialDir = NULL;

                ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER;

                if (GetOpenFileName(&ofn)==TRUE) {
                        //N_WINDOW_DEBUG();

                        GetCurrentDirectory(5000, buffer);
                        //if (strlen(buffer)==3)
                                buffer[2] = 0;
                       
                        PopulateList(buffer);
                        //PopulateList("H:");
                       


                }
        }
       
} browse_button;
class asdsdfasdf234: public nButton{
        void on_click(){
                file_list.rows_delete();
        }
} clear_button;

class asdasdasd:public nButton {

        void on_click(){

                WriteList();

        }

       
} add_button;


class asdsdfasdf: public nButton{
        void on_click(){
                main.on_close();
        }               
} quit_button;


void MainWindow::on_open(){

        CONTROL(file_list, 0,150,800,410);

        CONTROL(browse_button, 0,20,200,130);
        CONTROL(add_button, 200,20,200,130);
        CONTROL(clear_button, 400,20,200,130);
        CONTROL(quit_button, 600,20,200,130);

        CONTROL(name_textbox, 0,0,800,20);

        name_textbox.set_text("insert CD title here");
        browse_button.set_text("Browse");
        add_button.set_text("Add");
        clear_button.set_text("Clear");
        quit_button.set_text("Quit");

        file_list.add_column("Filename", 400);
        file_list.add_column("Size", 100);

}

int WinMain(          HINSTANCE hInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpCmdLine,
                        int nCmdShow
                        ){


                                main.set_position(0,0);
                                main.set_dimentions(800,600);
                                main.set_parent(0);
                                main.create();
                                main.animate();
                                return 0;
}



All times are GMT -5. The time now is 2:12 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC