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. dynamically create cbutton

dynamically create cbutton

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
3 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.
  • P Offline
    P Offline
    P e t e r
    wrote on last edited by
    #1

    In my application a variable number of buttons (MFC CButton) are dynamically created. How to dynamically assign callback (OnClick) functions to these buttons? Can someone help me? Best regards, Peter de Hon

    P J 2 Replies Last reply
    0
    • P P e t e r

      In my application a variable number of buttons (MFC CButton) are dynamically created. How to dynamically assign callback (OnClick) functions to these buttons? Can someone help me? Best regards, Peter de Hon

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      P e t e r wrote:

      In my application a variable number of buttons (MFC CButton) are dynamically created.

      There, you must have specified button Id's for those button, use that id and provide function handler in message map.

      #define IDC_BUTTON_1 1 //define id
      //creation code
      button.Create(...,IDC_BUTTON_1);//dynamically created button

      BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
      ON_BN_CLICKED(IDC_BUTTON_1, OnClickButton1)//handler
      END_MESSAGE_MAP()

      Prasad Notifier using ATL | Operator new[],delete[][^]

      1 Reply Last reply
      0
      • P P e t e r

        In my application a variable number of buttons (MFC CButton) are dynamically created. How to dynamically assign callback (OnClick) functions to these buttons? Can someone help me? Best regards, Peter de Hon

        J Offline
        J Offline
        JudyL_MD
        wrote on last edited by
        #3

        Easiest thing to do is just catch all the WM_COMMAND messages with HIWORD (wParam) == BN_CLICKED in your WindowProc and decide which OnClick to call based on the LOWORD (wParam) which will be your button ID. Judy

        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