代碼如下:
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();
ctrl.Capture = true;
IntPtr hWnd = GetCapture();
ctrl.Capture = false;
SetCapture(hOldWnd);
return hWnd;
}
}