Provides a low-level encapsulation of a window handle and a window procedure.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
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.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.