Click here to Skip to main content
Click here to Skip to main content

How to include a dialog without copying from .RC

, 26 Nov 2001
Rate this:
Please Sign up or sign in to vote.
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.
    #include "Dialog1.h"
  2. 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.

  1. In your header file remove the line
    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.

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

License

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

About the Author

Brad Bruce
Web Developer
United States United States
No Biography provided

Comments and Discussions

 
Generalreverse enginiering Pinmembermezik16-Nov-10 22:59 
GeneralThanks allot Pinmembermezik6-Nov-10 23:22 
GeneralGood Job! PinmemberDaneStorm13-Jun-06 18:59 
QuestionComplete workspace? PinmemberSibilant5-Sep-04 14:39 
GeneralCould not get it to work. PinmemberWREY12-Jul-03 7:36 
GeneralAnother approach PinmemberThomas Freudenberg26-Nov-01 8:58 
GeneralRe: Another approach PinmemberBrad Bruce26-Nov-01 10:03 
GeneralRe: Another approach PinmemberThomas Freudenberg26-Nov-01 11:37 
GeneralRe: Another approach PinmemberRex Turnbull3-Feb-06 3:22 
GeneralRe: Another approach PinmemberRoberto Rocco3-Dec-01 7:59 
GeneralRe: Another approach PinmemberBrad Bruce3-Dec-01 11:40 
GeneralRe: Another approach PinmemberThomas Freudenberg3-Dec-01 23:52 
GeneralRe: Another approach PinmembereFotografo8-Oct-09 3:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 27 Nov 2001
Article Copyright 2001 by Brad Bruce
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid