Click here to Skip to main content
15,881,172 members
Articles / Programming Languages / C++
Article

Build a CD directory database

Rate me:
Please Sign up or sign in to vote.
3.50/5 (6 votes)
5 Oct 20032 min read 42.6K   1.7K   30   3
An article on a tool for making a database containing the directories of CDs etc.

Image 1

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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralGreat idea Pin
Tom Archer5-Mar-04 18:07
Tom Archer5-Mar-04 18:07 
GeneralWell... Pin
dandy727-Oct-03 2:53
dandy727-Oct-03 2:53 
Generalme too! Pin
Kastellanos Nikos7-Oct-03 1:11
Kastellanos Nikos7-Oct-03 1: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.