在MFC中如何为滚动条添加消息事件处理程序:onvscroll

在MFC中如何为滚动条添加消息事件处理程序:onvscroll,第1张

滚动条控件的滚动事件是由其父对话框响应

所以,直接响应对话框的WM_VSCROLL和WM_HSCROLL消息就可以了

若对话框中有多个滚动条,则可以用WM_VSCROLL和WM_HSCROLL消息响应函数中的参数CScrollBar*

pScrollBar来进行判断

测试了一下,可以使用自定义事件。

    public partial class Form1 : Form

    {

        //定义事件

        public event EventHandler HScrollEvent

        public event EventHandler VScrollEvent

        public Form1()

        {

            InitializeComponent()

            //注册事件

            this.VScrollEvent += delegate

            {

                { this.Text = "纵向滚动了!" }

            }

        }

        protected override void WndProc(ref Message m)

        {

            //在输出窗口自己看对应的数字是多少

            Debug.Print(m.Msg.ToString())

            switch (m.Msg.ToString())

            {

                case "528"://我测试对应垂直滚动

                    //引发事件

                    if (this.VScrollEvent != null)

                        this.VScrollEvent(this, null)

                    break

                case "你自己检测数字":

                    if (this.HScrollEvent != null)

                        this.HScrollEvent(this, null)

                    break

                default:

                    break

            }

            base.WndProc(ref m)

        }

        private void button1_Click(object sender, EventArgs e)

        {

            this.Text = ""//清空便于对比

        }

    }


欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/bake/11947366.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存