NativeWindow.WndProc メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


このメソッドは、ウィンドウ メッセージがウィンドウのハンドルに送信されると呼び出されます。
継承時の注意 特定のメッセージ処理を実装するには、このメソッドをオーバーライドします。未処理のメッセージの base.WndProc を呼び出します。
ウィンドウ プロシージャでオペレーティング システムのウィンドウ メッセージを受け取る方法を次のコード例に示します。この例では、これを達成するために、NativeWindow から継承するクラスを作成します。
MyNativeWindowListener クラスは、コンストラクタに渡されたフォームのウィンドウ プロシージャにフックし、WndProc メソッドをオーバーライドして WM_ACTIVATEAPP ウィンドウ メッセージを受け取ります。このクラスでは、NativeWindow が使用するウィンドウ ハンドルを識別するために AssignHandle メソッドと ReleaseHandle メソッドを使用する方法を示しています。このハンドルは、Control.HandleCreated イベントと Control.HandleDestroyed イベントを基に割り当てられます。WM_ACTIVATEAPP ウィンドウ メッセージが受信されると、このクラスは form1ApplicationActivated メソッドを呼び出します。
このコードは、NativeWindow クラスの概要で紹介されている例からの抜粋です。簡略にするため、コードの一部は示されていません。コード全体については、NativeWindow を参照してください。
// NativeWindow class to listen to operating system messages. ref class MyNativeWindowListener: public NativeWindow { private: // Constant value was found in the S"windows.h" header file. literal int WM_ACTIVATEAPP = 0x001C; Form1^ parent; public: MyNativeWindowListener( Form1^ parent ) { parent->HandleCreated += gcnew EventHandler( this, &MyNativeWindowListener::OnHandleCreated ); parent->HandleDestroyed += gcnew EventHandler( this, &MyNativeWindowListener::OnHandleDestroyed ); this->parent = parent; } internal: // Listen for the control's window creation and then hook into it. void OnHandleCreated( Object^ sender, EventArgs^ /*e*/ ) { // Window is now created, assign handle to NativeWindow. AssignHandle( (dynamic_cast<Form1^>(sender))->Handle ); } void OnHandleDestroyed( Object^ /*sender*/, EventArgs^ /*e*/ ) { // Window was destroyed, release hook. ReleaseHandle(); } protected: virtual void WndProc( Message %m ) override { // Listen for operating system messages switch ( m.Msg ) { case WM_ACTIVATEAPP: // Notify the form that this message was received. // Application is activated or deactivated, // based upon the WParam parameter. parent->ApplicationActived( ((int)m.WParam != 0) ); break; } NativeWindow::WndProc( m ); } };
// NativeWindow class to listen to operating system messages. /** @attribute SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode) */ public class MyNativeWindowListener extends NativeWindow { // Constant value was found in the "windows.h" header file. private int WM_ACTIVATEAPP = 0x1C; private Form1 parent; public MyNativeWindowListener(Form1 parent) { parent.add_HandleCreated(new EventHandler(this.OnHandleCreated)); parent.add_HandleDestroyed(new EventHandler(this.OnHandleDestroyed)); this.parent = parent; } //MyNativeWindowListener // Listen for the control's window creation and then hook into it. void OnHandleCreated(Object sender, EventArgs e) { // Window is now created, assign handle to NativeWindow. AssignHandle(((Form1)sender).get_Handle()); } //OnHandleCreated void OnHandleDestroyed(Object sender, EventArgs e) { // Window was destroyed, release hook. ReleaseHandle(); } //OnHandleDestroyed protected void WndProc(Message m) { // Listen for operating system messages if (m.get_Msg() == WM_ACTIVATEAPP) { // Notify the form that this message was received. // Application is activated or deactivated, // based upon the WParam parameter. parent.ApplicationActived(m.get_WParam().ToInt32() != 0); } super.WndProc(m); } //WndProc } //MyNativeWindowListener

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からNativeWindow.WndProc メソッドを検索する場合は、下記のリンクをクリックしてください。

- NativeWindow.WndProc メソッドのページへのリンク