getcapture (coredll)
Last changed: -212.140.133.126

.
Summary
Retrieve a handle to the window that has captured mouse/stylus input.

C# Signature:

[DllImport("coredll.dll")]
static extern IntPtr GetCapture();

VB .NET Signature:

Declare Function GetCapture Lib "coredll.dll" () As IntPtr

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

You can use GetCapture in conjunction with SetCapture to obtain the window handle of a Control. See the sample code below.

Sample Code:

public IntPtr GetHWnd(Control ctrl)
{
   IntPtr hOldWnd = GetCapture();
   ctrl.Capture = true;
   IntPtr hWnd = GetCapture();
   ctrl.Capture = false;
   SetCapture(hOldWnd);
   return hWnd;
}


This is a way of getting a 'dialog' window on PocketPC

{

private const int RequiredWidth = 200;

private const int RequiredHeight = 148;

private void Form_Load(object sender, System.EventArgs e)

{

    this.Capture = true;
    IntPtr hWnd = GetCapture();

    SetWindowPos(hWnd,
        hWnd,
        (Screen.PrimaryScreen.Bounds.Width-RequiredWidth)/2,
        30,
        RequiredWidth,
        RequiredHeight,
        0);
    }

[DllImport("coredll.dll")]

static extern IntPtr GetCapture();

[DllImport("coredll.dll")]

static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,

    int Y, int cx, int cy, uint uFlags);

}

Alternative Managed API:

None

Documentation
GetCapture on MSDN