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. Managed C++/CLI
  4. Arrays and enums in an extended control

Arrays and enums in an extended control

Scheduled Pinned Locked Moved Managed C++/CLI
graphicsc++data-structureshelptutorial
6 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.
  • P Offline
    P Offline
    poppabaggins
    wrote on last edited by
    #1

    Hi, I'm completely new to C++ as a whole, so there might be a simple answer to my question, so here goes. I'm trying to write a program that will have the screen broken up into zones, or areas, each with a Point (location) a Size, an Image, and an array of terrain types (an enum). Trying to include a bitmap in my class made the compiler tell me that I couldn't mix managed and unmanaged types. To try to work around this, I tried extending the PictureBox control, but this has given me even more headaches. Basically, I can't figure out how to declare/use an array in an extended control.

    #pragma once

    using namespace System::Drawing;
    using namespace System::Windows::Forms;
    using namespace cli; //something I think MSDN said I had to do

    namespace MapEdit
    {
    //better than a "magic number". there can only be 3 different types of terrain per square
    //used in the TerrainTypes array
    const int MAX_TERRAIN = 3;

    public ref class Zone : public System::Windows::Forms::PictureBox
    {
    	
    public:
    	enum Terrain //says I can't mix types
    	{
    		Plain,
    		Hill,
    		Wood,
    		Marsh,
    		Stream,
    		River,
    		ShoreLine,
    		Impassable
    	};
    	
    	array<byte^> ^TerrainTypes; //this doesn't work
    	int TerrainTypes\[3\]; //neither does this.
    

    ... All of my errors (except the parts where I try to use these faulty enum/ array) come from this block. Frankly, I'm at a loss as to how to fix this. Also, if someone could tell me how to include a Bitmap in an unmanged class, that would be nice too. Thanks, Christian

    L M 2 Replies Last reply
    0
    • P poppabaggins

      Hi, I'm completely new to C++ as a whole, so there might be a simple answer to my question, so here goes. I'm trying to write a program that will have the screen broken up into zones, or areas, each with a Point (location) a Size, an Image, and an array of terrain types (an enum). Trying to include a bitmap in my class made the compiler tell me that I couldn't mix managed and unmanaged types. To try to work around this, I tried extending the PictureBox control, but this has given me even more headaches. Basically, I can't figure out how to declare/use an array in an extended control.

      #pragma once

      using namespace System::Drawing;
      using namespace System::Windows::Forms;
      using namespace cli; //something I think MSDN said I had to do

      namespace MapEdit
      {
      //better than a "magic number". there can only be 3 different types of terrain per square
      //used in the TerrainTypes array
      const int MAX_TERRAIN = 3;

      public ref class Zone : public System::Windows::Forms::PictureBox
      {
      	
      public:
      	enum Terrain //says I can't mix types
      	{
      		Plain,
      		Hill,
      		Wood,
      		Marsh,
      		Stream,
      		River,
      		ShoreLine,
      		Impassable
      	};
      	
      	array<byte^> ^TerrainTypes; //this doesn't work
      	int TerrainTypes\[3\]; //neither does this.
      

      ... All of my errors (except the parts where I try to use these faulty enum/ array) come from this block. Frankly, I'm at a loss as to how to fix this. Also, if someone could tell me how to include a Bitmap in an unmanged class, that would be nice too. Thanks, Christian

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

      poppabaggins wrote:

      Trying to include a bitmap in my class made the compiler tell me that I couldn't mix managed and unmanaged types. To try to work around this

      Rather than work around by making something up yourself I would strongly suggest that you learn C++/CLI. There are excellent tutorial articles on CLI here at CodeProject. Look under the "Chapters" in the site menu. Of course I would also strongly recommend you learn C++ first and then learn C++/CLI. I mean CLI is an extension so it seems rather obvious that one learns the root before the extension, but what do I know right?

      led mike

      M 1 Reply Last reply
      0
      • P poppabaggins

        Hi, I'm completely new to C++ as a whole, so there might be a simple answer to my question, so here goes. I'm trying to write a program that will have the screen broken up into zones, or areas, each with a Point (location) a Size, an Image, and an array of terrain types (an enum). Trying to include a bitmap in my class made the compiler tell me that I couldn't mix managed and unmanaged types. To try to work around this, I tried extending the PictureBox control, but this has given me even more headaches. Basically, I can't figure out how to declare/use an array in an extended control.

        #pragma once

        using namespace System::Drawing;
        using namespace System::Windows::Forms;
        using namespace cli; //something I think MSDN said I had to do

        namespace MapEdit
        {
        //better than a "magic number". there can only be 3 different types of terrain per square
        //used in the TerrainTypes array
        const int MAX_TERRAIN = 3;

        public ref class Zone : public System::Windows::Forms::PictureBox
        {
        	
        public:
        	enum Terrain //says I can't mix types
        	{
        		Plain,
        		Hill,
        		Wood,
        		Marsh,
        		Stream,
        		River,
        		ShoreLine,
        		Impassable
        	};
        	
        	array<byte^> ^TerrainTypes; //this doesn't work
        	int TerrainTypes\[3\]; //neither does this.
        

        ... All of my errors (except the parts where I try to use these faulty enum/ array) come from this block. Frankly, I'm at a loss as to how to fix this. Also, if someone could tell me how to include a Bitmap in an unmanged class, that would be nice too. Thanks, Christian

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Are you trying to make an array of enums? If so, why did you try to create a byte (whatever that is) array and an int array? First, you can't embed a native enumeration in a ref class. Second, once you have a managed enum class, you can create an array that stores the enum type...

        enum class Terrain
        {
        	Plain,
        	Hill,
        	Wood,
        	Marsh,
        	Stream,
        	River,
        	ShoreLine,
        	Impassable
        };
        
        array<Terrain> ^TerrainTypes;
        

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        P 1 Reply Last reply
        0
        • L led mike

          poppabaggins wrote:

          Trying to include a bitmap in my class made the compiler tell me that I couldn't mix managed and unmanaged types. To try to work around this

          Rather than work around by making something up yourself I would strongly suggest that you learn C++/CLI. There are excellent tutorial articles on CLI here at CodeProject. Look under the "Chapters" in the site menu. Of course I would also strongly recommend you learn C++ first and then learn C++/CLI. I mean CLI is an extension so it seems rather obvious that one learns the root before the extension, but what do I know right?

          led mike

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          led mike wrote:

          it seems rather obvious that one learns the root before the extension

          :laugh: Good one. You hang out on the C# board....it's pretty obvious there's a whole new generation of "programmers" that have completely bypassed the fundamentals. :beer:

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          L 1 Reply Last reply
          0
          • M Mark Salsbery

            led mike wrote:

            it seems rather obvious that one learns the root before the extension

            :laugh: Good one. You hang out on the C# board....it's pretty obvious there's a whole new generation of "programmers" that have completely bypassed the fundamentals. :beer:

            Mark Salsbery Microsoft MVP - Visual C++ :java:

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

            Mark Salsbery wrote:

            it's pretty obvious there's a whole new generation of "programmers" that have completely bypassed the fundamentals.

            they also seem to mostly bypass thinking. ;) It's likely a symptom of Drag and Drop development. Vee Bee Stupid :jig:

            led mike

            1 Reply Last reply
            0
            • M Mark Salsbery

              Are you trying to make an array of enums? If so, why did you try to create a byte (whatever that is) array and an int array? First, you can't embed a native enumeration in a ref class. Second, once you have a managed enum class, you can create an array that stores the enum type...

              enum class Terrain
              {
              	Plain,
              	Hill,
              	Wood,
              	Marsh,
              	Stream,
              	River,
              	ShoreLine,
              	Impassable
              };
              
              array<Terrain> ^TerrainTypes;
              

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              P Offline
              P Offline
              poppabaggins
              wrote on last edited by
              #6

              Thanks, I was trying to come up with some sort of sensible code from searching the internet, but nothing seemed to work for me. Basically, I'm working off of what little I know from C# and the small amount of information I can get from my professor after class. It obviously wasn't working well for me. This is part of a project for school, but my book has absolutely nothing on managed c++. I would take the time to learn C++/cli, but this project is due at the end of the semester, and I have so many other things I'm reading now for classes/personal study/entertainment. I'll get to it eventually, but I have a lot of other things I'm doing now.

              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