Custom title bar size in Non-client area

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

I am trying to make a custom size title-bar in the non-client area of the
form. I've tried hooking to the NCCALCSIZE message with this code:

case (int)Native.NativeMethods.WindowMessages.WM_NCCALCSIZE:
if (m.WParam == IntPtr.Zero)
{
// get the NCCALCSIZE parameters
NativeMethods.NCCALCSIZE_PARAMS csp;

// Marshal them from the pointer
csp =
(NativeMethods.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam,
typeof(NativeMethods.NCCALCSIZE_PARAMS));

// Resize the client area to make more room above
csp.rectBeforeMove.top-= csp.rectBeforeMove.top/ 2;

Marshal.StructureToPtr(csp, m.LParam, false);
}
else
{
base.WndProc(ref m);
}
return;

However, it just says that I am trying to read or write into a protected
memory. If i modify any other value, i.e. right, left or bottom of the same
rectangle, it works OK yet there are no changes. I also tried changing the
other two rectangles, but the result is never what I need.

I would really appriciate any suggestions on this topic.
 
Anze,

According to the docs lParam contains pointer to NCCALCSIZE_PARAMS struct
only if the wParam is TURE - that means non-zero. Your codition is reversed.
This might be the reason for the exception you are getting.

form MSDN:
....
If wParam is TRUE, lParam points to an NCCALCSIZE_PARAMS structure that
contains information an application can use to calculate the new size and
position of the client rectangle.
....
 
Stoitcho,

thanks for your reply. I've tried fixing the condition but in that case the
client area gets strecthed across the whole form. I was wondering if you
might have an example handy that would accomplish this?

Thanks again!

With regards,
Anze
 
Back
Top