-
March 11th, 2013, 04:57 PM
#1
DoModal is not a Member?
Hello,
I'm just learning this, and I am working through these tutorials:
http://www.codersource.net/MFC/MFCTu...oxesinMFC.aspx
I haven't had to modify them much for VS2010 so far. Right now, (I think) I have created the dialog box, and the menu as a class and a resource, respectively. However, when I call
Code:
void MFC_Tutorial_Window::OnClickDialogNew()
{
NewDialog dlg;
dlg.DoModal();
}
I get an error 'DoModal' : is not a member of 'NewDialog'
I suppose somehow I need to link the menu to the dialog box?
I believe I've added the references, included the libraries and essentially followed the instructions. Apparently I'm not very clear on how to make resources interact with new classes. Can anyone point me in the right direction?
Thanks very much!
-
March 11th, 2013, 07:28 PM
#2
Re: DoModal is not a Member?
Did you do step 7?
Step 7:
Now click on Menu --> View --> Class Wizard or press Ctrl + W. You will be presented with a dialog asking you, if you want to create a new class. Say Yes. The wizard will create a new dialog class and related files( Newdialog.h & newdialog.cpp) for you.
-
March 11th, 2013, 07:37 PM
#3
Re: DoModal is not a Member?
Originally Posted by Grue42
I get an error 'DoModal' : is not a member of 'NewDialog'
I suppose somehow I need to link the menu to the dialog box?
Your error is a general C++ error, and really has nothing to do with dialog boxes. Instead of thinking of dialog boxes and MFC, look at what the error is telling you in terms of the C++ language.
When you call a member function, that function must be available within the public interface of the class. There is no such function as "DoModal" that is in the NewDialog class that is publicly accessible, and it isn't publicly accessible from any parent class of NewDialog. In other words, either DoModal() doesn't exist within the NewDialog (or parent classes), or the function does exist and it is not publicly accessible (it is protected or private).
You get the same error if you did this:
Code:
class bar
{
public:
void b();
};
class foo : public bar
{
public:
void x();
};
int main()
{
foo f;
f.y(); // there is no function "y" defined in class foo or in its parent class "bar".
}
I believe I've added the references, included the libraries and essentially followed the instructions. Apparently I'm not very clear on how to make resources interact with new classes. Can anyone point me in the right direction?
Thanks very much!
Your problem has absolutely nothing to do with references, libraries, or resources. The problem is not understanding the rules of the C++ language in terms of how to define member functions, deriving from classes that contain those functions, making the functions publicly available, or a combination of all of these concepts.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; March 11th, 2013 at 07:39 PM.
-
March 12th, 2013, 07:22 AM
#4
Re: DoModal is not a Member?
Look at the definition of NewDialog. What is the base class?
-
March 12th, 2013, 07:24 AM
#5
Re: DoModal is not a Member?
Originally Posted by Paul McKenzie
When you call a member function, that function must be available within the public interface of the class. There is no such function as "DoModal" that is in the NewDialog class that is publicly accessible, and it isn't publicly accessible from any parent class of NewDialog. In other words, either DoModal() doesn't exist within the NewDialog (or parent classes), or the function does exist and it is not publicly accessible (it is protected or private).
I believe the compiler error will reflect that you're making an illegal call to a protected or private member if that's the case, rather than telling you the function doesn't exist.
-
March 12th, 2013, 09:01 AM
#6
Re: DoModal is not a Member?
Arjay and GCDEF:
The instructions for adding the new class "NewDialog" didn't quite match with my version. I did create a new class (Project -> Class Wizard -> Add Class). I left the base class "CWnd" - should it perhaps be CFrameWnd? Would this make the class/function available? (I guess #include isn't sufficient.)
Paul and GCDEF:
Thank you for that extremely detailed look at structure - it was very helpful. As I said, I have very little background in programming and this is all very new to me so I appreciate the information. I thought DoModal was a system command that would open/create the dialog box I created - so you're saying I haven't made the dialog box available in the public interface? How might I define that?
I hope my questions don't sound too stupid, it's a bit overwhelming to know where to start building a foundation!
Thank you all again for your help!
-
March 12th, 2013, 09:15 AM
#7
Re: DoModal is not a Member?
The base class should have been CDialog. They way you're using it, DoModal is a member of CDialog.
-
March 12th, 2013, 10:32 AM
#8
Re: DoModal is not a Member?
Ah, Dialog Box handling is done using CDialog class in MFC. So I create the class NewDialog of base class CDialog (hence CDialog:oModal?)
-
March 12th, 2013, 11:34 AM
#9
Re: DoModal is not a Member?
Originally Posted by Grue42
Ah, Dialog Box handling is done using CDialog class in MFC. So I create the class NewDialog of base class CDialog (hence CDialog::DoModal?)
Exactly!
Victor Nijegorodov
-
March 14th, 2013, 02:18 AM
#10
Re: DoModal is not a Member?
...and, in each situation of this kind (and every time it's necessary), have a look in the documentation: http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx.
Or, hit F12 key for jumping to whatever class definition to see if it has or not whatever method.
Looking in the documentation isn't so hard and prevents a lot of headaches.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|