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. Accessing a method in the Dlg object from the App object.

Accessing a method in the Dlg object from the App object.

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharpvisual-studioquestion
9 Posts 5 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.
  • L Offline
    L Offline
    LCI
    wrote on last edited by
    #1

    I have an MFC Dlg Application. Say the project is called Test. Visual Studio creates a TestDlg.cpp and a Test.cpp among others. I am finding that some initialization that i need to do in the Test.cpp involves me having to have access to a variable in the TestDlg.cpp. I cannot do a static cast of the TestDlg.cpp can I?

    M D T N 4 Replies Last reply
    0
    • L LCI

      I have an MFC Dlg Application. Say the project is called Test. Visual Studio creates a TestDlg.cpp and a Test.cpp among others. I am finding that some initialization that i need to do in the Test.cpp involves me having to have access to a variable in the TestDlg.cpp. I cannot do a static cast of the TestDlg.cpp can I?

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

      Before calling the dialog's DoModal() method, you can access the dialog's public members.

      "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

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

      1 Reply Last reply
      0
      • L LCI

        I have an MFC Dlg Application. Say the project is called Test. Visual Studio creates a TestDlg.cpp and a Test.cpp among others. I am finding that some initialization that i need to do in the Test.cpp involves me having to have access to a variable in the TestDlg.cpp. I cannot do a static cast of the TestDlg.cpp can I?

        M Offline
        M Offline
        Maxwell Chen
        wrote on last edited by
        #3

        "Test.cpp" is where your CTestApp implementation is. "TestDlg.cpp" is where your main dialog window CTestDlg implementation is. In "Test.cpp", there is the function CTestApp::InitInstance. Inside this function body, you can see the variable

        // ...
        CTestDlg dlg;
        dlg.DoModal();
        // ...

        So you can do initialization like this:

        // ...
        CTestDlg dlg;
        dlg.InitMyMemberValues();
        dlg.DoModal();
        // ...

        Maxwell Chen

        L 1 Reply Last reply
        0
        • M Maxwell Chen

          "Test.cpp" is where your CTestApp implementation is. "TestDlg.cpp" is where your main dialog window CTestDlg implementation is. In "Test.cpp", there is the function CTestApp::InitInstance. Inside this function body, you can see the variable

          // ...
          CTestDlg dlg;
          dlg.DoModal();
          // ...

          So you can do initialization like this:

          // ...
          CTestDlg dlg;
          dlg.InitMyMemberValues();
          dlg.DoModal();
          // ...

          Maxwell Chen

          L Offline
          L Offline
          LCI
          wrote on last edited by
          #4

          Is this the same way of thinking for a View application as opposed to a dlg based?

          M 1 Reply Last reply
          0
          • L LCI

            Is this the same way of thinking for a View application as opposed to a dlg based?

            M Offline
            M Offline
            Maxwell Chen
            wrote on last edited by
            #5

            LCI wrote:

            Is this the same way of thinking for a View application as opposed to a dlg based?

            This is the C++ object-oriented way. :-D

            Maxwell Chen

            L 1 Reply Last reply
            0
            • M Maxwell Chen

              LCI wrote:

              Is this the same way of thinking for a View application as opposed to a dlg based?

              This is the C++ object-oriented way. :-D

              Maxwell Chen

              L Offline
              L Offline
              LCI
              wrote on last edited by
              #6

              What i mean is in a dlg based app we have: CTestDlg dlg; dlg.DoModal(); in the initistance. What is the equivalent for a Single or multiple document based application? In other words , the same original question,just applied to a single or multi0ple document based app instead of a dlg based?

              D 1 Reply Last reply
              0
              • L LCI

                I have an MFC Dlg Application. Say the project is called Test. Visual Studio creates a TestDlg.cpp and a Test.cpp among others. I am finding that some initialization that i need to do in the Test.cpp involves me having to have access to a variable in the TestDlg.cpp. I cannot do a static cast of the TestDlg.cpp can I?

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #7

                not sure if it's really related to your problem, but have a look at this article[^] anyway...

                [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                1 Reply Last reply
                0
                • L LCI

                  What i mean is in a dlg based app we have: CTestDlg dlg; dlg.DoModal(); in the initistance. What is the equivalent for a Single or multiple document based application? In other words , the same original question,just applied to a single or multi0ple document based app instead of a dlg based?

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

                  After the view object has been created, you can access its public members.

                  "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

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

                  1 Reply Last reply
                  0
                  • L LCI

                    I have an MFC Dlg Application. Say the project is called Test. Visual Studio creates a TestDlg.cpp and a Test.cpp among others. I am finding that some initialization that i need to do in the Test.cpp involves me having to have access to a variable in the TestDlg.cpp. I cannot do a static cast of the TestDlg.cpp can I?

                    N Offline
                    N Offline
                    Nathan Holt at EMOM
                    wrote on last edited by
                    #9

                    LCI wrote:

                    I have an MFC Dlg Application. Say the project is called Test. Visual Studio creates a TestDlg.cpp and a Test.cpp among others. I am finding that some initialization that i need to do in the Test.cpp involves me having to have access to a variable in the TestDlg.cpp. I cannot do a static cast of the TestDlg.cpp can I?

                    I would add a CTestDlg member variable to CTestApp and change InitInstance to use that instead of one local to InitInstance. Nathan

                    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