Click here to Skip to main content
15,881,413 members
Articles / Desktop Programming / MFC

How to Include a Dialog without Copying from .RC

Rate me:
Please Sign up or sign in to vote.
4.64/5 (11 votes)
26 Nov 2001CPOL2 min read 106.8K   2.7K   42   13
Include a dialog without requiring to copy from resource file
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:

  1. Include header file:
    C++
    #include "Dialog1.h"
  2. Somewhere in your program, add:
    C++
    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.

  1. In your header file, remove the line:
    C++
    enum { IDD = IDD...};
  2. In your .cpp file, look for any #defined 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.

C++
#include "CWorking.h"
...
CWorking  Work;
Work.SetPrompt("Getting List Of Scheduled Reports...");

History

  • 26th November, 2001: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect TRAC Intermodal
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

 
Generalreverse enginiering Pin
mezik16-Nov-10 22:59
mezik16-Nov-10 22:59 
thanks for the article
Is there a way to reverse enginier the dialog back into the rc so I can update my dialog?

thanks
mezik
GeneralThanks allot Pin
mezik6-Nov-10 23:22
mezik6-Nov-10 23:22 
GeneralGood Job! Pin
DaneStorm13-Jun-06 18:59
DaneStorm13-Jun-06 18:59 
QuestionComplete workspace? Pin
Sibilant5-Sep-04 14:39
Sibilant5-Sep-04 14:39 
GeneralCould not get it to work. Pin
WREY12-Jul-03 7:36
WREY12-Jul-03 7:36 
GeneralAnother approach Pin
Thomas Freudenberg26-Nov-01 8:58
Thomas Freudenberg26-Nov-01 8:58 
GeneralRe: Another approach Pin
Brad Bruce26-Nov-01 10:03
Brad Bruce26-Nov-01 10:03 
GeneralRe: Another approach Pin
Thomas Freudenberg26-Nov-01 11:37
Thomas Freudenberg26-Nov-01 11:37 
GeneralRe: Another approach Pin
Rex Turnbull3-Feb-06 3:22
Rex Turnbull3-Feb-06 3:22 
GeneralRe: Another approach Pin
Roberto Rocco3-Dec-01 7:59
Roberto Rocco3-Dec-01 7:59 
GeneralRe: Another approach Pin
Brad Bruce3-Dec-01 11:40
Brad Bruce3-Dec-01 11:40 
GeneralRe: Another approach Pin
Thomas Freudenberg3-Dec-01 23:52
Thomas Freudenberg3-Dec-01 23:52 
GeneralRe: Another approach Pin
eFotografo8-Oct-09 3:59
professionaleFotografo8-Oct-09 3:59 

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.