Share via


方法 : MessageWindow クラスを使用します。

[このドキュメントはプレビュー版であり、後のリリースで変更されることがあります。 空白のトピックは、プレースホルダーとして挿入されています。]

.NET Compact Framework MessageWindow および生成され、Windows ベースのメッセージを受信する Message クラスを示します。 MessageWindow クラス、フォームへのハンドルとネイティブ コードでウィンドウを作成し、必要なプラットフォームを実行するネイティブ Windows 関数の呼び出しを起動します。 MessageWindow クラスは、 .NET Compact Framework でのみ利用可能です。

ウィンドウ ハンドル) Hwnd、メッセージ ウィンドウを使用して、メッセージ ウィンドウに Windows メッセージを送信します。 Create を使用して、マネージ コード、またはネイティブ コントロール、アプリケーションで使用して、、メッセージを生成することができます。 メッセージを生成するだけを受信できます。 MessageWindow を使用してオペレーティング システムのメッセージを監視することはできません。

メッセージ ウィンドウにコードを Windows ベースのメッセージに対する返信で提供できるように、特定のメッセージが検出されたは、WndProc メソッドを使用して、フォームを通知します。

注意

なお、.NET Compact Framework は、関数ポインターとしてのデリゲートのマーシャリングを直接呼び出す機能を提供では、関数をネイティブ コードから MessageWindow 代替として管理されます。詳細については、「.NET Compact Framework の相互運用性」を参照してください。

使用例

次の使用例は機能せず、ネイティブ コンポーネント、MessageWindow を示します。 Windows メッセージを現在のポインターの x 座標を格納および y 座標に送信、フォーム、Rectangle カスタム コントロールまたは Panel コントロール内のマウス ポインターがします。 カスタム コントロールがフォームにあるボックスとして表示されます。 両方のコントロールには、OnMouseMove メソッド メッセージの送信に使用します。 これらのメッセージは x 座標および y 座標を含めます。 フォームは、現在の x 座標と y 座標とメッセージを送信したコントロールで、ラベルを更新してユーザー定義 WM_BOXUPDATEWM_PNLUPDATE メッセージを応答します。

マウスがパネルとボックス外、フォームの OnMouseMove メソッドは、x 座標と y 座標、フォームのコンテキストで、ラベルを更新します。

                        Imports System
Imports System.Windows.Forms
Imports Microsoft.WindowsCE.Forms

PublicClass 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

 PublicSubNew()

  InitializeComponent()

  ' Create the message window using this form for its constructor.Me.MsgWin = New MsgWindow(Me)
 EndSubProtectedOverloadsOverridesSub Dispose(ByVal disposing AsBoolean)
  MyBase.Dispose(disposing)
 EndSub
#Region "Windows Form Designer generated code"PrivateSub InitializeComponent()
  Me.mainMenu1 = New System.Windows.Forms.MainMenu
  '  ' MessageWindowForm  'Me.Menu = Me.mainMenu1
  Me.Text = "Message Window Test"EndSub
#End Region


 SharedSub Main()
   Application.Run(New MessageWindowForm)
 EndSub

 ' Process taps to generate messages ' with the WParam and LParam parameters ' using the X and Y mouse coordinates.ProtectedOverridesSub 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)
 EndSub
 ' This callback method responds to the Windows-based message.PublicSub RespondToMessage(ByVal x AsInteger, ByVal y AsInteger)
  Me.Text = "X = " + x.ToString() + ", Y= " + y.ToString()
 EndSubEndClass
' Derive MessageWindow to respond to' Windows messages and to notify the' form when they are received.PublicClass MsgWindow
 Inherits MessageWindow
 ' Assign integers to messages. ' Note that custom Window messages start at WM_USER = 0x400.PublicConst WM_CUSTOMMSG AsInteger = &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.PublicSubNew(ByVal msgform As MessageWindowForm)
  Me.msgform = msgform
 EndSub
' Override the default WndProc behavior to examine messages.ProtectedOverridesSub WndProc(ByRef msg As Microsoft.WindowsCE.Forms.Message)
  SelectCase 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))
  EndSelect
 ' Call the base class WndProc method ' to process any messages not handled.MyBase.WndProc(msg)
 EndSubEndClass
                        using System;
using System.Windows.Forms;
using Microsoft.WindowsCE.Forms;

namespace MsgWindow
{
publicclass 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);

  }
  protectedoverridevoid Dispose( bool disposing )
  {
   base.Dispose( disposing );
  }
  #region Windows Form Designer generated code
  privatevoid InitializeComponent()
  {
   this.mainMenu1 = new System.Windows.Forms.MainMenu();
   this.Menu = this.mainMenu1;
   this.Text = "Message Window Test";

  }
  #endregion

  staticvoid Main()
  {
   Application.Run(new MessageWindowForm());
  }

  // Process taps to generate messages// with the WParam and LParam parameters// using the X and Y mouse coordinates.protectedoverridevoid 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.publicvoid 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.publicclass MsgWindow : MessageWindow
 {
  // Assign integers to messages.// Note that custom Window messages start at WM_USER = 0x400.publicconstint 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.protectedoverridevoid 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

Message

その他の技術情報

Windows フォーム コントロール、.NET Framework を最適化します。