How to programmatically create a CDialog window?

Go To StackoverFlow.com

1

I do not want to use the "graphics resources" to create the dialog!

What I have so far:

CDialog *dlgWin = new CDialog();
dlgWin->Create("hello");  // <-- but this Errors: "Debug Assertion failed!"

thx

2012-04-04 08:07
by jdl
If you don't want to use a dialog resource then there's no point whatsoever in using CDialog. Just derive your own class from CWnd, do the work to make it look more than just an empty window, call its RunModalLoop() method to make it a dialog - Hans Passant 2012-04-05 00:24


2

You need to create the dialog template in the resource editor, and provide it to the CDialog constructor.

Here's the documentation, they also explain how to dynamically create your dialog in memory, its not trivial and I'd advise against it. I'd advise against using MFC altogether.

The MSDN documentation is usually pretty well written, read it.

2012-04-04 08:10
by littleadv
What do you recommend for GUI if not MFC? ...I need buttons and Tabs, Edit boxes, Strings, plotting.. - jdl 2012-04-04 08:22
I would go with .NET. Qt is another (portable) option to consider. Maybe more, do some research - littleadv 2012-04-04 08:34
"I'd advise against using MFC altogether." Why? Because you heard it's old? I heard somewhere that "[t]he MSDN documentation is usually pretty well written" - Cody Gray 2012-04-05 02:26
@CodyGray no, because there are better tools. You can write everything in assembler, yet you would agree with my advice not to, wouldn't you - littleadv 2012-04-05 18:36
Hmm, mainly because I don't know assembler, whereas I know MFC well. But I suppose I take your point. The reason even seasoned assembly hackers don't use it is because it's slow and tedious to use when writing complex applications. I don't think that same rule applies to MFC. And perhaps even more to the point, there aren't very many other good toolkits that wrap the Win32 API. Most of them insist on re-inventing the wheel in a subpar fashion, like Qt - Cody Gray 2012-04-06 02:55
@CodyGray I think its an off-topic discussion. I have MFC experience, I've developed with it for quite a while, and while doing it I was pretty confident in what I'm doing. To me, as a C++ coder, it was the best option because I didn't want to learn .NET. But even for me the learning curve was very steep. I since worked with both .NET and Qt, and with both, the learning curve was much easier to cope with, and the results were much better - littleadv 2012-04-06 03:59


1

I use one empty dialog template for all dialog boxes and then use my own GUI layout library to generate and manage the size of the MFC widgets. Don't know if you really want to do it because it requires a lot of additional work, gives problems but also features.

Using Qt oder GTK might be a way but i don't like them.

2012-04-05 00:15
by Lothar
Ads