Dialog resource to MFC code utility

(rephrase) Does anyone know of a utility which can convert text from a .RC file (defining a dialog and its controls) to the equivalent MFC code?  

In my application I want to create a dialog on-the-fly (dynamically?), with a number of controls, instead of placing it in the resource file.  However, to actually design the dialog I would like to use Developer Studio, where I can size/position everything visually.  

Developer Studio creates a .rc file.  I would like something that can read that .rc file, and dump out the corresponding MFC code that would create the same dialog.

eg.  Translate (from the .rc)
     PUSHBUTTON "Cancel",IDCANCEL,205,75,50,14

     button.Create( "Cancel", ... ) ;

     OR to a DLGTEMPLATE structure

I would then stitch this code into my application, and the dialog would be created while the application is running.

Hope that makes sense.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi Buddy,
I have a question? What do you mean by creating at run time? Cause this is bit confusing.

trwestAuthor Commented:
Edited text of question
If U whant to use DevStudio to position and size control. Whats the meaning of translating that to code instead of just creating the dialog from resource.

Do you whant to modify the dialog controls at runtime ???

Creating a dialog from a resource definition is actually the same 'dynamic creation' of the dialog, as you would get by tranlating the resource into code.

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

If you want a DLGTEMPLATE structure, just get it: call LoadResource() on the dialog resource. Then, call LockResource() and you'll have a pointer to the DLGTEMPLATE structure.

.B ekiM

trwestAuthor Commented:
No, no no no NO!
I do NOT want to include the dialog in a resource file.
Otherwise, I would just do it!
The only reason I want to use Developer Studio is so I can layout the dialog's controls visually (instead of figuring out x,y's in dialog units).
I want to create the dialog RUN-TIME.  That means:  beforehand, the application (including the resource file) does not know anything about the dialog.  It is not the same as "creating a dialog from a resource definition", because I don't want the resource definition there in the first place.

So, to reiterate, does anyone know of a utility to convert a dialog from a resource file into MFC run-time code.

I'm beginning to think not.

No reason to get testy: I was just answering the question as you asked it. One way to translate a RC file to a DLGTEMPALTE structure is using the resource compiler and the APIs I mentioned in my response.

Anyhow, I don't know of any such utility. But it seems like you should be able to write one in an afternoon or two.

But, now I'm curious: hardcoding calls to create window to build your dialog is going to be slow at runtime. And it's going to result in a lot of code. You'll find that the same dialog in a resource is much smaller and creates faster.  Why would you want to not use resources?

.B ekiM

I agree with .B ekiM .. there seems to be little point in creating a dialog in code (from a dialog template) when it can be created from a dialog resource.  I could imagine there being some use in that if the dialog template were being created modified before the dialog is created for it .. but you even say that just generating the Create calls would do.

This all seems a bit odd.. perhaps if you tell us WHAT you are trying to achieve from a broader perspective, then we can offer a better solution.

Regarding the utility, it shouldn't be hard to write a little program that prompts for a dialog resource ID and a EXE or DLL.  It then loads the resource from that DLL or EXE, loads and locks the dialog resource to get the dialog template, and save the template data out to a file.  Then your other program can read in the generated dialog template and create a dialog from there.

But what is the point???

Perhaps we're missing something here?

trwestAuthor Commented:
I don't want a better solution, I just wanted to know if there was such a utility!! :-)

I have since realized, by lack of response to the question, that such a utility either does not exist, or at least is not known of.  In the mean time, I have created a class which will do the job for me.  

I know there are alternative ways (and probably better ways) to accomplish dialog creation, but the fact remains that this is the way I wanted to do it.  I want ONE portable dialog and it seemed overkill to create and distribute a .DLL for it.

By posting a quick question to a broad group of people I was hoping someone would save me the 1/2 day by saying "oh yeah, here's one".  But I've spent more time trying to justify my question than I would've spent just writing the utility! :-)

Thanks, anyways.

I am still interested in knowing what on earth you are trying to do here.  The code for generating the dialog would be much bigger than and slower than for just including the dialog resource.

I think I can speak for the other experts in that we think you may have a misunderstanding about the way dialogs and resources work.  We would like to be able to help you find a better and more efficient way of doing things, because the way you are suggesting seems to offer no advantages at all.

Anyway, if you do want such a utility, then have a look at (I'm not sure if this is what you want, but it sounds possible ??)


This is what it says about itself...

A code generating tool for the Windows C developer. Standard RC (resource) files is used as input for generating dialog code, SDI or MDI Windows and more. The philosophy of SW is to get a flying start to building your C application. SDI frames can contain list box, list view, tree view and more. When making dialog code, Source Wizard will typically generate about 70 % of the code. You have an option to use the dialog as the main window. In this case, no source editing will be needed to compile and run the application.

download from:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
trwestAuthor Commented:
The Source Wizard is C and not C++ but it is the kind of thing I was looking for.  Except I don't need it anymore.

And what on earth am I trying to do?
Okay <deep breath> we already have a static library that we share across several applications.  Instead of spending the time to turn it into a .DLL (into which I could embed resources), I wanted to add my dialog to the static lib.  The only way to do that is to create the dialog in code.  No resource file at all.  And we didn't want to cut and paste code from the .rc file, nor did we want to go through the "multiple resource files in your project" hell.  We were _hoping_ for the easy approach.

I took a quick look around the 'net to see if there was a utility to help me out (if I found one, it _would_ be easy).  But alas, no such beast.  Eventually I found a sample (from Developer Studio, no less) that creates dialogs by setting up a DLGTEMPLATE structure and everything in it.  I turned that into a class, and it's case closed.

But thanks for finding that link for me.  Who knows, it may yet come in handy -- especially if he converts it to MFC! :-)

You can simply use a #include to include from another resource file (you add it to the list of include file for the resource.  It would take very little effort to set this up (much less than what you have spent on this exercise).  You can even use the .rc2 file to do this and have it #include your common dialog resource.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.