1. How to obtain a window handle?
For example, you can obtain the handle of the window picturebox control (which can be used by other controls,
Intptr handle = picturebox. Handle;
2. Note: The process of creating a window is totally different from that of creating a window !!!
When a window is created, there is no handle in the window, only application. run (form) or Form. A handle is available only after show (). That is, a handle is available only after the window is displayed or the message loop is started! If form = new form () is created after form is created, the form is called in the main thread. handle. If the handle has not been created, referencing this attribute will force the creation of the handle, which will have a fatal impact on the system logic.
3. How can I determine whether a window handle has been created?
Use the ishandlecreated attribute: This attribute indicates whether the control has a handle associated with it. If a handle has been assigned to the control, the value is true; otherwise, the value is false.
4. Some attributes:
(1) createcontrol: Creates controls forcibly, including handles and any child controls.
(2) createhandle: Create a handle for the control,
Generally, you should not directly call the createhandle method. The preferred method is to call the createcontrol method, which forces the creation of a handle for the control and its child controls when creating the control. When you override createhandle in a derived class, make sure that the createhandle method of the base class is called to ensure that the handle has been created.
(3) destroyhandle: destroys the handle associated with the control.
(4) fromchildhandle: Retrieves controls containing the specified handle.
(5) fromhandle: return the current control associated with the specified handle
(6) handle: gets the window handle bound to the control. The value of the handle attribute is Windows hwnd. If the handle has not been created, referencing this property will force the creation of the handle.
(7) ishandlecreated: indicates whether the control has an associated handle. If the control has been assigned a handle, the value is true; otherwise, the value is false.
(8), recreatehandle: force a new handle for the control
(9), recreatinghandle: indicates whether the current handle is hitting
5. Note:
The handle is a random volume. Generally, two different results are returned when two operations are performed.