private void WM_NCHITTEST(ref Message m) { int wparam = m.LParam.ToInt32(); Point point = new Point(Win32.LOWORD(wparam), Win32.HIWORD(wparam)); point = PointToClient(point); if (m.Msg != Win32.WM_NCHITTEST) { return; } if (_IsResize) { TaskMenu.DeleteSYSMENU(this); if (point.X <= 8) { if (point.Y <= 8) { m.Result = (IntPtr)Win32.HTTOPLEFT; } else if (point.Y > Height - 8) { m.Result = (IntPtr)Win32.HTBOTTOMLEFT; } else { m.Result = (IntPtr)Win32.HTLEFT; } } else if (point.X >= Width - 8) { if (point.Y <= 8) { m.Result = (IntPtr)Win32.HTTOPRIGHT; } else if (point.Y >= Height - 8) { m.Result = (IntPtr)Win32.HTBOTTOMRIGHT; } else { m.Result = (IntPtr)Win32.HTRIGHT; } } else if (point.Y <= 8) { m.Result = (IntPtr)Win32.HTTOP; } else if (point.Y >= Height - 8) { m.Result = (IntPtr)Win32.HTBOTTOM; } else { TaskMenu.AddSYSMENU(this); m.Result = (IntPtr)Win32.HTCAPTION; } //this.Invalidate(); } else { m.Result = (IntPtr)Win32.HTCAPTION; } }
//重载WndProc方法 protected override void WndProc(ref Message m) { try { //渐变相关 if (_UseFadeStyle && m.Msg != Win32.WM_NCPAINT) { if (m.Msg == Win32.WM_SYSCOMMAND || m.Msg == Win32.WM_COMMAND) { //渐变到0,当最小化时 if (m.WParam == (IntPtr)Win32.SC_MINIMIZE) { if (heldMessage.WParam != (IntPtr)Win32.SC_MINIMIZE) { heldMessage = m; TargetOpacity = minimizedOpacity; } else { heldMessage = new Message(); TargetOpacity = activeOpacity; } return; } //当任务栏还原时渐变 else if (m.WParam == (IntPtr)Win32.SC_RESTORE && this.WindowState == FormWindowState.Minimized) { base.WndProc(ref m); TargetOpacity = activeOpacity; return; } //当窗体关闭时. else if (m.WParam == (IntPtr)Win32.SC_CLOSE) { heldMessage = m; TargetOpacity = minimizedOpacity; return; } } } switch (m.Msg) { //窗体客户区以外的重绘消息,一般是由系统负责处理 case Win32.WM_NCPAINT: break; // 在需要计算窗口客户区的大小和位置时发送。通过处理这个消息,应用程序可以在窗口大小或位置改变时控制客户区的内容 //case Win32.WM_NCCALCSIZE: // break; // 画窗体被激活或者没有被激活时的样子 case Win32.WM_NCACTIVATE: if (m.WParam == (IntPtr)Win32.WM_FALSE) { m.Result = (IntPtr)Win32.WM_TRUE; } break; case Win32.WM_ACTIVATE: TaskMenu.AddSYSMENU(this); base.WndProc(ref m); break; case Win32.WM_NCLBUTTONDBLCLK: if (_IsResize) { base.WndProc(ref m); } break; //鼠标移动,按下或释放都会执行该消息 case Win32.WM_NCHITTEST: WM_NCHITTEST(ref m); break; default: base.WndProc(ref m); break; } } catch (Exception Exception) { } }