tags:

views:

834

answers:

5

Hi All,

Need your help for the following issue:

I have defined a new dialog and its controls in an already existing resource file. I have also created a new file which will handle the events being generated from this dialog. But i am not sure how to connect these two.

Is the statement *enum { IDD=IDD_NEW_DIALOG };* all that is required to connect the two? Or should we add some other statement?

Thanks for any help in advance,

Raghu

A: 

use class wizard to createa a class for newly created dialog(ctrl+w) is the shortcut key from UI resource view

yesraaj
+1  A: 

That's all that is needed when you create the dialog through the dialog class (DoModal(), or Create for a non-modal dialog), which is the normal way to go.

You of course need to inherit from CDialog, and add a message map to route the messages to your ewvent handler functions.

peterchen
A: 

OK. Thanks for the quick reply.

Raghu

Raghu
Thanks the fellow by accepting his answer
yesraaj
A: 

One more thing what is the difference between DIALOG and DIALOGEX?

Raghu
@raghu add that as a seperate qn..other wise people will not notice
yesraaj
thanks. Will do the same.
Raghu
+3  A: 

The way this is usually done in MFC is to define a dialog template in the resource editor (as you've done), then in C++ derive a class from CDialog and associate it with the dialog template (which it sounds like you've done - it's not entirely clear).

What actually associates the two is the constructor for your CDialog code. If you look at dialog related code auto-generated by the MFC class wizard, you'll see in the constructor implementation something like this:

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/) : CDialog(CMyDlg::IDD, pParent)

where CMyDlg::IDD is defined as an enumeration with a value of your new dialog template's identifier. It's this that makes it all happen, not the declaration of the enum. You could modify it to

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/) : CDialog(IDD_NEW_DIALOG, pParent)

and it will still work (assuming IDD_NEW_DIALOG is the template id of your dialog in the resources), as all that's happening is the dialog id is being passed into the constructor.

In general, it's always worth remembering that, despite initial appearances, MFC does not bind to Windows through bits of compiler magic - it's all done with C++ and a few macros.

EDIT: DIALOGEX and DIALOG declare slightly difference dialog resource formats that Windows understands: the former is newer than the latter. However both have been around since at least Windows 95, so it's not a very significant distinction.

DavidK
Thanks for the reply. I derive the class from a base class which derives from CDialog. So i guess this takes care of the stuff.
Raghu