在客户区域中包含标题栏

时间:2013-11-24 19:41:39

标签: c# winapi custom-titlebar nonclient-area

我正在寻找一些建议......我要做的是扩展表单的客户区域以包括标题栏和窗口边框。我希望能够在非客户区域添加按钮和绘画。我读了 this文章,但是它是用C ++编写的,我正在使用C#(Visual Basic也可以)。读完之后,我想出了这段代码:

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);
    }

所有这一切都是为了使窗口更大,它对非客户区域没有任何作用。我一整天都在谷歌搜索,并没有遇到任何更好的事情。这已经困扰了我一段时间,所以如果有人有任何想法,请留下回复。

另外,这是我的第一篇文章,所以如果我做错了什么,请告诉我。

0 个答案:

没有答案