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. limited dynamic CStatics

limited dynamic CStatics

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorialannouncement
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.
  • H Offline
    H Offline
    halblonious
    wrote on last edited by
    #1

    So...I want users to be able to create an unlimited number of CStatics dynamically in my program, and save & load them. Right now, I'm just defining 20 of them in OnCreate, then serializing data about those 20 (blank data for those not yet created). My problem is: how do I create dynamically any number of them, yet still have a way of say painting/updating them, or even knowing how to refer to them from a function other than the one in which they were created (my only guess on how to make unlimited is just to have the same variable name for each one as it's created, then store the data, but then I'd have to re-create each one on EVERY update or painting for the user to be able to see all of them? Wouldn't this be a horrible waste of resources?) Or, is there nothing to be done, and I should just define like 200 from the beginning and hope they don't want to go crazy with creating things? halblonious

    C 1 Reply Last reply
    0
    • H halblonious

      So...I want users to be able to create an unlimited number of CStatics dynamically in my program, and save & load them. Right now, I'm just defining 20 of them in OnCreate, then serializing data about those 20 (blank data for those not yet created). My problem is: how do I create dynamically any number of them, yet still have a way of say painting/updating them, or even knowing how to refer to them from a function other than the one in which they were created (my only guess on how to make unlimited is just to have the same variable name for each one as it's created, then store the data, but then I'd have to re-create each one on EVERY update or painting for the user to be able to see all of them? Wouldn't this be a horrible waste of resources?) Or, is there nothing to be done, and I should just define like 200 from the beginning and hope they don't want to go crazy with creating things? halblonious

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Put them in a vector, and I believe that if they are created so that your window is their parent, they will get their proper update calls, etc. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

      H 1 Reply Last reply
      0
      • C Christian Graus

        Put them in a vector, and I believe that if they are created so that your window is their parent, they will get their proper update calls, etc. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

        H Offline
        H Offline
        halblonious
        wrote on last edited by
        #3

        You'll have to pardon my ineptitude, but can you tell me what a vector is, and how to use them? I figured there must be some well-known way to do what I want, I just didn't know about it. halblonious

        C P 2 Replies Last reply
        0
        • H halblonious

          You'll have to pardon my ineptitude, but can you tell me what a vector is, and how to use them? I figured there must be some well-known way to do what I want, I just didn't know about it. halblonious

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          A vector is a dynamic array, part of the stl ( standard template library ). If you search for 'vector STL', there are plenty of articles on the site on how to use them. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

          1 Reply Last reply
          0
          • H halblonious

            You'll have to pardon my ineptitude, but can you tell me what a vector is, and how to use them? I figured there must be some well-known way to do what I want, I just didn't know about it. halblonious

            P Offline
            P Offline
            Peter Molnar
            wrote on last edited by
            #5

            Just a simple example of what Christian suggested:

            //in your dialog header
            CStatic m_Statics[1000];

            //in your cpp

            for (int i = 0; i < 1000; i++)
            {
            m_Statics[i].Create(...);
            m_Statics[i].LoadBitmap(...);
            m_Statics[i].ShowWindow(SW_HIDE);
            }

            You can acces the m_Statics[] member variable of your dialog from any function of your dialog.

            void CYourDialog::ShowMeOneStatic(void)
            {
            m_Statics[112].ShowWindow(SW_SHOW);
            }

            But my problem is with your design. A dialog window has a very limited space. How do you wanna show dozens of control on it at a time? Is it possible that you don't need them all at a time? Do you just wanna use those CStatic's to store data, and show a FEW of them on your dialog? Give more details about your project so that we can provide you with more help. Peter Molnar

            H 1 Reply Last reply
            0
            • P Peter Molnar

              Just a simple example of what Christian suggested:

              //in your dialog header
              CStatic m_Statics[1000];

              //in your cpp

              for (int i = 0; i < 1000; i++)
              {
              m_Statics[i].Create(...);
              m_Statics[i].LoadBitmap(...);
              m_Statics[i].ShowWindow(SW_HIDE);
              }

              You can acces the m_Statics[] member variable of your dialog from any function of your dialog.

              void CYourDialog::ShowMeOneStatic(void)
              {
              m_Statics[112].ShowWindow(SW_SHOW);
              }

              But my problem is with your design. A dialog window has a very limited space. How do you wanna show dozens of control on it at a time? Is it possible that you don't need them all at a time? Do you just wanna use those CStatic's to store data, and show a FEW of them on your dialog? Give more details about your project so that we can provide you with more help. Peter Molnar

              H Offline
              H Offline
              halblonious
              wrote on last edited by
              #6

              I'd first like to say that this website and you people who help me out are amazing and wonderful, and I'm thankful for you. Well, the program I'm making is a report generator for doctors. Basically, the visual part for the user will be kinda like Microsoft Publisher. They can make squares, rectangles, and lines, each with whatever thickness or color, and the shapes will have borders and frames. Plus, there'll of course be text boxes. The reason I want to change how I'm doing it is: if I have to plan ahead for ANY possible way someone might want to use this, I'd have to setup at least like 10 of each type of thing from the get go, which I'm assuming uses more overhead than would be good. But, then what if they want 11 text boxes, or 11 ovals? Well, maybe I should create 20 of each? See the issue, there? So, I figured that a dynamic way of creating them would be better, so I'm only using the space needed for what the user wants, and they can create as many whatevers as they so desire. A question: CStatic m_Statics[1000]; Wouldn't that use a ton of memory, or is there really no way to avoid it? Is this an stl vector? Or is that something different? halblonious

              P 1 Reply Last reply
              0
              • H halblonious

                I'd first like to say that this website and you people who help me out are amazing and wonderful, and I'm thankful for you. Well, the program I'm making is a report generator for doctors. Basically, the visual part for the user will be kinda like Microsoft Publisher. They can make squares, rectangles, and lines, each with whatever thickness or color, and the shapes will have borders and frames. Plus, there'll of course be text boxes. The reason I want to change how I'm doing it is: if I have to plan ahead for ANY possible way someone might want to use this, I'd have to setup at least like 10 of each type of thing from the get go, which I'm assuming uses more overhead than would be good. But, then what if they want 11 text boxes, or 11 ovals? Well, maybe I should create 20 of each? See the issue, there? So, I figured that a dynamic way of creating them would be better, so I'm only using the space needed for what the user wants, and they can create as many whatevers as they so desire. A question: CStatic m_Statics[1000]; Wouldn't that use a ton of memory, or is there really no way to avoid it? Is this an stl vector? Or is that something different? halblonious

                P Offline
                P Offline
                Peter Molnar
                wrote on last edited by
                #7

                halblonious wrote: Wouldn't that use a ton of memory No, not an issue. You will hardly notice it in the memory footprint of your app. halblonious wrote: is there really no way to avoid it? There are two ways for storing multiple values of the same type (like those of your shapes): 1.List 2.Array Theoritically both can replace each other, but there are rules of thumbs for their usage: A list should be preferred if the number of elements is not known, and an array if their number is well known. The reson for the why lies in the memory management of them (i.e. the way the stored items are organised in memory). Using a list you can easily (i.e: quickly) access the next or previous element but you can only slowly access the elemnt at a given number from the begining. Arrays can access elements at given position quickly but they are slow if you change their size. If you allocated 1000 CStatic's in an array and later it turns out that you will need 1001 of them, all the stored data in the 1000 CStatic's must be reordered by the memory management which might go slowly. In MFC they are called array and list(e.g see CObArray and CObList in MSDN), but in STL (Satandard Template Library - which is Microsoft independent) they are called vector and list. BTW: ask another question on this forum about your app's design describing what in detail what you want. You will save a bunch of time by not trying to go unachievable ways. Peter Molnar

                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