private class ControlInfo
{
public float LeftRatio;
public float TopRatio;
public float WidthRatio;
public float HeightRatio;
public bool AnchorLeft;
public bool AnchorTop;
public bool AnchorRight;
public bool AnchorBottom;
public IntPtr ParentHandle;
}
_mainWindowHandle = hWnd;
GetWindowRect(_mainWindowHandle, out _originalWindowRect);
_hookProc = new HookProc(WindowProc);
_hookHandle = SetWindowsHookEx(WH_CALLWNDPROC, _hookProc, IntPtr.Zero, GetCurrentThreadId());
return _hookHandle != IntPtr.Zero;
}
[DllExport("AddControlToAutoScale", CallingConvention = CallingConvention.StdCall)]
public static bool AddControlToAutoScale(IntPtr hWnd, int anchorLeft, int anchorTop, int anchorRight, int anchorBottom)
{
if (_hookHandle == IntPtr.Zero || _controls.ContainsKey(hWnd))
{
return false;
}
RECT controlRect;
GetWindowRect(hWnd, out controlRect);
IntPtr parentHandle = GetParent(hWnd);
RECT parentRect;
GetWindowRect(parentHandle, out parentRect);
POINT topLeft = new POINT { X = controlRect.Left, Y = controlRect.Top };
POINT bottomRight = new POINT { X = controlRect.Right, Y = controlRect.Bottom };
ScreenToClient(parentHandle, ref topLeft);
ScreenToClient(parentHandle, ref bottomRight);
int parentWidth = parentRect.Right - parentRect.Left;
int parentHeight = parentRect.Bottom - parentRect.Top;
if (cwp.message == WM_SIZE)
{
foreach (var kvp in _controls)
{
IntPtr controlHandle = kvp.Key;
ControlInfo info = kvp.Value;
RECT parentRect;
GetWindowRect(info.ParentHandle, out parentRect);
int parentWidth = parentRect.Right - parentRect.Left;
int parentHeight = parentRect.Bottom - parentRect.Top;