NativeWindow.CreateHandle(CreateParams) 메서드

정의

지정된 생성 매개 변수로 창 및 해당 핸들을 만듭니다.

public:
 virtual void CreateHandle(System::Windows::Forms::CreateParams ^ cp);
public virtual void CreateHandle (System.Windows.Forms.CreateParams cp);
abstract member CreateHandle : System.Windows.Forms.CreateParams -> unit
override this.CreateHandle : System.Windows.Forms.CreateParams -> unit
Public Overridable Sub CreateHandle (cp As CreateParams)

매개 변수

cp
CreateParams

이 창의 생성 매개 변수를 지정하는 CreateParams입니다.

예외

네이티브 창을 만들려고 할 때 운영 체제의 리소스가 부족한 경우

네이티브 Windows API로 지정된 창을 만들 수 없는 경우

현재 네이티브 창의 핸들이 이미 할당된 경우. 즉 Handle 속성이 Zero와 같지 않은 경우

예제

다음 코드 예제에서는 특정 운영 체제 창 클래스 이름으로 창을 만드는 하는 방법을 보여 줍니다. 이 예제에서 상속 되는 클래스를 만듭니다 NativeWindow 이렇게 하려면.

합니다 MyNativeWindow 클래스를 사용 하 여 새 창을 만듭니다 합니다 ClassNameBUTTON합니다. 이 Win32 단추 창을 만듭니다. 단추의 크기와 위치 설정 되 고 추가 창 스타일을 지정 합니다. 클래스를 사용 하는 방법에 설명 합니다 CreateHandle 메서드와 재정의 WndProc 수신 되는 창 메시지를 가로채는 메서드. WM_ACTIVATEAPP 메시지에 대 한 예제 보이지만이 바꿀 수 있습니다 실제 프로그램에서 창 메시지의 유형이 생성 시에 특정 합니다.

참고

일부 컨트롤 형식은 컨트롤 창 대신 창의 부모 창 메시지를 보냅니다. 자세한 내용은 Windows Platform 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.
internal class MyNativeWindow : NativeWindow
{

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

    private int windowHandle;

    public MyNativeWindow(Form parent)
    {

        CreateParams cp = new 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);
    }

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

    protected override void WndProc(ref 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.

        switch (m.Msg)
        {
            case WM_ACTIVATEAPP:
                // Do something here in response to messages
                break;
        }
        base.WndProc(ref m);
    }
}
' MyNativeWindow class to create a window given a class name.
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Friend Class MyNativeWindow
    Inherits NativeWindow

    ' Constant values were found in the "windows.h" header file.
    Private Const WS_CHILD As Integer = &H40000000, _
                  WS_VISIBLE As Integer = &H10000000, _
                  WM_ACTIVATEAPP As Integer = &H1C

    Private windowHandle As Integer

    Public Sub New(ByVal parent As Form)

        Dim cp As CreateParams = New 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 Or WS_VISIBLE

        ' Create the actual window
        Me.CreateHandle(cp)
    End Sub

    ' Listen to when the handle changes to keep the variable in sync
    <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
    Protected Overrides Sub OnHandleChange()
        windowHandle = Me.Handle.ToInt32()
    End Sub

    <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
        Protected Overrides Sub WndProc(ByRef m As Message)
        ' Listen for messages that are sent to the button window. Some messages are sent
        ' to the parent window instead of the button's window.

        Select Case (m.Msg)
            Case WM_ACTIVATEAPP
                ' Do something here in response to messages
        End Select

        MyBase.WndProc(m)
    End Sub

End Class

설명

합니다 cp 네이티브 Win32로 전달 되는 값을 지정 하는 매개 변수 CreateWindowEx 창 및 해당 핸들을 만드는 방법.

경우는 ClassName 필드가 아닙니다 null, 새로 만든된 창 핸들을 지정된 된 클래스에서 상속 합니다. 예를 들어 경우 ClassName 로 설정 된 BUTTON, Win32를 기반으로 하는 새로 만든된 창을 BUTTON 창 클래스입니다. Param 의 속성을 ClassName 개체 여야 합니다 null 또는 구조체로 선언 된 클래스의 인스턴스를 참조 합니다.

이 코드는 예제에 표시 된 발췌 된 NativeWindow 클래스 개요입니다. 간 결함을 위해 일부 코드가 표시 되지 않습니다. 참조 NativeWindow 전체 코드 샘플에 대 한 합니다.

참고

클래스 이름은 제공 되는 운영 체제를 사용 하 여 등록 됩니다.

적용 대상

추가 정보