1 Attachment(s)
[2.0] Custom border form problem (Advanced. Guru needed)
I'm having a problem processing the WM_NCCALCSIZE message to redefine the border widths of a form.
This is the code:
Code:
private void WmNCCalcSize(ref Message m)
{
if (m.WParam.ToInt32() == 0)
{
RECT rc = (RECT)m.GetLParam(typeof(RECT));
rc.Left += 120;
rc.Top += 20;
rc.Right -= 20;
rc.Bottom -= 20;
Marshal.StructureToPtr(rc, m.LParam, true);
m.Result = IntPtr.Zero;
}
else
{
NCCALCSIZE_PARAMS csp;
csp = (NCCALCSIZE_PARAMS)m.GetLParam(typeof(NCCALCSIZE_PARAMS));
csp.rgrc0.Top += 120;
csp.rgrc0.Bottom -= 20;
csp.rgrc0.Left += 20;
csp.rgrc0.Right -= 20;
Marshal.StructureToPtr(csp, m.LParam, true);
//Return zero to preserve client rectangle
m.Result = IntPtr.Zero;
}
}
Works perfectly - that is until the user maximizes and normalizes the form, then the size of the @#!##@% form changes! i.e. it does not restore to the proper size.
It's driving me nuts.
A small and rather messy project illustrating the problem is attached. Sorry, it's a rar as I don't have WinZip on this machine.
Any ideas? Can it be a DotNet bug?
Help!!!!
Re: [2.0] Custom border form problem (Advanced. Guru needed)
Well, I'm no guru, but I think I know what the problem is. The overriden WndProc function's switch statement doesn't take into account that WM_WINDOWPOSCHANGED sets the client rectangle (Effectively calling that function you posted twice).. if you choose to simply ignore that message, the thing works fine.. i.e,
add this to your switch statement
Code:
case (int)NativeMethods.WindowMessages.WM_WINDOWPOSCHANGED: break;
hth,
Bill
Re: [2.0] Custom border form problem (Advanced. Guru needed)
That sounds logical. I'll give it a try.
Many thanks Bill!
Re: [2.0] Custom border form problem (Advanced. Guru needed)
Hi Bill.
Yes, that did the trick. Thanks!