Provides a low-level encapsulation of a window handle and a window procedure.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
[<SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.UnmanagedCode)>] [<SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)>] type NativeWindow = class inherit MarshalByRefObject interface IWin32Window end
Thetype exposes the following members.
|AssignHandle||Assigns a handle to this window.|
|CreateHandle||Creates a window and its handle with the specified creation parameters.|
|CreateObjRef||Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)|
|DefWndProc||Invokes the default window procedure associated with this window.|
|DestroyHandle||Destroys the window and its handle.|
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Releases the resources associated with this window. (Overrides Object.Finalize().)|
|FromHandle||Retrieves the window associated with the specified handle.|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetLifetimeService||Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|InitializeLifetimeService||Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)|
|MemberwiseClone()||Creates a shallow copy of the current Object. (Inherited from Object.)|
|MemberwiseClone(Boolean)||Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)|
|OnHandleChange||Specifies a notification method that is called when the handle for a window is changed.|
|OnThreadException||When overridden in a derived class, manages an unhandled thread exception.|
|ReleaseHandle||Releases the handle associated with this window.|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
|WndProc||Invokes the default window procedure associated with this window.|
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.
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 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 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 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.