Click here to Skip to main content
14,775,978 members
Articles » Web Development » Applications & Tools » Tools with source code
Posted 5 Oct 2003


30 bookmarked

Build a CD directory database

Rate me:
Please Sign up or sign in to vote.
3.50/5 (6 votes)
5 Oct 2003
An article on a tool for making a database containing the directories of CDs etc.

Image 1


A little while ago I wanted to get acquainted with the Win32 API. So I needed to build something that would give me the opportunity to use all kinds of controls and built-in functions. I decided on making a program to view the directory structure of any HD or CD, to which I could add my own remarks and having the option to save that information in a file. I also added a search function. Since I often used information in CodeProject to solve particular problems I encountered, it looked like a good idea to share the result with you guys.

Using the code

Using the program is quite straight forward I think. For details please refer to the help file included in the demo. To summarize its features:

  • Create directory trees from any CD or HD;
  • Add your own remarks to any directory or file in the tree;
  • Save the results in a file;
  • Search for a specific string in the directory tree or the remarks;
  • Print the tree, including the remarks.

I don't want to elaborate on the code I built. I guess it's all straight forward API usage. I preferred using the message cracking macro's like Hernán di Pietro described in these pages. It allows you to break up the large callback functions into nicely looking compact pieces of code like these:

BOOL CALLBACK NewDlgProc(HWND hwnd, UINT Message, 
                         WPARAM wParam, LPARAM lParam)
    HANDLE_MSG (hwnd, WM_INITDIALOG, NewDlgProc_OnInitDialog);
    HANDLE_MSG (hwnd, WM_COMMAND,    NewDlgProc_OnCommand);
    case WM_CLOSE:
      return FALSE;
  return TRUE;


void NewDlgProc_OnCommand(HWND hwnd, int id, 
                        HWND hwndCtl, UINT codeNotify)
    case ID_DIRNAME:
      if(codeNotify == EN_UPDATE)
        HWND hOkButton = GetDlgItem(hwnd, ID_POK);
        BOOL x = EnableWindow(hOkButton, TRUE);
    case ID_DRIVE:
      NewDlgProc_OnDrive(hwnd, id, hwndCtl, codeNotify);
    case ID_DIRLIST:
      NewDlgProc_OnDirlist(hwnd, id, hwndCtl, codeNotify);
    case ID_SELDRIVE:
      NewDlgProc_OnSeldrive(hwnd, id, hwndCtl, codeNotify);
    case ID_POPEN:
      NewDlgProc_OnOpen(hwnd, id, hwndCtl, codeNotify);
    case ID_POK:
            NewDlgProc_OnOk(hwnd, id, hwndCtl, codeNotify);
    case ID_PCANCEL:
      if (!DestroyWindow(hwnd))
        MessageBox(NULL, "Window Destruction Failed!", "Error!",
                  MB_ICONEXCLAMATION | MB_OK);

To other novices I can recommend the tutorial by Brook Miles. I found the lcc compiler useful. It has nice Win32 support and contains all kinds of templates.

Points of interest

I encountered one peculiar problem in the GetSaveFileName function. The function failed until I set the lpstrDefExt member in the OPENFILENAME structure in upper case characters. Before that it didn't do anything, not even produce an error return value.


  • This is the first version, date Oct 2, 2003


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Jack Janssen
United States United States
No Biography provided

Comments and Discussions

GeneralGreat idea Pin
Tom Archer5-Mar-04 19:07
MemberTom Archer5-Mar-04 19:07 
GeneralWell... Pin
dandy727-Oct-03 3:53
Memberdandy727-Oct-03 3:53 
Generalme too! Pin
Kastellanos Nikos7-Oct-03 2:11
MemberKastellanos Nikos7-Oct-03 2:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.