When dealing with native code, we often need to pass the handle of a control (such as form) to the local code. The following code demonstrates how to use the copture attribute of control and the setcapture and getcapture methods to implement this process: Class winapi
{
[Dllimport ("coredll. dll")]
Private Static extern intptr setcapture (intptr hwnd );
[Dllimport ("coredll. dll")]
Private Static extern intptr getcapture ();
Public static intptr gethwnd (control CTRL)
{
Intptr holdwnd = getcapture (); // get the handle of the current active form
CTRL. Capture = true; // set CTRL to form focus
Intptr hwnd = getcapture (); get the current focus handle (that is, CTRL)
CTRL. Capture = false;
Setcapture (holdwnd); // restores the capture status.
Return hwnd;
}
}
When calling: Intptr hwndbutton = winapi. gethwnd (button1 );
Then pass the intptr to the local function.
Easy!
Enjoy it!
Yellow winter