迷你5207专属论坛

注册

 

发新话题 回复该主题

[DotNet] C#消息处理 [复制链接]

发表者
我发现framework对系统底层的东西封装的太严实了,但是如果使用消息处理的话可以提高程序的灵活性,应用的好还可以提高性能,所以使用必要的底层技术还有必要的。 消息处理在以前的开发工具中应用是非常广泛的,下面我就写举了一个简单的处理消息的例子,基本上说明了C#中的消息处理方法:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Runtime.InteropServices;


  9. namespace WinMsg
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         const int WM_Lbutton = 0x201; //定义了鼠标的左键点击消息

  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.         
  19.         [DllImport("User32.dll", EntryPoint = "SendMessage")]
  20.         private static extern int SendMessage(
  21.                      int hWnd,      // handle to destination window
  22.                      int Msg,       // message
  23.                      int wParam,  // first message parameter
  24.                      int lParam // second message parameter
  25.          );

  26.         protected override void DefWndProc(ref Message m)
  27.         {
  28.             
  29.             switch (m.Msg)
  30.             {
  31.                 case WM_Lbutton:
  32.                     MessageBox.Show("点左键");
  33.                     return;
  34.                 default:
  35.                     base.DefWndProc(ref m);
  36.                     return;
  37.             }
  38.         }
  39.     }
  40. }
复制代码
本主题由 管理员 5207 于 2007-12-2 11:15:36 执行 主题分类 操作
分享 转发
相信与不相信都是矛盾的.  5207宣!欢迎您来到点滴论坛
TOP
发新话题 回复该主题