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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Communicating with top level form

Communicating with top level form

Scheduled Pinned Locked Moved Managed C++/CLI
c++question
8 Posts 2 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.
  • M Offline
    M Offline
    mrhonus
    wrote on last edited by
    #1

    Using the designer to create the main form for an application generated the following code in the .cpp file: int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA; Application::Run(new DataForm(lpCmdLine)); return 0; } The DataForm class has a button which generates a new form: linkedForm = new LinkedForm() ; The LinkedForm class exists in the same namespace as the DataForm class. What needs to be done to allow this child form to see public methods in it's parent, since a DataForm ptr cannot be declared globally? Are there any examples of parent/child form communications of this nature? Thanks, MrHonus

    L 1 Reply Last reply
    0
    • M mrhonus

      Using the designer to create the main form for an application generated the following code in the .cpp file: int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA; Application::Run(new DataForm(lpCmdLine)); return 0; } The DataForm class has a button which generates a new form: linkedForm = new LinkedForm() ; The LinkedForm class exists in the same namespace as the DataForm class. What needs to be done to allow this child form to see public methods in it's parent, since a DataForm ptr cannot be declared globally? Are there any examples of parent/child form communications of this nature? Thanks, MrHonus

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      See the MVC (Model-View-Controller) design pattern. It is on Wikipedia. Forms are Views and should not be coupled. Views (Forms) should access a "Controller" to initiate action based on UI (User) events. Views subscribe to events exposed from the "Model" to be notified of data and/or "state" changes. Views then obtain the latest data to display from the "Model".

      M 1 Reply Last reply
      0
      • L led mike

        See the MVC (Model-View-Controller) design pattern. It is on Wikipedia. Forms are Views and should not be coupled. Views (Forms) should access a "Controller" to initiate action based on UI (User) events. Views subscribe to events exposed from the "Model" to be notified of data and/or "state" changes. Views then obtain the latest data to display from the "Model".

        M Offline
        M Offline
        mrhonus
        wrote on last edited by
        #3

        Well, since I used the .net designer to create all of the views, it doesn't seem to lend itself to mvc. Are there any examples of how to use mvc with studio/net generated forms? Thanks for the reply

        L 1 Reply Last reply
        0
        • M mrhonus

          Well, since I used the .net designer to create all of the views, it doesn't seem to lend itself to mvc. Are there any examples of how to use mvc with studio/net generated forms? Thanks for the reply

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          mrhonus wrote:

          it doesn't seem to lend itself to mvc.

          :confused: That makes no sense.

          mrhonus wrote:

          Are there any examples of how to use mvc with studio/net generated forms?

          Sure the Microsoft UI Composit Application Block[^]

          M 1 Reply Last reply
          0
          • L led mike

            mrhonus wrote:

            it doesn't seem to lend itself to mvc.

            :confused: That makes no sense.

            mrhonus wrote:

            Are there any examples of how to use mvc with studio/net generated forms?

            Sure the Microsoft UI Composit Application Block[^]

            M Offline
            M Offline
            mrhonus
            wrote on last edited by
            #5

            I agree, it makes no sense. Well, I am looking for C++ examples. Thanks

            L 1 Reply Last reply
            0
            • M mrhonus

              I agree, it makes no sense. Well, I am looking for C++ examples. Thanks

              L Offline
              L Offline
              led mike
              wrote on last edited by
              #6

              mrhonus wrote:

              Well, I am looking for C++ examples.

              You are using .NET WinForms

              mrhonus wrote:

              Application::Run(new DataForm(lpCmdLine));

              The application block is .NET library so you can use it. If you can't translate C# samples into Managed C++ why are you doing Managed Development in C++?

              M 1 Reply Last reply
              0
              • L led mike

                mrhonus wrote:

                Well, I am looking for C++ examples.

                You are using .NET WinForms

                mrhonus wrote:

                Application::Run(new DataForm(lpCmdLine));

                The application block is .NET library so you can use it. If you can't translate C# samples into Managed C++ why are you doing Managed Development in C++?

                M Offline
                M Offline
                mrhonus
                wrote on last edited by
                #7

                Mainly because so many things which I know about C++ don't seem to apply in the .Net environment. I'm doing Managed Devlopment in C++ because I wasn't allowed to choose the development environment. I would have chosen Java, which is much more straightforward. But since you're now getting snide, I guess you've helped me enough--thanks for your time.

                L 1 Reply Last reply
                0
                • M mrhonus

                  Mainly because so many things which I know about C++ don't seem to apply in the .Net environment. I'm doing Managed Devlopment in C++ because I wasn't allowed to choose the development environment. I would have chosen Java, which is much more straightforward. But since you're now getting snide, I guess you've helped me enough--thanks for your time.

                  L Offline
                  L Offline
                  led mike
                  wrote on last edited by
                  #8

                  mrhonus wrote:

                  But since you're now getting snide

                  Not at all. So many times in message based communications people leave out reasons for things that create gaps in understanding. I was just trying to understand how you arrived in your situation to see if a different view might help. It does not appear so.

                  mrhonus wrote:

                  I would have chosen Java, which is much more straightforward.

                  Much more straight forward than Managed C++ but very similar to C#. Perhaps you could use C# Research apps as a way of learning the .NET libraries you need and then translate your own C# code into managed C++. That would also allow you to apply samples you can find to the C# research application. It's not real pretty but after time you probably won't need the C# step as you would be able to translate the samples directly to C++. Also on the MSDN2 web site many of the .NET Framework Documentation contains short samples in C++.

                  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