..
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
//WindowResizer r = new WindowResizer(this);
//r.addResizerLeft(left);
//r.addResizerLeftDown(leftdown);
//r.addResizerRightDown(rightdown);
//r.addResizerRight(right);
//r.addResizerUp(up);
//r.addResizerDown(down);
HwndSource hs = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
hs.AddHook( new HwndSourceHook(HookWnd));
}
struct NCCALCSIZE_PARAMS
{
public _RECT rcNewWindow;
public _RECT rcOldWindow;
public _RECT rcClient;
IntPtr lppos;
}
struct _RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
private void AdjustClientRect(ref _RECT rcClient)
{
rcClient.left -= SystemInformation.FrameBorderSize.Width;
rcClient.right += SystemInformation.FrameBorderSize.Width;
rcClient.bottom += SystemInformation.FrameBorderSize.Width;
rcClient.top -= SystemInformation.FrameBorderSize.Width + SystemInformation.CaptionHeight;
}
IntPtr HookWnd(IntPtr hwnd,int msg, IntPtr w, IntPtr l , ref bool handle)
{
switch(msg)
{
case 0x83:
{
NCCALCSIZE_PARAMS p = (NCCALCSIZE_PARAMS)Marshal.PtrToStructure(l, typeof(NCCALCSIZE_PARAMS));
AdjustClientRect(ref p.rcClient);
Marshal.StructureToPtr(p, l, false);
handle = true;
}
break;
case WindowsMessage.WM_NCACTIVATE:
handle = true;
break;
}
return IntPtr.Zero;
}