Blue0500
Blue0500

Reputation: 725

Include Titlebar in Client Area

I'm looking for some advice...what I'm trying to do is extend the form's client area to include the title bar and window border. I want to be able to add a button and paint on the non-client area. I've read this article, but it's in C++, and I'm using C# (Visual Basic works too). After reading it, I came up with this code:

public partial class Form2 : Form
{
    [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] 
    public static extern bool GetWindowRect(HandleRef hwnd, out Rectangle lpRect);

    [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, 
        int cx, int cy, SetWindowPosFlags uFlags);

    public enum SetWindowPosFlags : uint { };

    public Form2()
    {
        InitializeComponent();
    }

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == 0x0001)
        {
            Rectangle rcClient;
            GetWindowRect(new HandleRef(this, this.Handle), out rcClient);
            SetWindowPos(this.Handle, (IntPtr)0, rcClient.Left, rcClient.Top,
                rcClient.Width, rcClient.Height, new SetWindowPosFlags());

            //fCallDWP = true;  No idea what to do with these two
            //lRet = 0;
        }
        base.WndProc(ref m);
    }

All this does is make the window larger, it doesn't do anything with the non-client area. I've been Googling it all day and haven't come across anything better. This has been stumping me for a while, so if anyone has any ideas, please leave a reply.

Also, this is my first post so if I'm doing anything wrong, let me know.

Upvotes: 1

Views: 864

Answers (0)

Related Questions