如何创建滑块控件 [英] How to create a slider control

查看:105
本文介绍了如何创建滑块控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个亮度控制滑块.

将其ID更改为IDC_H_SLIDER_BAR
b.水平方向
c.控制类别
d.m_HSliderBar的变量名称 e.将变量类型更改为CSliderCtrl
f.在主属性中选择消息"按钮,向下滚动到WM_VSCROLL并单击"ADD OnVScroll"

接下来,我该怎么做,请回复.

I have made a control slider for brightness.

a.Change its ID to IDC_H_SLIDER_BAR
b.Orientation to Horizontal
c.Category to Control
d.Variable Name to m_HSliderBar
e.Variable Type to CSliderCtrl
f.Select the Messages button in main properties,Scroll down to WM_VSCROLL and click on "ADD OnVScroll"

What should I do next, please reply.

推荐答案

为滑块添加int类型的变量,以轻松访问其值.

在对话框标题中
Add a variable of type int for your slider to get easy access to its value.

in header for you dialog
public:
    int GetBrightness() const { return m_sliderValue; }
    void SetBrightness(int brightness) { m_sliderValue = brightness; }
protected:
    int m_sliderValue; // Value added for control



对于简单的任务,您不需要事件处理程序.

请注意,您会得到类似
的信息



For simple tasks you don''t need an event handler.

Notice that you will get something like

DDX_Slider(pDX, IDC_H_SLIDER_BAR, m_sliderValue);



在您的DoDataExchange函数中.它将负责将控件值转移到您的成员变量.

有关更多信息,请查看SDK中的UpdateData().

如果您打算预览亮度值,则只需要一个事件处理程序即可.

另外,您还想通过OnInitDialog()方法设置滑块的范围.



in your DoDataExchange function. It will take care of transferring the controls value to your member variable.

For more reading you can check out UpdateData() in the SDK.

You will only need an event handler if you plan on having a preview of your brightness value.

Also, you want to set the range for your slider from your OnInitDialog() method.

m_HSliderBar.SetRange(0, 100);


这篇关于如何创建滑块控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆