Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

NativeWindow.CreateHandle Method

Creates a window and its handle with the specified creation parameters.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

abstract CreateHandle : 
        cp:CreateParams -> unit  
override CreateHandle : 
        cp:CreateParams -> unit


Type: System.Windows.Forms.CreateParams

A CreateParams that specifies the creation parameters for this window.


The operating system ran out of resources when trying to create the native window.


The native Win32 API could not create the specified window.


The handle of the current native window is already assigned; in explanation, the Handle property is not equal to Zero.

The cp parameter specifies the values that are passed to the native Win32 CreateWindowEx method to create a window and its handle.

When the ClassName field is not a null reference (Nothing in Visual Basic), the newly created window handle inherits from the specified class. For example, if ClassName is set to BUTTON, the newly created window is based on the Win32 BUTTON window class. The Param property of the ClassName object must either be a null reference (Nothing in Visual Basic) or reference an instance of a class that was declared as a structure.

This code is an excerpt from the example shown in the NativeWindow class overview. Some code is not shown for the purpose of brevity. See NativeWindow for the whole code listing.


   The class name provided is registered with the operating system.

The following code example demonstrates creating a window with a specific operating system window class name. The example creates a class that inherits from NativeWindow to accomplish this.

The MyNativeWindow class creates a new window with the ClassName set to BUTTON. This creates a Win32 button window. The location and size of the button is set, along with specifying additional window styles. The class demonstrates how to use the CreateHandle method and override the WndProc method to intercept window messages that are received. Although the example looks for the WM_ACTIVATEAPP message, this can be replaced in a real program with window messages specific to the type created.


Some control types send their window messages to the window parent instead of the window. See the Windows Platform SDK for more information.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

© 2015 Microsoft