OT - Menu that displays a dialog
Lately i''ve been trying to learn MFC with marginal success. Today I hit a wall with a program I was writting and was hoping someone could help me.
The Problem is this. I have a menu bar and one of the selections is called Add/Modify. When you click on it my Add/Modify dialog box is supposed to pop up. I created a class for the add dialog box, but I can''t pass the dialog''s resource id when I instantiate it. Normally to bring up a dialog all you would have to do is something like this:
CDialog dlg(ID_ADD);
int ret = dlg.DoModal();
But I need to instantiate my dialog class, and it will not take the control id of my dialog resource as a construction parameter. It is expecting a CWnd*. Fair Enough. I tried to cast it to a CWnd, like this:
CDialog* pDB = (CDialog*)GetDlgItem(ID_ADD);
CAdd dlg(pDB);
int ret = dlg.DoModal();
The program just crashes when I click on add/modify on the menu. I have even played around with what im casting the pointer as (CWnd explicitly, and a few others). If any one has had this problem before and can help I would appreciate it. =)
Mike Barela
mbarela@earthlink.net
Mike BarelaMikeB@yaya.com
I am no MFC guru, but when you created a class that handles the Add/Modify dialog THAT class is what you want to instantiate to get your dialog.
Lets call that class CAddModifyDlg. Then, all you should have to do is:
CAddModifyDlg dlg;
dlg.DoModal();
and be done with it.
HTH,
-mordell
__________________________________________
Yeah, sure... we are laughing WITH you ...
Yeah, sure... we are laughing WITH you ...
CAdd is the class for the dialog, but it doesn''t know what resource id to use.
Mike Barela
mbarela@earthlink.net
Mike Barela
mbarela@earthlink.net
Mike BarelaMikeB@yaya.com
The resource id should already be in CAdd header file..probably something like this:
//{{AFX_DATA(CAdd)
enum { IDD = IDD_ADD };
//}}AFX_DATA
or whatever you named it. By default its IDD_DIALOG1 or something.
You don't necessarily need the resource id...thats what the class wrapper is for. it handles all the instantiation, etc..
Edited by - mordell on 3/16/00 12:27:35 PM
//{{AFX_DATA(CAdd)
enum { IDD = IDD_ADD };
//}}AFX_DATA
or whatever you named it. By default its IDD_DIALOG1 or something.
You don't necessarily need the resource id...thats what the class wrapper is for. it handles all the instantiation, etc..
Edited by - mordell on 3/16/00 12:27:35 PM
__________________________________________
Yeah, sure... we are laughing WITH you ...
Yeah, sure... we are laughing WITH you ...
You were right in your first post, and thats how I thought it originally worked but everytime my menu item called the dialog, it would crash. I assumed it was because it didn''t know which resource to load. I was wrong. It turns out I was doing something wacky in the OnInitDialog that was overflowing the stack. As soon as I stepped through the program step by step I saw it. Ouch, it hurts when you still get caught on newbie mistakes! Thanks for the help mordell.
Mike Barela
mbarela@earthlink.net
Mike Barela
mbarela@earthlink.net
Mike BarelaMikeB@yaya.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement