public bool CenterWindow(IntPtr hWnd, int iMonitorIndex = 0, bool bUseWorkArea = false) { RECT srect = new RECT(); WindowsAPI.GetWindowRect(hWnd, ref srect); Rect rect = new Rect(srect.left, srect.top, srect.right - srect.left, srect.bottom - srect.top); if (0 > iMonitorIndex) { rect = CenterWindowToAll(rect, bUseWorkArea); } else if (0 == iMonitorIndex) { MonitorDevice pMonitor = GetNearestMonitor(hWnd); if (pMonitor.handle == IntPtr.Zero) { return false; } rect = pMonitor.CenterRectToMonitor(rect, bUseWorkArea); } else { MonitorDevice pMonitor = GetMonitor(iMonitorIndex); if (pMonitor.handle == IntPtr.Zero) { return false; } rect = pMonitor.CenterRectToMonitor(rect, bUseWorkArea); } return WindowsAPI.SetWindowPos( hWnd, IntPtr.Zero, (int)rect.Left, (int)rect.Top, 0, 0, CommonConst.SWP_NOSIZE | CommonConst.SWP_NOZORDER); }
public static extern bool ExtTextOut(IntPtr hdc, int X, int Y, uint fuOptions, ref RECT lprc, string lpString, uint cbCount, int[] lpDx);
public static extern int DrawTextEx(IntPtr hdc, string lpchText, int cchText, RECT lprc, uint dwDTFormat, DRAWTEXTPARAMS lpDTParams);
public static extern bool InvalidateRect(int hWnd, ref RECT lpRect, bool bErase);
public static extern int DrawText(IntPtr hDC, string lpString, int nCount, ref RECT lpRect, uint uFormat);
public static extern bool IsRectEmpty(ref RECT lprc);
public static extern bool OffsetRect(ref RECT lprc, int dx, int dy);
public static extern bool CopyRect(string lprcDst, ref RECT lprcSrc);
public static extern IntPtr GetDCEx(IntPtr hWnd, RECT hrgnClip, int flags);
public static extern int FillRect(IntPtr hDC, ref RECT lprc, IntPtr hbr);
public static extern int TileWindows(IntPtr hwndParent, uint wHow, ref RECT lpRect, uint cKids, IntPtr lpKids);
public static extern bool GetClipCursor(ref RECT lpRect);
public static extern bool AdjustWindowRectEx(RECT lpRect, int dwStyle, bool bMenu, int dwExStyle);
public static extern bool AdjustWindowRect(ref RECT lpRect, int dwStyle, bool bMenu);
public static extern bool GetClientRect(IntPtr hWnd, ref RECT lpRect);
public static extern bool GetWindowRect(IntPtr handle, ref RECT lpRect);