码迷,mamicode.com
首页 > Windows程序 > 详细

windows 消息

时间:2019-08-16 22:33:29      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:click   override   style   ide   ali   cat   测试   dem   partial   

 

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private Demo demo = null;
        private void Form1_Load(object sender, EventArgs e)
        {
            demo = new Demo(this.Handle.ToInt32());
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //demo = new Demo(this.Handle.ToInt32());
            //demo.Test();
        }

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == Demo.MY_MSG_BEGIN)
            {
                MessageBox.Show("类Demo for循环开始.");
            }
            else if (m.Msg == Demo.MY_MSG_END)
            {
                MessageBox.Show("类Demo for循环结束.");
            }
            Console.WriteLine(new Random().Next());//测试什么时候执行WndProc方法
            base.WndProc(ref m);
        }
    }

    public class Demo
    {
        private int m_hWnd = 0;

        public Demo(int hWnd)
        {
            m_hWnd = hWnd;
        }

        private const int WM_USER = 0x0400;
        public static int MY_MSG_BEGIN = WM_USER + 100;
        public static int MY_MSG_END = WM_USER + 101;

        [DllImport("User32.DLL")]
        public static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);

        public void Test()
        {
            SendMessage(m_hWnd, MY_MSG_BEGIN, 0, 0);
            for (int i = 0; i < 100000; i++)
            {
                Application.DoEvents();
            }
            SendMessage(m_hWnd, MY_MSG_END, 0, 0);
        }
    }
}

 

windows 消息

标签:click   override   style   ide   ali   cat   测试   dem   partial   

原文地址:https://www.cnblogs.com/buchizaodian/p/11366402.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!