MessageWindow Class
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Provides the ability to send and receive Windows-based messages.
Namespace: Microsoft.WindowsCE.Forms
Assembly: Microsoft.WindowsCE.Forms (in Microsoft.WindowsCE.Forms.dll)
Syntax
'Declaration
Public Class MessageWindow _
Implements IDisposable
'Usage
Dim instance As MessageWindow
public class MessageWindow : IDisposable
public ref class MessageWindow : IDisposable
type MessageWindow =
class
interface IDisposable
end
Remarks
The MessageWindow class provides the ability to send and receive Windows-based messages. It creates a window handle in native code and performs the required platform invoke calls to native Windows functions.
To use the MessageWindow in your program you need to create a class derived from MessageWindow and override the default WndProc behavior to watch for specific Window messages. You can generate messages with the Message class. You can receive only the Windows-based messages that you generate using MessageWindow or those with a native control.
To use this class, you must add a reference in your Visual Studio 2005 project to the Microsoft.WindowsCE.Forms namespace.
Topic | Location |
---|---|
How to: Use the MessageWindow Class | .NET Compact Framework |
How to: Use the MessageWindow Class | .NET Compact Framework |
How to: Use the MessageWindow Class | .NET Compact Framework |
How to: Use the MessageWindow Class | .NET Compact Framework |
Examples
The following code example demonstrates MessageWindow by having the form send Windows-based messages of current mouse x-y coordinates to the message window, which invokes the callback method on the form to display the coordinates in the title bar.
The form contains a custom class, MsgWindow, derived from MessageWindow. The MsgWindow class examines messages in the overridden WndProc method, looking for messages with a WM_CUSTOMMSG identifier. When it finds these messages, it invokes the RespondToMessage callback method defined in the form.
The form creates a new instance of MsgWindow. The MsgWindow constructor takes a form, which in this example is the containing form. The form generates Windows-based messages in an override of the OnMouseMove method.
When the form runs, mouse movements generate messages to the message window. The message window WndProc method invokes the callback method on the form, which responds to the messages.
Note that you must add a reference to Microsoft.WindowsCE.Forms to your project.
Imports System
Imports System.Windows.Forms
Imports Microsoft.WindowsCE.Forms
Public Class MessageWindowForm
Inherits System.Windows.Forms.Form
Private mainMenu1 As System.Windows.Forms.MainMenu
' Create an instance of MsgWindow, a derived MessageWindow class.
Private MsgWin As MsgWindow
Public Sub New()
InitializeComponent()
' Create the message window using this form for its constructor.
Me.MsgWin = New MsgWindow(Me)
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
#Region "Windows Form Designer generated code"
Private Sub InitializeComponent()
Me.mainMenu1 = New System.Windows.Forms.MainMenu
'
' MessageWindowForm
'
Me.Menu = Me.mainMenu1
Me.Text = "Message Window Test"
End Sub
#End Region
Shared Sub Main()
Application.Run(New MessageWindowForm)
End Sub
' Process taps to generate messages
' with the WParam and LParam parameters
' using the X and Y mouse coordinates.
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
Dim msg As Microsoft.WindowsCE.Forms.Message = _
Microsoft.WindowsCE.Forms.Message.Create(MsgWin.Hwnd, _
MsgWindow.WM_CUSTOMMSG, New IntPtr(e.X), New IntPtr(e.Y))
MessageWindow.SendMessage(msg)
MyBase.OnMouseMove(e)
End Sub
' This callback method responds to the Windows-based message.
Public Sub RespondToMessage(ByVal x As Integer, ByVal y As Integer)
Me.Text = "X = " + x.ToString() + ", Y= " + y.ToString()
End Sub
End Class
' Derive MessageWindow to respond to
' Windows messages and to notify the
' form when they are received.
Public Class MsgWindow
Inherits MessageWindow
' Assign integers to messages.
' Note that custom Window messages start at WM_USER = 0x400.
Public Const WM_CUSTOMMSG As Integer = &H400
' Create an instance of the form.
Private msgform As MessageWindowForm
' Save a reference to the form so it can
' be notified when messages are received.
Public Sub New(ByVal msgform As MessageWindowForm)
Me.msgform = msgform
End Sub
' Override the default WndProc behavior to examine messages.
Protected Overrides Sub WndProc(ByRef msg As Microsoft.WindowsCE.Forms.Message)
Select Case 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
Me.msgform.RespondToMessage(Fix(msg.WParam.ToInt32), Fix(msg.LParam.ToInt32))
End Select
' Call the base class WndProc method
' to process any messages not handled.
MyBase.WndProc(msg)
End Sub
End Class
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);
}
}
}
Inheritance Hierarchy
System.Object
Microsoft.WindowsCE.Forms.MessageWindow
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms
Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information
.NET Compact Framework
Supported in: 3.5, 2.0, 1.0