MessageWindow 类
来源:互联网 发布:gz.java.tedu.cn v 编辑:程序博客网 时间:2024/06/04 18:14
下面的代码示例演示 MessageWindow。此示例让窗体将有关当前鼠标位置的 x-y 坐标的基于 Windows 的消息发送到消息窗口,消息窗口调用窗体上的回调方法在标题栏中显示相应的坐标。
窗体包含一个从 MessageWindow 派生的自定义类 MsgWindow。MsgWindow 类检查重写的 WndProc 方法中的消息,查找带有 WM_CUSTOMMSG 标识符的消息。当 MsgWindow 类找到这些消息后,将调用窗体中定义的 RespondToMessage 回调方法。
窗体创建 MsgWindow 的一个新实例。MsgWindow 构造函数采用一个窗体作为参数,在此示例中将采用它所在的窗体作为参数。窗体在重写的 OnMouseMove 方法中生成基于 Windows 的消息。
当窗体运行时,若移动鼠标则会生成要发送到消息窗口中的消息。消息窗口的 WndProc 方法调用窗体上的回调方法来响应这些消息。
注意,必须在您的项目中添加对 Microsoft.WindowsCE.Forms 的引用。
using System;
using System.Windows.Forms;
using Microsoft.WindowsCE.Forms;
namespace MsgWindow
{
public class MessageWindowForm : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
// Create an instance of MsgWindow, a derived MessageWindow class.
MsgWindow MsgWin;
public MessageWindowForm()
{
InitializeComponent();
// Create the message window using this form for its constructor.
this.MsgWin = new MsgWindow(this);
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.Menu = this.mainMenu1;
this.Text = "Message Window Test";
}
#endregion
static void Main()
{
Application.Run(new MessageWindowForm());
}
// Process taps to generate messages
// with the WParam and LParam parameters
// using the X and Y mouse coordinates.
protected override void OnMouseMove(MouseEventArgs e)
{
Message msg = Message.Create(MsgWin.Hwnd,
MsgWindow.WM_CUSTOMMSG,
(IntPtr)e.X,
(IntPtr)e.Y);
MessageWindow.SendMessage(ref msg);
base.OnMouseMove(e);
}
// This callback method responds to the Windows-based message.
public void RespondToMessage(int x, int y)
{
this.Text = "X = " + x.ToString() + ", Y= " + y.ToString();
}
}
// Derive MessageWindow to respond to
// Windows messages and to notify the
// form when they are received.
public class MsgWindow : MessageWindow
{
// Assign integers to messages.
// Note that custom Window messages start at WM_USER = 0x400.
public const int WM_CUSTOMMSG = 0x0400;
// Create an instance of the form.
private MessageWindowForm msgform;
// Save a reference to the form so it can
// be notified when messages are received.
public MsgWindow(MessageWindowForm msgform)
{
this.msgform = msgform;
}
// Override the default WndProc behavior to examine messages.
protected override void WndProc(ref Message msg)
{
switch(msg.Msg)
{
// If message is of interest, invoke the method on the form that
// functions as a callback to perform actions in response to the message.
case WM_CUSTOMMSG:
this.msgform.RespondToMessage((int)msg.WParam, (int)msg.LParam);
break;
}
// Call the base WndProc method
// to process any messages not handled.
base.WndProc(ref msg);
}
}
}
- MessageWindow 类
- MessageWindow类
- 使用 Microsoft .NET Framework 精简版中的 MessageWindow 类
- 使用 MessageWindow 类来响应Windows的消息
- [Windows Mobile]C#如何:使用 MessageWindow 类来响应Windows的消息
- Using the Microsoft .NET Compact Framework MessageWindow Class
- 类
- 类
- 类
- 类
- 类
- 类
- 类
- 类
- 类
- 类
- 类
- 类
- 学习 Google Maps API
- PHP中header()函数使用说明
- 游标使用
- Windows HPC Server 2008 技术发布
- 在ArcEngine中创建内存图层[转]
- MessageWindow 类
- 利用Delphi编写Socket通信程序-- 转贴收藏 http://dev.rdxx.com/Delphi/DelphiNET/
- gridview如何改变行显示的内容以及设置单元格的是否允许编辑
- 如何使用WatermarkedTextbox
- 随网页滚动条上下移动的效果 浮动QQ在线客服&网站QQ在线咨询
- C#gridview操作汇总(未整理)
- 日立硬盤型號中各字母的意義
- 微软的 XML 解析
- url转码