Click here to Skip to main content
Click here to Skip to main content
Go to top

Build a CD directory database

, 5 Oct 2003
Rate this:
Please Sign up or sign in to vote.
An article on a tool for making a database containing the directories of CDs etc.

Introduction

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)
{
  switch(Message)
  {
    HANDLE_MSG (hwnd, WM_INITDIALOG, NewDlgProc_OnInitDialog);
    HANDLE_MSG (hwnd, WM_COMMAND,    NewDlgProc_OnCommand);
    case WM_CLOSE:
      EndDialog(hwnd,0);
    break;
    default:
      return FALSE;
  }
  return TRUE;
}

and:

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

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.

History

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

License

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

Share

About the Author

Jack Janssen

United States United States
No Biography provided

Comments and Discussions

 
GeneralGreat idea PinmemberTom Archer5-Mar-04 18:07 
GeneralWell... PinmemberDaniel Desormeaux7-Oct-03 2:53 
I've been meaning to write one of these for years but never got around to it. Then I found this[^] and figured I was only going to be wasting my time re-inventing the wheel. I have no affiliation whatsoever with this guy, other than having registered the program (one of the very few shareware programs I felt was worth registering).
 
Still, if you're doing this to learn, then by all means, knock yourself out.

Generalme too! PinmemberKastellanos Nikos7-Oct-03 1:11 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 6 Oct 2003
Article Copyright 2003 by Jack Janssen
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid