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

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

NativeWindow.CreateHandle メソッド

作成パラメータを指定してウィンドウとそのハンドルを作成します。

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

Public Overridable Sub CreateHandle
 ( _
    cp As CreateParams _
)
Dim instance As NativeWindow
Dim cp As CreateParams

instance.CreateHandle(cp)
public virtual void CreateHandle (
    CreateParams cp
)
public:
virtual void CreateHandle (
    CreateParams^ cp
)
public void CreateHandle (
    CreateParams cp
)
public function CreateHandle (
    cp : CreateParams
)

パラメータ

cp

ウィンドウの作成パラメータを指定する CreateParams。

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

特定のオペレーティング システム ウィンドウ クラス名を使用してウィンドウを作成するコード例を次に示します。この例では、これを達成するために、NativeWindow から継承するクラスを作成します。

MyNativeWindow クラスは、ClassName が BUTTON に設定された新しいウィンドウを作成します。これは Win32 ボタン ウィンドウを作成します。ボタンの位置とサイズは、追加のウィンドウ スタイルと併せて設定されます。このクラスは、CreateHandle メソッドを使用し、WndProc メソッドをオーバーライドして、受信されたウィンドウ メッセージを受け取る方法を示しています。この例では WM_ACTIVATEAPP メッセージを処理していますが、実際のプログラムでは、作成した型に対応するウィンドウ メッセージを使用できます。

メモメモ

コントロールの種類によっては、ウィンドウではなく、ウィンドウの親にウィンドウ メッセージを送信します。詳細については、Windows プラットフォーム SDK を参照してください。

// MyNativeWindow class to create a window given a class name.
ref class MyNativeWindow: public NativeWindow
{
private:

   // Constant values were found in the S"windows.h" header
 file.
   literal int WS_CHILD = 0x40000000,WS_VISIBLE = 0x10000000,WM_ACTIVATEAPP
 = 0x001C;
   int windowHandle;

public:
   MyNativeWindow( Form^ parent )
   {
      CreateParams^ cp = gcnew CreateParams;

      // Fill in the CreateParams details.
      cp->Caption = "Click here";
      cp->ClassName = "Button";

      // Set the position on the form
      cp->X = 100;
      cp->Y = 100;
      cp->Height = 100;
      cp->Width = 100;

      // Specify the form as the parent.
      cp->Parent = parent->Handle;

      // Create as a child of the specified parent
      cp->Style = WS_CHILD | WS_VISIBLE;

      // Create the actual window
      this->CreateHandle( cp );
   }

protected:

   // Listen to when the handle changes to keep the variable in sync

   virtual void OnHandleChange() override
   {
      windowHandle = (int)this->Handle;
   }

   virtual void WndProc( Message % m ) override
   {
      // Listen for messages that are sent to the button window. Some
 messages are sent
      // to the parent window instead of the button's window.
      switch ( m.Msg )
      {
         case WM_ACTIVATEAPP:
            
            // Do something here in response to messages
            break;
      }
      NativeWindow::WndProc( m );
   }
};
// MyNativeWindow class to create a window given a class name.
/** @attribute SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)
 */
public class MyNativeWindow extends NativeWindow
{
    // Constant values were found in the "windows.h" header
 file.
    private int WS_CHILD = 0x40000000;
    private int WS_VISIBLE = 0x10000000;
    private int WM_ACTIVATEAPP = 0x1C;
    private int windowHandle;

    public MyNativeWindow(Form parent)
    {
        CreateParams cp = new CreateParams();

        // Fill in the CreateParams details.
        cp.set_Caption("Click here");
        cp.set_ClassName("Button");

        // Set the position on the form
        cp.set_X(100);
        cp.set_Y(100);
        cp.set_Height(100);
        cp.set_Width(100);

        // Specify the form as the parent.
        cp.set_Parent(parent.get_Handle());

        // Create as a child of the specified parent
        cp.set_Style(WS_CHILD | WS_VISIBLE);

        // Create the actual window
        this.CreateHandle(cp);
    } //MyNativeWindow

    // Listen to when the handle changes to keep the variable in sync
    protected void OnHandleChange()
    {
        windowHandle = this.get_Handle().ToInt32();
    } //OnHandleChange

    protected void WndProc(Message m)
    {
        // Listen for messages that are sent to the button window. 
        // Some messages are sent to the parent window 
        // instead of the button's window.
        if (m.get_Msg() == WM_ACTIVATEAPP) {
            // Do something here in response to messages
        }
        super.WndProc(m);
    } //WndProc
} //MyNativeWindow
.NET Framework のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
NativeWindow クラス
NativeWindow メンバ
System.Windows.Forms 名前空間
CreateParams クラス
Handle
AssignHandle
DestroyHandle
Finalize
ReleaseHandle


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

英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

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

   

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



NativeWindow.CreateHandle メソッドのページの著作権

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

©2026 GRAS Group, Inc.RSS