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