Go Premium for a chance to win a PS4. Enter to Win


Dialog resource to MFC code utility

Posted on 1998-04-01
Medium Priority
Last Modified: 2013-11-25
(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.
Question by:trwest
  • 4
  • 3
  • 2
  • +2
LVL 23

Expert Comment

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


Author Comment

ID: 1317372
Edited text of question

Expert Comment

ID: 1317373
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.

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

LVL 11

Expert Comment

ID: 1317374
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


Author Comment

ID: 1317375
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.

LVL 11

Expert Comment

ID: 1317376
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

LVL 10

Expert Comment

ID: 1317377
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?


Author Comment

ID: 1317378
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.

LVL 10

Accepted Solution

RONSLOW earned 100 total points
ID: 1317379
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:


Author Comment

ID: 1317380
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! :-)

LVL 10

Expert Comment

ID: 1317381
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.

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question