0

I have four CSpinButtonCtrl objects on my dialog.

They are all configured as:

  • Auto Buddy
  • Buddy Integer

The respective CEdit objects map to int variables and the maximum range is set to 0-20. Now I need the spin controls to match.


I know that I can map the spin controls to CSpinButtonCtrl variables and them use SetRange but I was hoping to avoid the need to create the variables. Some controls come with macro counterparts that take the HWND. Can a simple macro counterpart be created here so that I can set all the ranges to 0-20?

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • 2
    The final paragraph reads like you have something like the [`ON_CONTROL_RANGE`](https://learn.microsoft.com/en-us/cpp/mfc/reference/message-map-macros-mfc#on_control_range) macro in mind. In that case, no. MFC supplies macros to register a callback to multiple control ID's. It doesn't provide a way to *execute* a piece of code against multiple controls. Is that what you're asking for? – IInspectable Mar 22 '23 at 22:41
  • @IInspectable Yeah. I guess the easiest is to use the method to get the control from the ID and cast to spinner. Then run SetRange. That could be a lambda function that I call 4 times in OnInitDialog. – Andrew Truckle Mar 22 '23 at 23:07
  • 1
    Now, you *can* gather the set of controls and [`for_each`](https://en.cppreference.com/w/cpp/algorithm/for_each) over them, applying either a cast, or sending a `UDM_SETRANGE32` message, but honestly, someone's got to read and debug that code, eventually. And if that someone is you, you'll start to appreciate a simple `for`-loop, when all you have is a crash dump, and debug symbols lost to history. – IInspectable Mar 22 '23 at 23:34
  • 1
    @IInspectable Alright. I think it simplest that I map to variables then. – Andrew Truckle Mar 23 '23 at 05:30

0 Answers0