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