在Windows资源管理器和Internet Explorer等应用程序中,可以抓住标题栏下方的扩展框架区域并拖动窗口.
对于WinForms应用程序,表单和控件尽可能接近原生Win32 API; 一个人只是简单地覆盖WndProc()其表单中的处理程序,处理WM_NCHITTEST窗口消息并欺骗系统,使其认为点击框架区域实际上是通过返回点击标题栏HTCAPTION.我已经在我自己的WinForms应用程序中做到了令人愉快的效果.
在WPF中,我还可以实现一个类似的WndProc()方法并将其挂钩到我的WPF窗口的句柄,同时将窗口框架扩展到客户端区域,如下所示:
// In MainWindow
// For use with window frame extensions
private IntPtr hwnd;
private HwndSource hsource;
private void Window_SourceInitialized(object sender, EventArgs e)
{
try
{
if ((hwnd = new WindowInteropHelper(this).Handle) == IntPtr.Zero)
{
throw new InvalidOperationException("Could not get window handle for the main window.");
}
hsource = HwndSource.FromHwnd(hwnd);
hsource.AddHook(WndProc);
AdjustWindowFrame();
}
catch (InvalidOperationException)
{
FallbackPaint();
}
}
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr …Run Code Online (Sandbox Code Playgroud)