Export (0) Print
Expand All

NativeWindow Class

Provides a low-level encapsulation of a window handle and a window procedure.

System.Object
  System.MarshalByRefObject
    System.Windows.Forms.NativeWindow

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

[<SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)>]
[<SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.UnmanagedCode)>]
type NativeWindow =  
    class 
        inherit MarshalByRefObject 
        interface IWin32Window 
    end

The NativeWindow type exposes the following members.

  NameDescription
Public methodNativeWindowInitializes an instance of the NativeWindow class.
Top

  NameDescription
Public propertyHandleGets the handle for this window.
Top

  NameDescription
Public methodAssignHandleAssigns a handle to this window.
Public methodCreateHandleCreates a window and its handle with the specified creation parameters.
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodDefWndProcInvokes the default window procedure associated with this window.
Public methodDestroyHandleDestroys the window and its handle.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeReleases the resources associated with this window. (Overrides Object.Finalize().)
Public methodStatic memberFromHandleRetrieves the window associated with the specified handle.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Protected methodOnHandleChangeSpecifies a notification method that is called when the handle for a window is changed.
Protected methodOnThreadExceptionWhen overridden in a derived class, manages an unhandled thread exception.
Public methodReleaseHandleReleases the handle associated with this window.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Protected methodWndProcInvokes the default window procedure associated with this window.
Top

This class automatically manages window class creation and registration.

A window is not eligible for garbage collection when it is associated with a window handle. To ensure proper garbage collection, handles must either be destroyed manually using DestroyHandle or released using ReleaseHandle.

NoteNote

The ReleaseHandle method is called when the WM_NCDESTROY message is processed. This means there are cases in which when you do not need to manually call ReleaseHandle, but it is good practice to do so.

The NativeWindow class provides the following properties and methods to manage handles: Handle, CreateHandle, AssignHandle, DestroyHandle, and ReleaseHandle.

The following code example demonstrates intercepting operating system window messages in a window procedure, and creating a window with a specific operating system window class name. The example creates two classes that inherit from NativeWindow that accomplish this.

The MyNativeWindowListener class hooks into the window procedure of the form passed into the constructor, and overrides the WndProc method to intercept the WM_ACTIVATEAPP window message. The class demonstrates the usage of the AssignHandle and ReleaseHandle methods to identify the window handle the NativeWindow will use. The handle is assign based upon the Control.HandleCreated and Control.HandleDestroyed events. When the WM_ACTIVATEAPP window message is received, the class calls the form1 ApplicationActivated method.

The MyNativeWindow class creates a new window with the ClassName set to BUTTON. The class demonstrates using the CreateHandle method and overriding the WndProc method to intercept window messages that are received.

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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft