NativeWindow.AssignHandle メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > NativeWindow.AssignHandle メソッドの意味・解説 

NativeWindow.AssignHandle メソッド

ウィンドウハンドル割り当てます

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Sub AssignHandle ( _
    handle As IntPtr _
)
Dim instance As NativeWindow
Dim handle As IntPtr

instance.AssignHandle(handle)
public void AssignHandle (
    IntPtr handle
)
public:
void AssignHandle (
    IntPtr handle
)
public void AssignHandle (
    IntPtr handle
)
public function AssignHandle (
    handle : IntPtr
)

パラメータ

handle

ウィンドウ割り当てるハンドル

例外例外
解説解説
使用例使用例

ウィンドウ プロシージャオペレーティング システムウィンドウ メッセージ受け取方法次のコード例示します。この例では、これを達成するために、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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
NativeWindow クラス
NativeWindow メンバ
System.Windows.Forms 名前空間
Handle
CreateHandle
DestroyHandle
ReleaseHandle
Finalize
OnHandleChange


このページでは「.NET Framework クラス ライブラリ リファレンス」からNativeWindow.AssignHandle メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からNativeWindow.AssignHandle メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からNativeWindow.AssignHandle メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「NativeWindow.AssignHandle メソッド」の関連用語

NativeWindow.AssignHandle メソッドのお隣キーワード
検索ランキング

   

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



NativeWindow.AssignHandle メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS