MFC Example Projects

From time to time, I've posted these example projects in answer to questions on the Codeguru web site (which I highly recommend).... Rather than having to repost them, I thought I'd create this page to link to. I don't have time to write a paper on how they work... so it's up to you to get what you can from the code.

All code is as is and for educational purposes only.

Any comments are welcome and may be emailed to Rail at

Example 2

This I did years ago, which is a Directory Chooser dialog derived from the NON-Explorer style CFileDialog.... I preferred this to using SHBrowseForFolder, mainly because it works on all versions of Windows, is recognized by most users because Microsoft used it for years and it still appears in most installation software -- I also modified it to allow the user to create a directory.

Download the project

Example 3

This is a quick example of how to add your own controls to a CFileDialog. It also shows how to tell how the dialog was exited - did the user hit OK, Cancel or double click on a file name?

Download the project

Example 5

This example shows two methods to allow the user to move from an Edit control to the next dialog control by hitting Enter, instead of having to Tab.

Download the project

Example 6 - Persistent contents of a ListBox

This example was to show how to let a CListBox remember it's contents between opening and closing the dialog.

Download the project

Example 11 - MRU Folders

This adds a control to a CFileDialog which I wish all programs would add... It allows the user to quickly switch to the last 9 folders used in your app.

Download the project

Example 12 - CBitmapButton

I often see posts on how to implement CBitmapButton, so I thought a quick project which showed how would be helpful. It also answers that all too often asked question, "How do I disable my button?".

Download the code

Example13 - ComboBox and SetItemDataPtr

This shows how to attach data to your ComboBox entries using the SetItemDataPtr and GetItemDataPtr functions. It also shows how to change the font of a static control on your dialog.

Download the code

Example14 - Subclass CEdit to select the contents on an edit control on a left button click

This shows how to subclass the CEdit control. Whe the user left clicks on the subclassed edit control, the entire contents of the edit control are highlighted.

Download the code

Example 16 - Open/Read a TXT file and display with Print/Print Preview (Doc/View)

Simple project which opens a TXT file and displays its contents in a vertically scrollable CView derived class. This will handle very large text files.

Download the code

Example 17 - Search for files.

This example upon launching searches all drives for any MP3 files and lists them - the user may double click on any MP3 file to edit its ID3v1 Tag info. The user may cancel the search at any time by hitting the ESC key. This doesn't use CFileFind, but rather uses the API commands FindFirstFile and FindNextFile so it works with older versions of VC++ which don't have CFileFind.

Download the code


Example 18 - CHoverBitmapButton.


Download the code


Return to Rail Jon Rogut Software's Home page