Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Calling a Function in CMainFrame

Calling a Function in CMainFrame

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abhijeet Pathak
    wrote on last edited by
    #1

    Hi, I have a MFC app with a main form (CMainFrame) and a dialog. How can I call a member function of CMainFrame from another dialog?

    S 1 Reply Last reply
    0
    • A Abhijeet Pathak

      Hi, I have a MFC app with a main form (CMainFrame) and a dialog. How can I call a member function of CMainFrame from another dialog?

      S Offline
      S Offline
      StevenS_Dev
      wrote on last edited by
      #2

      One way is to pass the CMainFrame into your dialog. Another is to use the m_pMainWnd member from your application object like this: CMainFrame* mainFrame = dynamic_cast(AfxGetApp()->m_pMainWnd); mainFrame->doThisMemberMethod();

      A 2 Replies Last reply
      0
      • S StevenS_Dev

        One way is to pass the CMainFrame into your dialog. Another is to use the m_pMainWnd member from your application object like this: CMainFrame* mainFrame = dynamic_cast(AfxGetApp()->m_pMainWnd); mainFrame->doThisMemberMethod();

        A Offline
        A Offline
        Abhijeet Pathak
        wrote on last edited by
        #3

        Hey, I tried that. But while compiling I am getting error: error C2059: syntax error : ')' I can't figure out why. Can u please help me?

        1 Reply Last reply
        0
        • S StevenS_Dev

          One way is to pass the CMainFrame into your dialog. Another is to use the m_pMainWnd member from your application object like this: CMainFrame* mainFrame = dynamic_cast(AfxGetApp()->m_pMainWnd); mainFrame->doThisMemberMethod();

          A Offline
          A Offline
          Abhijeet Pathak
          wrote on last edited by
          #4

          Oh! I looked at MSDN and found the correct way to use it. The code should be as follows: CMainFrame* mainFrame = dynamic_cast(AfxGetApp()->m_pMainWnd); mainFrame->doThisMemberMethod(); Thanks. -- modified at 6:26 Sunday 17th June, 2007

          S 1 Reply Last reply
          0
          • A Abhijeet Pathak

            Oh! I looked at MSDN and found the correct way to use it. The code should be as follows: CMainFrame* mainFrame = dynamic_cast(AfxGetApp()->m_pMainWnd); mainFrame->doThisMemberMethod(); Thanks. -- modified at 6:26 Sunday 17th June, 2007

            S Offline
            S Offline
            StevenS_Dev
            wrote on last edited by
            #5

            Ooops. I copied the code from one of my own projects and had to rename things from my class name to CMainFrame. I accidentally erased . Very sorry about that. Glad you still figured it out. I ran into my own pet peeve of someone giving a code example which doesn't work.

            S 1 Reply Last reply
            0
            • S StevenS_Dev

              Ooops. I copied the code from one of my own projects and had to rename things from my class name to CMainFrame. I accidentally erased . Very sorry about that. Glad you still figured it out. I ran into my own pet peeve of someone giving a code example which doesn't work.

              S Offline
              S Offline
              StevenS_Dev
              wrote on last edited by
              #6

              Hmmm, strange. Apparently I did not erase it. It seems the forum is completely deleting my code. I just typed it again in my previous message and it does not show up in the post. Somehow it worked when you typed it in your post. I wonder why.

              D 1 Reply Last reply
              0
              • S StevenS_Dev

                Hmmm, strange. Apparently I did not erase it. It seems the forum is completely deleting my code. I just typed it again in my previous message and it does not show up in the post. Somehow it worked when you typed it in your post. I wonder why.

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                StevenS_Dev wrote:

                It seems the forum is completely deleting my code.

                No, it's there, albeit not shown. You are just failing to use the angle brackets above the smileys.


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups