What’s the right way to connect a slider to a member variable in MFC? What I’ve done so far:
- Dragged a slider in to my dialog in the resource view and given it an ID
- Right clicked on the slider and chosen Add Variable
- Set the variable to Control variable and the Category to Value and also set the Min value and Max value to desired values.
This creates a member variable of type int in my dialog class and also adds some stuff to the DoDataExchange method.
However, the DoDataExchange method is only called once when my dialog is created, what do I have to do to make my member variable update when I drag the slider? Should I have set the Category to Ctrl instead and manually managed the range, and intercepted the WM_HSCROLL messages?
(This is a non modal dialog by the way)
Call UpdateData to do the DataExchange passing TRUE to save and validate the data to your variable and FALSE to set the control value based on your variable, ie. passing data into the control. More information about UpdateData:
http://msdn.microsoft.com/en-us/library/t9fb9hww(v=vs.80).aspx
and for general data exchange mechanism:
http://msdn.microsoft.com/en-us/library/xwz5tb1x(v=vs.80).aspx