Beispiel #1
0
        protected override void WndProc(ref Message m)
        {
            int    WM_NCCALCSIZE = 0x83;
            int    WM_NCHITTEST  = 0x84;
            IntPtr result        = default(IntPtr);

            int dwmHandled = Dwm.DwmDefWindowProc(m.HWnd, m.Msg, m.WParam, m.LParam, ref result);

            if (dwmHandled == 1)
            {
                m.Result = result;
                return;
            }

            if (m.Msg == WM_NCCALCSIZE && m.WParam.ToInt32() == 1)
            {
                WinApi.NCCALCSIZE_PARAMS nccsp = (WinApi.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(WinApi.NCCALCSIZE_PARAMS));

                if (!_marginOk)
                {
                    //Set what client area would be for passing to DwmExtendIntoClientArea. Also remember that at least one of these values NEEDS TO BE > 1, else it won't work.
                    dwmMargins.cyTopHeight    = 1;
                    dwmMargins.cxLeftWidth    = 1;
                    dwmMargins.cyBottomHeight = 1;
                    dwmMargins.cxRightWidth   = 1;
                    _marginOk = true;
                }

                Marshal.StructureToPtr(nccsp, m.LParam, false);

                m.Result = IntPtr.Zero;
            }
            else if (m.Msg == WM_NCHITTEST && m.Result.ToInt32() == 0)
            {
                m.Result = HitTestNCA(m.HWnd, m.WParam, m.LParam);
            }
            else
            {
                base.WndProc(ref m);
            }
        }
Beispiel #2
0
 private void Form1_Activated(object sender, EventArgs e)
 {
     Dwm.DwmExtendFrameIntoClientArea(this.Handle, ref dwmMargins);
 }