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 controls and attaching listeners to them?

dynamically create controls and attaching listeners to them?

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionhelp
3 Posts 2 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
    misterbear
    wrote on last edited by
    #1

    Hello, I don't know if this is super-easy to accomplish, I am pretty new to VC++/MFC.. I need to create a dialog which must contain a different number of CButton controls depending on certain state parameters of the application. So I need to dynamically create a number of those controls and attach a message handler for them ( they all share the same message handler code ). How do I attach this listener function to the controls once I've created them? (I destroy all buttons and create a bunch of new ones when the layout changes) thankful for any help.

    K 1 Reply Last reply
    0
    • M misterbear

      Hello, I don't know if this is super-easy to accomplish, I am pretty new to VC++/MFC.. I need to create a dialog which must contain a different number of CButton controls depending on certain state parameters of the application. So I need to dynamically create a number of those controls and attach a message handler for them ( they all share the same message handler code ). How do I attach this listener function to the controls once I've created them? (I destroy all buttons and create a bunch of new ones when the layout changes) thankful for any help.

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      Why dont you enable/disable or show/hide the controls at runtime, it is also better by UI Design-Guidelines. -> Make a full dialog with all resources in the resource editor, assign control objects to all controls and work with mycontrol.EnableWindow( bActiveNow ):cool: Try this @ home. (B&B)

      M 1 Reply Last reply
      0
      • K KarstenK

        Why dont you enable/disable or show/hide the controls at runtime, it is also better by UI Design-Guidelines. -> Make a full dialog with all resources in the resource editor, assign control objects to all controls and work with mycontrol.EnableWindow( bActiveNow ):cool: Try this @ home. (B&B)

        M Offline
        M Offline
        misterbear
        wrote on last edited by
        #3

        I've thought of that as well. But I really don't have a clue as of what the maximum number of controls is. I could of course create a ridiculously large amount of CButton objects to be on the safe side, and just hide/show those. But it sounds a bit unneccessary to me... And I'm still very much interested in attaching a message handler dynamically. Can I for example create a hook and install it for every new item? And in that hook listen for the BN_CLICKED event and if one is received obtain the text for the control and pass it further on? If so, how is a hook procedure attached?

        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