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. Dynamic controls

Dynamic controls

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorial
9 Posts 4 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.
  • G Offline
    G Offline
    grassrootkit
    wrote on last edited by
    #1

    How do I add event handler for dynamically created controls in MFC? For example a button & an onclick event.

    D M 2 Replies Last reply
    0
    • G grassrootkit

      How do I add event handler for dynamically created controls in MFC? For example a button & an onclick event.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      grassrootkit wrote:

      How do I add event handler for dynamically created controls in MFC? For example a button & an onclick event.

      Just like any other button click:

      BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
      //{{AFX_MSG_MAP(CMyDialog)
      ON_BN_CLICKED(IDC_SOME_BUTTON, OnButtonClicked)
      //}}AFX_MSG_MAP
      END_MESSAGE_MAP()

      "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      G L 2 Replies Last reply
      0
      • D David Crow

        grassrootkit wrote:

        How do I add event handler for dynamically created controls in MFC? For example a button & an onclick event.

        Just like any other button click:

        BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
        //{{AFX_MSG_MAP(CMyDialog)
        ON_BN_CLICKED(IDC_SOME_BUTTON, OnButtonClicked)
        //}}AFX_MSG_MAP
        END_MESSAGE_MAP()

        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        G Offline
        G Offline
        grassrootkit
        wrote on last edited by
        #3

        Can't follow you. I'm creating the control like:

        CButton\* pButton = new CButton;
        pButton->Create("&ENTER", WS\_CHILD | WS\_VISIBLE,
        	            CRect(0, 0, 100, 43), this, 1);
        

        How do I assign a handler for this? I do not even know it's ID here. Little unclear.

        D 1 Reply Last reply
        0
        • D David Crow

          grassrootkit wrote:

          How do I add event handler for dynamically created controls in MFC? For example a button & an onclick event.

          Just like any other button click:

          BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
          //{{AFX_MSG_MAP(CMyDialog)
          ON_BN_CLICKED(IDC_SOME_BUTTON, OnButtonClicked)
          //}}AFX_MSG_MAP
          END_MESSAGE_MAP()

          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

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

          Will that be enough, or is another shoe to drop?

          D 1 Reply Last reply
          0
          • G grassrootkit

            Can't follow you. I'm creating the control like:

            CButton\* pButton = new CButton;
            pButton->Create("&ENTER", WS\_CHILD | WS\_VISIBLE,
            	            CRect(0, 0, 100, 43), this, 1);
            

            How do I assign a handler for this? I do not even know it's ID here. Little unclear.

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            grassrootkit wrote:

            I do not even know it's ID here.

            Have you bothered to read the documentation? The fifth argument is the ID.

            "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            G 1 Reply Last reply
            0
            • L led mike

              Will that be enough, or is another shoe to drop?

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              :confused: I'm missing the punch line, Mike.

              "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              L 1 Reply Last reply
              0
              • G grassrootkit

                How do I add event handler for dynamically created controls in MFC? For example a button & an onclick event.

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

                You need to define a hard-coded range of IDs for your dynamically created controls. for example, you can decide that the range #define IDC_DYNAMIC_CONTROL_RANGE_START 1300 #define IDC_DYNAMIC_CONTROL_RANGE_START 2000 And when you create a new control, you assign the first free ID in the range; that means you will have a limit on how many controls you will be able to support.

                This signature was proudly tested on animals.

                1 Reply Last reply
                0
                • D David Crow

                  :confused: I'm missing the punch line, Mike.

                  "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

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

                  Not really one. I was predicting this[^] it hadn't shown up before I posted mine. Looking at the times it no longer reflects the predictive nature of my post. :laugh: :laugh:

                  1 Reply Last reply
                  0
                  • D David Crow

                    grassrootkit wrote:

                    I do not even know it's ID here.

                    Have you bothered to read the documentation? The fifth argument is the ID.

                    "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    G Offline
                    G Offline
                    grassrootkit
                    wrote on last edited by
                    #9

                    DavidCrow wrote:

                    Have you bothered to read the documentation? The fifth argument is the ID.

                    :doh: . Please excuse. That's dumb. Thanks for the reply.

                    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