You've seen this in Control-Panel applets, small utility programs, and even the Windows Task Manager. A simple dialog-based program won't provide the U/I experience you want, but the document/view architecture seems too complex.
To give that familiar U/I to your program, use a CPropertySheet-derived object as the main window. Individual CPropertyPages can be used to handle various categories of settings and options, and you can provide multiple views -- real-time status, lists of objects, log of activities, etc. -- in other pages. Each page is effectively a dialog box (a "form") so you have great flexibility in your U/I design.
In this article, I'll describe what you need to do to create this type of program, and I'll throw in a few tips and tricks that are handy to know in this scenario: We'll get rid of the Apply and Help buttons and enable minimize/restore functionality. Here we go.
- 1
- In Visual Studio,
Create Project...
Project Type: VisualC++ / MFC
Template: MFC Application
Name: MyProg
Click [Next], then..
Application Type: Dialog-based
[Finish]
- 2
- Create some PropertyPages
In the Resource View...
Right-click My Prog
Select Add > Resource
Click on Dialog to open it up.
Select IDD_PROPPAGE_LARGE
Click [New]
In the Dialog Editor, set
Caption: General
ID: IDD_PgGeneral
Add some Controls:
- 3
- Create a CPropertyPage-derived object for that property page:
In the Dialog Editor, double-click on the title bar of the property page to bring up the Class Wizard. Set...
Class Name: CPgGeneral
Base Class: CPropertyPage
- 4
- Repeat steps 2 and 3 for each property page
- 5
- Open up the application main CPP file (MyProg.cpp)
Add these #include lines at the top:
Now, locate the InitInstance() function, and near the bottom of it, replace the key start-up sequence as follows:
But Wait! There's More!
We used CPropertySheet's default functionality, but you will want make a few adjustments because this is your main window and you want want to exert some control over various aspects of the User Interface.
Get Rid of the Help and Apply Buttons
=========================
For instance, let's say that you want to get rid of the "Help" and "Apply" buttons. We'll derive a class that does that:
- 1
- In the Class View...
Right-click MyProg
Select Add > Class
Choose MFC Class
Click [Add]
- 2
- In Class Wizard,
Class Name: CSheetMain
Base class: CPropertySheet
[Finish]
- 3
- Right-click the SheetMain item in the Class View
Choose Properties
Click the diamond-shaped Overrides icon.
Click OnInitDialog and choose <Add OnInitDialog>
Put this code into your CSheetMain::OnInitDialog() function:
And modify your constructor to be:
- 4
- Next, go back to MyProg.cpp and set it to use the derived object rather than the base object:
Enable Your App to Minimize to the Taskbar
=========================
Since this is your main window, you will want to let your user minimize it normally -- so that it will show an icon in the Taskbar, just like a real program! It's not particularly obvious how to do that, so here's the trick. First, change the CSheetMain() constructor like this:
That gives your program an icon to display on the title bar and in the taskbar when it's minimized. Now to enable the Minimize/Restore functionality, add this code to the bottom of your CSheetMain::OnInitDialog(
The finished product is illustrated by Fig 1.1 at the top of this article.
=-=-=-=-=-=-=-=-=-=-=-=-=-
If you liked this article and want to see more from this author, please click the Yes button near the:
Was this article helpful?
label that is just below and to the right of this text. Thanks!
=-=-=-=-=-=-=-=-=-=-=-=-=-