private void ApplyLetterBoxing(ref MM_RECT win) { // avoid fisheye text overhang as 1:1 source when letterboxing applied. const float aspectRatio = (float)1 / (float)1; float targetW = Math.Abs((float)(win.Right - win.Left)); float targetH = Math.Abs((float)(win.Bottom - win.Top)); float tempH = targetW / aspectRatio; if (tempH <= targetH) { float deltaH = Math.Abs(tempH - targetH) / 2; win.Top += (int)deltaH; win.Bottom -= (int)deltaH; } else { float tempW = targetH * aspectRatio; float deltaW = Math.Abs(tempW - targetW) / 2; win.Left += (int)deltaW; win.Right -= (int)deltaW; } }
public static extern bool GetClientRect([In] IntPtr hWnd, out MM_RECT lpRect);
public static extern bool GetWindowRect([In] IntPtr hWnd, out MM_RECT lpRect);