Non Client Area

  • Thread starter Thread starter Patrick Blackman
  • Start date Start date
P

Patrick Blackman

How do you access the non-client area of a control for painting or resizing
the client area.

Thanks any help would do.
 
Patrick said:
How do you access the non-client area of a control for painting or resizing
the client area.

Thanks any help would do.

You handle the WM_NCPAINT message in your windows processing handler.
From a previous post from a microsoftie:

protected override void WndProc(ref Message msg)
{
// Call the base paint FIRST.
base.WndProc(ref msg);
const int WM_NCPAINT = 0x85;
if (msg.Msg == WM_NCPAINT)
{
// Do your painting here.
}

}

matt
 
Thanks for the info, what I want to do is to access the non client area of a richtextbox so I can paint line numbers at the side, therefore I need to reduce the client rectangle/area, any ideas on this.

I was trying this bit of code but got errors memory:

[DllImport("kernel32", CharSet = CharSet.Auto)]

internal static extern void CopyMemory (WINDOWPOS pDst , IntPtr pSrc , int ByteLen);

[DllImport("kernel32", CharSet = CharSet.Auto)]

internal static extern void CopyMemory(NCCALCSIZE_PARAMS pDst, IntPtr pSrc, int ByteLen);


[DllImport("kernel32", CharSet = CharSet.Auto)]

internal static extern void CopyMemory(IntPtr pSrc, NCCALCSIZE_PARAMS pDst, int ByteLen);



[StructLayout(LayoutKind.Sequential)]

internal class NCCALCSIZE_PARAMS

{

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]

public RECT[] rgxRects;

public IntPtr lppos ;

public NCCALCSIZE_PARAMS()

{

}

}

[StructLayout(LayoutKind.Sequential)]

internal class WINDOWPOS

{

public IntPtr hwnd;

public IntPtr hWndInsertAfter;

public int x;

public int y;

public int cx;

public int cy;

public int flags;

public WINDOWPOS() { }

}


//WinProc override
protected override void WndProc(ref Message m)

{

case WM_NCCALCSIZE :

NCCALCSIZE_PARAMS aNCCS = new NCCALCSIZE_PARAMS();

Marshal.PtrToStructure(m.LParam, aNCCS);

WINDOWPOS aWinPos = new WINDOWPOS();

// Get the non-client calc size rectangle and window position

CopyMemory( aNCCS, m.LParam, Marshal.SizeOf(aNCCS));

//CopyMemory( aWinPos, aNCCS.lppos, Marshal.SizeOf(aWinPos));

//Populate the non-client rectangle UDT information

aNCCS.rgxRects[0].Left =aWinPos.x;

aNCCS.rgxRects[0].Top = aWinPos.y;

aNCCS.rgxRects[0].Right =75;// aWinPos.x + aWinPos.cx;

aNCCS.rgxRects[0].Bottom = 75;// aWinPos.y + aWinPos.cy;


//Make an adjustment for our line numbers

aNCCS.rgxRects[0].Left = aNCCS.rgxRects[0].Left + 75;

//Duplicate these values in the other rectangle

aNCCS.rgxRects[1] = aNCCS.rgxRects[0];

//copy it back to the lParam pointer address so the process uses the information.

CopyMemory(m.LParam, aNCCS, Marshal.SizeOf(aNCCS));

base.WndProc(ref m);

}
 
Patrick said:
Thanks for the info, what I want to do is to access the non client area of a richtextbox so I can paint line numbers at the side, therefore I need to reduce the client rectangle/area, any ideas on this.

NcCalcSize is the message to catch. What error did you get and what
line?

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top