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 handlers?

Dynamic handlers?

Scheduled Pinned Locked Moved C / C++ / MFC
questioncom
2 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.
  • F Offline
    F Offline
    Fredrik Skog
    wrote on last edited by
    #1

    How does one go about to implement handlers for buttons that are created dynamically at runtime? E.g. I want to create a button which should run a program when pressed. The program to run is configured by the user. I was thinking of storing the program name within the button object. Then I could use one handler for all of the buttons, but how do I know which button it was that called the handler (in order to retrieve the program name)? Cheers,
    /Fredrik

    Do you Sonork? I do! 100.11430:PhatBoy

    T 1 Reply Last reply
    0
    • F Fredrik Skog

      How does one go about to implement handlers for buttons that are created dynamically at runtime? E.g. I want to create a button which should run a program when pressed. The program to run is configured by the user. I was thinking of storing the program name within the button object. Then I could use one handler for all of the buttons, but how do I know which button it was that called the handler (in order to retrieve the program name)? Cheers,
      /Fredrik

      Do you Sonork? I do! 100.11430:PhatBoy

      T Offline
      T Offline
      Thomas Ascher
      wrote on last edited by
      #2

      You can use ON_COMMAND_RANGE to handle a range of commands: class CMyDialog : public CDialog { afx_msg void OnHandleCommands(UINT nID); DECLARE_MESSAGE_MAP() }; BEGIN_MESSAGE_MAP(CMyDialog, CDialog) ON_COMMAND_RANGE(ID_COMMAND_FIRST, ID_COMMAND_LAST, OnHandleCommands) END_MESSAGE_MAP() void CMyDialog::OnHandleCommands(UINT nID) { // nID contains the ID of the command to handle }

      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