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 クラスは、ClassNameBUTTON設定され新しウィンドウ作成します。これは 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



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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2024 GRAS Group, Inc.RSS