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. Multiple dynamically created Spin Button Controls

Multiple dynamically created Spin Button Controls

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestioncsharpc++
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.
  • G Offline
    G Offline
    gokings
    wrote on last edited by
    #1

    Hello, ENVIRONMENT: MFC I seek help regarding the dynamic creation and use of Spin Button Controls. Every example/tutorial I've found provides a lot of information, all of which I already know. They all state the obvious, and avoid addressing the only non-obvious (at least to me) aspect. When dealing with a statically created (or a single dynamically created) control, "up" and "down" messages are generally handled by a method of the spin button's parent window, having a prototype such as:

    void Dlg::OnDeltaposSpinFoo(NMHDR* pNMHDR, LRESULT* pResult)
    {
    }

    The NMHDR* parm can be type cast to an NMUPDOWN*, which provides data specific to a Spin Button Control. The message map for the parent window contains an entry such as:

    ON\_NOTIFY(UDN\_DELTAPOS, IDC\_SPIN\_ADJUST\_FOO, OnDeltaposSpinFoo)
    

    In such a case, it's obvious which spin control has been clicked, since the method is invoked for only a single control. Suppose I want a range of ID's to be associated with OnDeltaposSpinFoo()? Say I dynamically create a number of spin controls on a window, for which I wish to use a single message handler. For some controls, such as buttons, there are "range" macros that may be placed in the message map. How about for a spin button control? If I could manage to have OnDeltaposSpinFoo() called for a range of ID's, I could identify the control by the idFrom member of the NMHDR parm (see structures below). I'd probably subtract a base value from the idFrom value to obtain an index to be used programmatically). [

    The relevant structures are:

    typedef struct tagNMHDR {
    HWND hwndFrom;
    UINT_PTR idFrom;
    UINT code;
    } NMHDR;

    typedef struct _NM_UPDOWN {
    NMHDR hdr;
    int iPos;
    int iDelta;
    } NMUPDOWN, *LPNMUPDOWN;

    ] The bottom-line questions are: 1) How can I place an entry in the message map that will cause a "spin button prototype" function to be called (with an NMUPDOWN*) for a range of control ID's? 2) If that's not possible, how else can I handle the problem? I'd appreciate suggestions. Even more, I'd appreciate a working example project that will build and run using Visual Studio 2008 (I don't expect anyone to spend a lot of time creating one, but if you have one, or can quickly create one from something you have....).

    L 1 Reply Last reply
    0
    • G gokings

      Hello, ENVIRONMENT: MFC I seek help regarding the dynamic creation and use of Spin Button Controls. Every example/tutorial I've found provides a lot of information, all of which I already know. They all state the obvious, and avoid addressing the only non-obvious (at least to me) aspect. When dealing with a statically created (or a single dynamically created) control, "up" and "down" messages are generally handled by a method of the spin button's parent window, having a prototype such as:

      void Dlg::OnDeltaposSpinFoo(NMHDR* pNMHDR, LRESULT* pResult)
      {
      }

      The NMHDR* parm can be type cast to an NMUPDOWN*, which provides data specific to a Spin Button Control. The message map for the parent window contains an entry such as:

      ON\_NOTIFY(UDN\_DELTAPOS, IDC\_SPIN\_ADJUST\_FOO, OnDeltaposSpinFoo)
      

      In such a case, it's obvious which spin control has been clicked, since the method is invoked for only a single control. Suppose I want a range of ID's to be associated with OnDeltaposSpinFoo()? Say I dynamically create a number of spin controls on a window, for which I wish to use a single message handler. For some controls, such as buttons, there are "range" macros that may be placed in the message map. How about for a spin button control? If I could manage to have OnDeltaposSpinFoo() called for a range of ID's, I could identify the control by the idFrom member of the NMHDR parm (see structures below). I'd probably subtract a base value from the idFrom value to obtain an index to be used programmatically). [

      The relevant structures are:

      typedef struct tagNMHDR {
      HWND hwndFrom;
      UINT_PTR idFrom;
      UINT code;
      } NMHDR;

      typedef struct _NM_UPDOWN {
      NMHDR hdr;
      int iPos;
      int iDelta;
      } NMUPDOWN, *LPNMUPDOWN;

      ] The bottom-line questions are: 1) How can I place an entry in the message map that will cause a "spin button prototype" function to be called (with an NMUPDOWN*) for a range of control ID's? 2) If that's not possible, how else can I handle the problem? I'd appreciate suggestions. Even more, I'd appreciate a working example project that will build and run using Visual Studio 2008 (I don't expect anyone to spend a lot of time creating one, but if you have one, or can quickly create one from something you have....).

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The hwndFrom and idFrom parameters in the notification structure tell you which control is sending the message. Use the ON_NOTIFY_RANGE macro, as described in http://msdn.microsoft.com/en-us/library/749htf6k(v=vs.110).aspx[^].

      Veni, vidi, abiit domum

      G 1 Reply Last reply
      0
      • L Lost User

        The hwndFrom and idFrom parameters in the notification structure tell you which control is sending the message. Use the ON_NOTIFY_RANGE macro, as described in http://msdn.microsoft.com/en-us/library/749htf6k(v=vs.110).aspx[^].

        Veni, vidi, abiit domum

        G Offline
        G Offline
        gokings
        wrote on last edited by
        #3

        Thank you for your feedback. The range macros of which I was aware were: ON_COMMAND_RANGE, and ON_CONTROL_RANGE, neither of which matched the function prototype I normally use for a spin button control. The ON_NOTIFY_RANGE worked great. However, I did have to add an ID parameter to the message handling function. [The first parameter, in case anyone is interested.] Due to the additional parameter, one need not use the mentioned structure members to identify the control.

        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