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 can I programmatically add controls.

How can I programmatically add controls.

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++tutoriallearning
8 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.
  • M Offline
    M Offline
    Marko B L
    wrote on last edited by
    #1

    Hi, well, it's for sure a simple problem for an advanced MFC user, but I don't know how to solve it X| Here's what i want to do: I want to create a MFC controls dynamically to my MFC dialog without the use of the resource editor. E.g. a simple static text at the coordinates 0,0 with text on it? The reason I'm asking is that I have to add 120 leds/labels to a dialog and I don't want to make it by hand, because if something changes, I have to redo everything, Or if I want to add tabs later. Thanks for your help.

    M 1 Reply Last reply
    0
    • M Marko B L

      Hi, well, it's for sure a simple problem for an advanced MFC user, but I don't know how to solve it X| Here's what i want to do: I want to create a MFC controls dynamically to my MFC dialog without the use of the resource editor. E.g. a simple static text at the coordinates 0,0 with text on it? The reason I'm asking is that I have to add 120 leds/labels to a dialog and I don't want to make it by hand, because if something changes, I have to redo everything, Or if I want to add tabs later. Thanks for your help.

      M Offline
      M Offline
      Mila025
      wrote on last edited by
      #2

      Hi, This is simple window - you can add the new e.g. by CStatic class (derivied from CWnd): CStatic * myStatic = new CStatic; myStatic->Create( _T("my static"), WS_CHILD|WS_VISIBLE|SS_CENTER, CRect(0,0,150,15), pParentWnd );

      ----------- Mila

      T 1 Reply Last reply
      0
      • M Mila025

        Hi, This is simple window - you can add the new e.g. by CStatic class (derivied from CWnd): CStatic * myStatic = new CStatic; myStatic->Create( _T("my static"), WS_CHILD|WS_VISIBLE|SS_CENTER, CRect(0,0,150,15), pParentWnd );

        ----------- Mila

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        Mila025 wrote:

        M

        Mila025 wrote:

        CStatic * myStatic = new CStatic; myStatic->Create( _T("my static"), WS_CHILD|WS_VISIBLE|SS_CENTER, CRect(0,0,150,15), pParentWnd );

        don't forget to delete the MyStatic object

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you

        M 1 Reply Last reply
        0
        • T ThatsAlok

          Mila025 wrote:

          M

          Mila025 wrote:

          CStatic * myStatic = new CStatic; myStatic->Create( _T("my static"), WS_CHILD|WS_VISIBLE|SS_CENTER, CRect(0,0,150,15), pParentWnd );

          don't forget to delete the MyStatic object

          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

          cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you

          M Offline
          M Offline
          Mila025
          wrote on last edited by
          #4

          naturally ;-) kindest regards

          ----------- Mila

          M 1 Reply Last reply
          0
          • M Mila025

            naturally ;-) kindest regards

            ----------- Mila

            M Offline
            M Offline
            Marko B L
            wrote on last edited by
            #5

            Thanks for you help :) Now to the next problem :~ I'm using the following controler: http://www.codeproject.com/buttonctrl/LedButton.asp[^] It's an LED button, which interhits from CButton. I can actually create a CButton dynamically, but it doesn't work with this CLedButton class. If anyone has five free minutes, it would you could say why it doesn't work this this control :confused:

            M 1 Reply Last reply
            0
            • M Marko B L

              Thanks for you help :) Now to the next problem :~ I'm using the following controler: http://www.codeproject.com/buttonctrl/LedButton.asp[^] It's an LED button, which interhits from CButton. I can actually create a CButton dynamically, but it doesn't work with this CLedButton class. If anyone has five free minutes, it would you could say why it doesn't work this this control :confused:

              M Offline
              M Offline
              Mila025
              wrote on last edited by
              #6

              Hi, hm do you mean something like that: CLedButton * led = new CLedButton; led->Create( "an strange text", WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX, CRect( 2, 2, 120, 20 ), this, iCtrlId ); led->SetIcons(IDI_GRAY_LED_ICON, IDI_GREEN_LED_ICON); ... ... ... delete led;

              ----------- Mila

              M T 2 Replies Last reply
              0
              • M Mila025

                Hi, hm do you mean something like that: CLedButton * led = new CLedButton; led->Create( "an strange text", WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX, CRect( 2, 2, 120, 20 ), this, iCtrlId ); led->SetIcons(IDI_GRAY_LED_ICON, IDI_GREEN_LED_ICON); ... ... ... delete led;

                ----------- Mila

                M Offline
                M Offline
                Marko B L
                wrote on last edited by
                #7

                Mila025 wrote:

                Hi, hm do you mean something like that: CLedButton * led = new CLedButton; led->Create( "an strange text", WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX, CRect( 2, 2, 120, 20 ), this, iCtrlId ); led->SetIcons(IDI_GRAY_LED_ICON, IDI_GREEN_LED_ICON); ... ... ... delete led;

                Yes, thanks. I found it out on my own at the same time and wanted to post it here, but you were faster :) The BS_AUTOCHECKBOX flag needs to be set, otherwise the class asserts. Damn, I have the feeling that asserts are really bad implemented. I'm using my non-mfc application an custom assert, which brings me directly to the line, where the assert happend and not somewhere deep in the MFC, where I have to search the huge call stack for the place, where the real assert happend. Anyway, thanks for you help :)

                1 Reply Last reply
                0
                • M Mila025

                  Hi, hm do you mean something like that: CLedButton * led = new CLedButton; led->Create( "an strange text", WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX, CRect( 2, 2, 120, 20 ), this, iCtrlId ); led->SetIcons(IDI_GRAY_LED_ICON, IDI_GREEN_LED_ICON); ... ... ... delete led;

                  ----------- Mila

                  T Offline
                  T Offline
                  ThatsAlok
                  wrote on last edited by
                  #8

                  Mila025 wrote:

                  delete led;

                  better make a call to DestoryWindow before deleting variable or make call to delete at destructor or OnDestroy Window handller

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                  cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you

                  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