显示列表

GetWindowPlacement
返回指定窗口的显示状态以及被恢复的、最大化的和最小化的窗口位置。
bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);

hWnd
指定窗口的句柄

WINDOWPLACEMENT
保存窗口位置的信息

[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();

[DllImport("user32.dll")]
public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);

public struct POINT
{
    public int x;
    public int y;
}

public struct RECT
{
    public int left;
    public int top;
    public int right;
    public int bottom;
}

public struct WINDOWPLACEMENT
{
    public int length;
    public int flags;
    public int showCmd;
    public POINT ptMinPosition;
    public POINT ptMaxPosition;
    public RECT rcNormalPosition;
}

private void button1_Click(object sender, EventArgs e)
{
    IntPtr hWnd = GetForegroundWindow();

    WINDOWPLACEMENT lpwndpl = new WINDOWPLACEMENT();

    //lpwndpl.length = Marshal.SizeOf(typeof(WINDOWPLACEMENT));

    GetWindowPlacement(hWnd, ref lpwndpl); // 数据都被存在 WINDOWPLACEMENT 中

    // 窗口的位置信息
    MessageBox.Show(lpwndpl.rcNormalPosition.left.ToString());
}

标签:API 
返回摘要 | 分类(C#/CSharp) | 访问(37) | 编辑