1

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.

Blue0500
  • 715
  • 8
  • 16
  • Do you mean you want to **expand** the client area and of course it may remove the tittle bar and the window border? – King King Nov 24 '13 at 19:45
  • Yes I would like to expand it to include the title bar, like in the link above, in the section "Drawing in the Extended Frame Window" http://i.msdn.microsoft.com/dynimg/IC502154.png – Blue0500 Nov 24 '13 at 19:52
  • 2
    http://stackoverflow.com/questions/2841180/how-to-add-an-extra-button-to-the-windows-title-bar – Sam Axe Nov 24 '13 at 22:40
  • Thanks! I don't know why I didn't see that before. I do have a question though. Why won't the Close, Minimize, and Maximize buttons change their look when the mouse hovers over them? – Blue0500 Nov 24 '13 at 23:30

0 Answers0