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 Event handler to dynamically created Button

How to add Event handler to dynamically created Button

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

    Hi, I have created Button on my Dialog Box using following code.

    CButton *m_myButton;
    m_myButton = new CButton();
    m_myButton->Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
    CRect(800,y1,900,(y1+25)),this, 1);

    How should I add Event handler to this button.

    _ F H 3 Replies Last reply
    0
    • H hemlat

      Hi, I have created Button on my Dialog Box using following code.

      CButton *m_myButton;
      m_myButton = new CButton();
      m_myButton->Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
      CRect(800,y1,900,(y1+25)),this, 1);

      How should I add Event handler to this button.

      F Offline
      F Offline
      fitatc
      wrote on last edited by
      #2

      I think you can use CMyButton instead of CButton:

      class CMyButton: public CButton{
      };

      you can add Event handler(massage handler) to this class.

      H 1 Reply Last reply
      0
      • H hemlat

        Hi, I have created Button on my Dialog Box using following code.

        CButton *m_myButton;
        m_myButton = new CButton();
        m_myButton->Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
        CRect(800,y1,900,(y1+25)),this, 1);

        How should I add Event handler to this button.

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

        one easy way is to create a button at design time, and double click on it to add the handler to know what all is needed.. Otherwise also, it is not a mammoth task. You have to declare a function, define it and add an entry for the button click to the message map. Also you may be interested ON_CONTROL_RANGE

        You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

        modified on Tuesday, April 14, 2009 4:02 AM

        H 1 Reply Last reply
        0
        • _ _AnsHUMAN_

          one easy way is to create a button at design time, and double click on it to add the handler to know what all is needed.. Otherwise also, it is not a mammoth task. You have to declare a function, define it and add an entry for the button click to the message map. Also you may be interested ON_CONTROL_RANGE

          You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

          modified on Tuesday, April 14, 2009 4:02 AM

          H Offline
          H Offline
          hemlat
          wrote on last edited by
          #4

          thanks for your reply.I have declared one function.I have added entry in message map. It is working for me.

          1 Reply Last reply
          0
          • F fitatc

            I think you can use CMyButton instead of CButton:

            class CMyButton: public CButton{
            };

            you can add Event handler(massage handler) to this class.

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

            Do I need to insert a class for an event?no.

            Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

            1 Reply Last reply
            0
            • H hemlat

              Hi, I have created Button on my Dialog Box using following code.

              CButton *m_myButton;
              m_myButton = new CButton();
              m_myButton->Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
              CRect(800,y1,900,(y1+25)),this, 1);

              How should I add Event handler to this button.

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

              You can insert this code on your code and then if you want you can make your button. #define IDC_DYNAMICBUTTON 3000 BEGIN_MESSAGE_MAP(CMFCDlg, CDialog) ON_BN_CLICKED(IDC_DYNAMICBUTTON,&CMFCDlg::OnBnClickedbutton) END_MESSAGE_MAP() void CMFCDlg::OnBnClickedbutton() { } //header file public: afx_msg void OnBnClickedbutton();

              Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

              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