How to: Use the MessageWindow Class

The .NET Compact Framework provides the MessageWindow and Message classes to generate and receive Windows-based messages. The MessageWindow class creates a window in native code with a handle to your form and performs the required platform invoke calls to native Windows functions. The MessageWindow class is available only in the .NET Compact Framework.

Use the Window handle to the message window, Hwnd, for sending Windows messages to the message window. You can generate messages by using Create in managed code, or by using a native control in your application. You can receive only the messages that you generate. You cannot use MessageWindow to monitor operating system messages.

The message window notifies a form, using the WndProc method, when it detects specific messages enabling you to provide code in response to a Windows-based message.

Note

Note that the .NET Compact Framework version 2.0 provides the ability to marshal delegates as Function Pointers, and directly call managed functions from native code, as an alternative to MessageWindow. See Interoperability in the .NET Compact Framework for more information.

Example

This example demonstrates the functionality of a MessageWindow but without a native component. It sends Windows messages, containing the current pointer x and y coordinates, to a form when the mouse pointer is within a Rectangle in custom control or in a Panel control. The custom control appears as a box on the form. Both controls use the OnMouseMove method for sending messages. These messages contain the x-coordinate and the y-coordinate. The form responds to user defined WM_BOXUPDATE and WM_PNLUPDATE messages by updating a label with the current x-coordinate and y-coordinate and the control that sent the message.

When the mouse is outside the box and panel, the OnMouseMove method of the form updates the label with x-coordinate and y-coordinate in the context of the form.