using System.Runtime.InteropServices;
[DllImport("user32.dll")]
internal static extern bool GetWindowPlacement(int hWnd, ref WINDOWPLACEMENT lpwndpl);
internal struct WINDOWPLACEMENT
{
public int length;
public int flags;
public ShowWindowCommands showCmd;
public System.Drawing.Point ptMinPosition;
public System.Drawing.Point ptMaxPosition;
public System.Drawing.Rectangle rcNormalPosition;
}
internal enum ShowWindowCommands : int
{
Hide = 0,
Normal = 1,
Minimized = 2,
Maximized = 3,
}
internal enum WNDSTATE : int
{
SW_HIDE = 0,
SW_SHOWNORMAL = 1,
SW_NORMAL = 1,
SW_SHOWMINIMIZED = 2,
SW_MAXIMIZE = 3,
SW_SHOWNOACTIVATE = 4,
SW_SHOW = 5,
SW_MINIMIZE = 6,
SW_SHOWMINNOACTIVE = 7,
SW_SHOWNA = 8,
SW_RESTORE = 9,
SW_SHOWDEFAULT = 10,
SW_MAX = 10
}
private static WINDOWPLACEMENT GetPlacement(int hwnd)
{
WINDOWPLACEMENT placement = new WINDOWPLACEMENT();
placement.length = Marshal.SizeOf(placement);
GetWindowPlacement(hwnd, ref placement);
return placement;
}
private void GetWindowPos(int hwnd, ref int ptrPhwnd, ref int ptrNhwnd, ref Point ptPoint, ref Size szSize, ref WNDSTATE intShowCmd)
{
WINDOWPLACEMENT wInf = new WINDOWPLACEMENT();
wInf.length = System.Runtime.InteropServices.Marshal.SizeOf(wInf);
GetWindowPlacement(hwnd, ref wInf);
szSize = new Size(wInf.rcNormalPosition.Right - (wInf.rcNormalPosition.Left * 2),wInf.rcNormalPosition.Bottom - (wInf.rcNormalPosition.Top * 2));
ptPoint = new Point(wInf.rcNormalPosition.Left, wInf.rcNormalPosition.Top);
}
C#