Click here to Skip to main content
Licence CPOL
First Posted 25 Nov 2001
Views 87,809
Bookmarked 42 times

How to include a dialog without copying from .RC

By | 26 Nov 2001 | Article
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

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalreverse enginiering Pinmembermezik22:59 16 Nov '10  
GeneralThanks allot Pinmembermezik23:22 6 Nov '10  
GeneralGood Job! PinmemberDaneStorm18:59 13 Jun '06  
QuestionComplete workspace? PinmemberSibilant14:39 5 Sep '04  
GeneralCould not get it to work. PinmemberWREY7:36 12 Jul '03  
GeneralAnother approach PinmemberThomas Freudenberg8:58 26 Nov '01  
GeneralRe: Another approach PinmemberBrad Bruce10:03 26 Nov '01  
GeneralRe: Another approach PinmemberThomas Freudenberg11:37 26 Nov '01  
GeneralRe: Another approach PinmemberRex Turnbull3:22 3 Feb '06  
GeneralRe: Another approach PinmemberRoberto Rocco7:59 3 Dec '01  
GeneralRe: Another approach PinmemberBrad Bruce11:40 3 Dec '01  
GeneralRe: Another approach PinmemberThomas Freudenberg23:52 3 Dec '01  
GeneralRe: Another approach PinmembereFotografo3:59 8 Oct '09  

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.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 27 Nov 2001
Article Copyright 2001 by Brad Bruce
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid