• 基于消息驱动的C#Windows程序


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;

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

            const int WM_Lbutton = 0x201; //定义了鼠标的左键点击消息
            const int WM_RBUTTONDOWN = 0x204;//定义鼠标右键
            const int WM_KEYDOWN = 0x100;

            public const int USER = 0x0400;// 是windows系统定义的用户消息

            [DllImport("User32.dll", EntryPoint = "SendMessage")]

            private static extern int SendMessage(

                   int hWnd,   // handle to destination window

                   int Msg,    // message

                   int wParam, // first message parameter

                   int lParam // second message parameter

             );

            protected override void DefWndProc(ref System.Windows.Forms.Message m)
            {
                string message = "";

                switch (m.Msg)
                {
                    case WM_Lbutton:
                        ///string与MFC中的CString的Format函数的使用方法有所不同
                        message = string.Format("收到消息!参数为:{0},{1}", m.WParam, m.LParam);
                        MessageBox.Show(message);///显示一个消息框
                        break;
                    case 0:
                        message = string.Format("收到鼠标点击按钮消息!参数为:{0},{1}", m.WParam, m.LParam);
                        MessageBox.Show(message);
                        break;
                    case WM_RBUTTONDOWN:
                        MessageBox.Show("你按下了鼠标右键!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        break;
                    case WM_KEYDOWN:
                        MessageBox.Show("你按下了键盘!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        break;
                    default:
                        base.DefWndProc(ref m);///调用基类函数处理非自定义消息。
                        break;
                }
            }
            private void button1_Click(object sender, EventArgs e)
            {
                System.Windows.Forms.Message m = new Message();
                m.Msg = 0;
                m.LParam = (IntPtr)10;
                m.WParam = (IntPtr)11;
                SendMessage((int)this.Handle, (int)m.Msg, (int)m.WParam, (int)m.LParam);
            } 
        }
    }

  • 相关阅读:
    iOS-Core-Animation-Advanced-Techniques(一)
    vue 路由
    Vue 生产环境部署
    vue 单文件组件
    vue 插件
    Vue 混合
    vue 自定义指令
    vue render函数 函数组件化
    vue render函数
    vue 过渡状态
  • 原文地址:https://www.cnblogs.com/zhangpengshou/p/1699893.html
Copyright © 2020-2023  润新知