捕获特定按钮单击的WndProc消息 [英] Capturing WndProc message of a certain button click

查看:177
本文介绍了捕获特定按钮单击的WndProc消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单上有一个取消按钮。我想确定在 WndProc 方法中单击此取消按钮并为其编写一些代码。这是绝对必要的,因为否则我将无法取消所有其他尚未执行的控件验证事件。

I have a cancel button on my form. I want to determine inside the WndProc method that this Cancel button is clicked and write some code for it. This is absolutely necessary because otherwise I'm not able to cancel all other control validation events that are yet to be performed.

请帮助。

.NET-2.0,WinForms

.NET - 2.0, WinForms

推荐答案

这是解析WndProc消息的方式左键单击子控件:

This is how you could parse the WndProc message for a left-click on a child control:

protected override void WndProc(ref Message m)
{
    // http://msdn.microsoft.com/en-us/library/windows/desktop/hh454920(v=vs.85).aspx
    // 0x210 is WM_PARENTNOTIFY
    // 513 is WM_LBUTTONCLICK
    if (m.Msg == 0x210 && m.WParam.ToInt32() == 513) 
    {
        var x = (int)(m.LParam.ToInt32() & 0xFFFF);
        var y = (int)(m.LParam.ToInt32() >> 16);

        var childControl = this.GetChildAtPoint(new Point(x, y));
        if (childControl == cancelButton)
        {
            // ...
        }
    }
    base.WndProc(ref m);
}

BTW:这是32位代码。

BTW: this is 32-bit code.

这篇关于捕获特定按钮单击的WndProc消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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