CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Mar 2013
    Location
    I know how fast I'm moving
    Posts
    11

    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!

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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.

  3. #3
    Join Date
    Mar 2013
    Location
    I know how fast I'm moving
    Posts
    11

    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!

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    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.

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: DoModal is not a Member?

    Quote Originally Posted by Grue42 View Post
    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.

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: DoModal is not a Member?

    Quote Originally Posted by Paul McKenzie View Post

    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.

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: DoModal is not a Member?

    Look at the definition of NewDialog. What is the base class?

  8. #8
    Join Date
    Mar 2013
    Location
    I know how fast I'm moving
    Posts
    11

    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?)

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: DoModal is not a Member?

    Quote Originally Posted by Grue42 View Post
    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

  10. #10
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured