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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Adding event to controls at runtime

Adding event to controls at runtime

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

    hi, As i created 5 buttons at runtime (getting values from user). Simultaneously i want to add event to those button which i created at runtime. how & where could i add the button cliked event in our code . reply early:) send reply

    N _ H 3 Replies Last reply
    0
    • M maharaja pandian

      hi, As i created 5 buttons at runtime (getting values from user). Simultaneously i want to add event to those button which i created at runtime. how & where could i add the button cliked event in our code . reply early:) send reply

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      You can override OnCommand for this purpose. Look up MSDN for more help.


      Nibu thomas Software Developer

      1 Reply Last reply
      0
      • M maharaja pandian

        hi, As i created 5 buttons at runtime (getting values from user). Simultaneously i want to add event to those button which i created at runtime. how & where could i add the button cliked event in our code . reply early:) send reply

        _ Offline
        _ Offline
        _AnsHUMAN_
        wrote on last edited by
        #3

        Check the id of the button that was clicked in the OnCommand function and perform the tasks required over there . Vision is Always important and so is your ATTITUDE. Wishes. Anshuman Dandekar

        M 1 Reply Last reply
        0
        • M maharaja pandian

          hi, As i created 5 buttons at runtime (getting values from user). Simultaneously i want to add event to those button which i created at runtime. how & where could i add the button cliked event in our code . reply early:) send reply

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          Hi maharaja pandian, ////In file h/////////////// CButton m_Button3; afx_msg void OnBnClickedButton3(); ////////In file Cpp///////////// #define IDC_BUTTON3 12000 ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton3) ///////In you function//////////////// m_Button3.Create("Butotn3",WS_CHILD|WS_VISIBLE|BS_NOTIFY,CRect(0,0,20,20),this,IDC_BUTTON3); void CssDlg::OnBnClickedButton3() { MessageBox("button3"); }

          M 1 Reply Last reply
          0
          • _ _AnsHUMAN_

            Check the id of the button that was clicked in the OnCommand function and perform the tasks required over there . Vision is Always important and so is your ATTITUDE. Wishes. Anshuman Dandekar

            M Offline
            M Offline
            maharaja pandian
            wrote on last edited by
            #5

            thanks , i got it from ur reply... send reply

            1 Reply Last reply
            0
            • H Hamid Taebi

              Hi maharaja pandian, ////In file h/////////////// CButton m_Button3; afx_msg void OnBnClickedButton3(); ////////In file Cpp///////////// #define IDC_BUTTON3 12000 ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton3) ///////In you function//////////////// m_Button3.Create("Butotn3",WS_CHILD|WS_VISIBLE|BS_NOTIFY,CRect(0,0,20,20),this,IDC_BUTTON3); void CssDlg::OnBnClickedButton3() { MessageBox("button3"); }

              M Offline
              M Offline
              maharaja pandian
              wrote on last edited by
              #6

              thanks for ur reply, but during the runtime only i know ,how many buttons are requried. i created like CButton bt[]=new CButton (noofval); bt[0].create(....); bt[1].create(....); . . . like that i created, but i want to add cliked event to that each button:) send reply

              H 1 Reply Last reply
              0
              • M maharaja pandian

                thanks for ur reply, but during the runtime only i know ,how many buttons are requried. i created like CButton bt[]=new CButton (noofval); bt[0].create(....); bt[1].create(....); . . . like that i created, but i want to add cliked event to that each button:) send reply

                H Offline
                H Offline
                Hamid Taebi
                wrote on last edited by
                #7

                You can use Oncommand in your project but if you know about buttons you can use this code (example you created 10 buttons dynamic) then you can use this way.I use this way and this is safe and I think it's easy

                M 1 Reply Last reply
                0
                • H Hamid Taebi

                  You can use Oncommand in your project but if you know about buttons you can use this code (example you created 10 buttons dynamic) then you can use this way.I use this way and this is safe and I think it's easy

                  M Offline
                  M Offline
                  maharaja pandian
                  wrote on last edited by
                  #8

                  thanks , i got it from ur reply... send 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