MessageWindowとは? わかりやすく解説

MessageWindow クラス

Windows ベースのメッセージを送受信できるようにします。

名前空間: Microsoft.WindowsCE.Forms
アセンブリ: Microsoft.WindowsCE.Forms (microsoft.windowsce.forms.dll 内)
構文構文

Public Class MessageWindow
    Implements IDisposable
Dim instance As MessageWindow
public class MessageWindow : IDisposable
public ref class MessageWindow : IDisposable
public class MessageWindow implements IDisposable
public class MessageWindow implements IDisposable
解説解説
使用例使用例

フォームから現在のマウスの x 座標と y 座標の Windows ベースのメッセージをメッセージ ウィンドウに送信させ、コールバック メソッドを呼び出し、タイトル バーに座標を表示する MessageWindow のコード例を次に示します。

フォームには、MessageWindow から派生したカスタム クラス MsgWindow が格納されています。MsgWindow クラスは、WM_CUSTOMMSG 識別子を含むメッセージを検索して、オーバーライドされた WndProc メソッドのメッセージを検査します。これらのメッセージを見つけると、フォームで定義された RespondToMessage コールバック メソッドを呼び出します。

フォームは、MsgWindow の新しいインスタンスを作成します。MsgWindow コンストラクタはフォームを受け取ります。この例では、格納しているフォームです。フォームは、OnMouseMove メソッドのオーバーライドで Windows ベースのメッセージを生成します。

フォームの実行時にマウスを移動すると、メッセージ ウィンドウにメッセージが生成されます。メッセージ ウィンドウの WndProc メソッドがフォームのコールバック メソッドを呼び出し、コールバック メソッドがメッセージに応答します。

Microsoft.WindowsCE.Forms への参照をプロジェクトに追加する必要があることに注意してください。

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);
  }
 }
}
継承階層継承階層
System.Object
  Microsoft.WindowsCE.Forms.MessageWindow
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
MessageWindow メンバ
Microsoft.WindowsCE.Forms 名前空間

MessageWindow コンストラクタ

MessageWindow クラスの新しいインスタンスを作成します。

名前空間: Microsoft.WindowsCE.Forms
アセンブリ: Microsoft.WindowsCE.Forms (microsoft.windowsce.forms.dll 内)
構文構文

public MessageWindow ()
public:
MessageWindow ()
public MessageWindow ()
public function MessageWindow ()
解説解説
.NET Framework のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
MessageWindow クラス
MessageWindow メンバ
Microsoft.WindowsCE.Forms 名前空間

MessageWindow プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Text MessageWindow のテキストを取得または設定します。
参照参照

関連項目

MessageWindow クラス
Microsoft.WindowsCE.Forms 名前空間

MessageWindow メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

MessageWindow クラス
Microsoft.WindowsCE.Forms 名前空間

MessageWindow メンバ

Windows ベースのメッセージを送受信できるようにします。

MessageWindow データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド MessageWindow MessageWindow クラスの新しいインスタンスを作成します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Text MessageWindow のテキストを取得または設定します。
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

MessageWindow クラス
Microsoft.WindowsCE.Forms 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「MessageWindow」の関連用語

MessageWindowのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



MessageWindowのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS