This code allows you to include a dialog in your code snippets without requiring a user to copy from your resource file and pasting it into their own.
Introduction
Have you ever had a wonderful dialog class you wanted to share with someone? You give them the .h and .cpp files and they go on their way. Five minutes later, they are back at your door wanting the dialog resource to go with it. Then they have to open your .RC file and copy the dialog into their .RC file. Two days later, you make a change, and the cycle begins all over again.
A quick search of the Internet led to several pieces of information related to using the DLGTEMPLATE
structure. The downside of them was that I had to create the structure from scratch.
Then I found article Q231591 on MSDN.
What I did was create an automated method of extracting a dialog resource. The file Dialog1.h is my extraction class.
Why Extract the Dialog
The biggest advantage of using this method is that you can create your dialog and write the class to support it, using the class wizard. Only when you are packaging the class for final release do you need to extract the dialog structure.
How to Use the Class
In order to use this class, you should:
- Include header file:
#include "Dialog1.h"
- Somewhere in your program, add:
CDialog1 Dlg;
Dlg.Extract(IDD_PROFILE_SELECTION);
Replace IDD_PROFILE_SELECTION
with the ID of the dialog you are exporting.
When your program reaches this code, you will be presented with a dialog box (created using this method). Choose whether you need a modal or modeless dialog and then press "Do It". You will then be presented with further directions to finish the embedding of the dialog in your class file.
You may now remove the dialog1.h file and calls from your program. I would comment them out, but not remove them. (You might want to make changes in the future.)
Once you have made the above changes, you need to make a few more changes to remove dependencies on the resource.h file.
- In your header file, remove the line:
enum { IDD = IDD...};
- In your .cpp file, look for any
#define
d values IDC_PROMPT
, etc. and copy them from your resource.h file to your header file.
The Sample
The sample shows a class that I wrote to display a "Working" message during a long process. It will display text that shows progress, as the background work is going on. I have created it using the method above. In order to use it in your own program, you should #include
the .h file and add the .cpp to your project.
It is used similar to CWaitCursor
.
#include "CWorking.h"
...
CWorking Work;
Work.SetPrompt("Getting List Of Scheduled Reports...");
History
- 26th November, 2001: Initial version
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.