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. How to add Buttons dynamically

How to add Buttons dynamically

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
2 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
    mr2003
    wrote on last edited by
    #1

    Hi, In my application, MDI, I have to read an output file in one of the dialog boxes. According to the output file, lets say 6 is read in the file. I then have to make 6 Buttons in that Dialog box. the number 6 could change, so I would like to know how to make it dynamic. Any ideas? Ehsan Behboudi

    N 1 Reply Last reply
    0
    • M mr2003

      Hi, In my application, MDI, I have to read an output file in one of the dialog boxes. According to the output file, lets say 6 is read in the file. I then have to make 6 Buttons in that Dialog box. the number 6 could change, so I would like to know how to make it dynamic. Any ideas? Ehsan Behboudi

      N Offline
      N Offline
      Nitron
      wrote on last edited by
      #2

      Just use a std::vector of CButtons.

      std::vector<CButton> m_Buttons;

      ifstream inFile;
      char buff[1024] = {0};
      CString szBuff;

      inFile.open("YourFile.txt");

      while !inFile.eof())
      {
      inFile.getline(buff, sizeof(buff), chDelim);
      szBuff = buff;
      m_Buttons.push_back(CButton());
      if(!m_Buttons.back().Create(static_cast<const char*>(szBuff), STYLEFLAGS, rectforbutton, this, uiSomeID))
      TRACE("Error creating button");
      m_Buttons.back().ShowWindow(SW_SHOW);

      }

      inFile.close();

      - Nitron


      "Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb

      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