调整窗口大小而不显示窗口内容

时间:2017-07-27 21:05:48

标签: c# wpf windows resize

在Windows中,您有一个设置为“拖动时显示窗口内容”。关闭此功能后,您将使用窗口轮廓调整大小。

我的WPF应用程序有很多控件,因此调整大小非常慢。有没有办法通过仅显示窗口轮廓而不是始终更新内容来调整应用程序的大小?

我发现了question regarding WinForms,但遗憾的是我无法将其改编为WPF。我可以挂钩到HwndSource,但是在Windows 10中消息编号可能已更改,因此从未输入该答案中的if语句...或者可能还有其他工作正在进行中。

此外,在if内部调用WndProc基础之后更改了系统参数,然后在调用完系统参数后重置系统参数。但是在WPF中调用该方法不是一个选项,因为Window对象无法转发消息。

public void OnViewLoaded() {
    HwndSource source = HwndSource.FromHwnd(
        new WindowInteropHelper(this).Handle);
    source?.AddHook(WndProc);
}

private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam,
                              IntPtr lParam, ref bool handled) {
    if (msg == WM_SYSCOMMAND && (wParam.ToInt32() & 0xfff0) == SC_SIZE) {
        // This if is never entered

        int isDragFullWindow;
        GetSystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0, out isDragFullWindow, 0);

        if (isDragFullWindow != 0)
            SetSystemParametersInfo(SPI_SETDRAGFULLWINDOWS, 0, 0, 0);

        // How to call this?
        base.WndProc(ref m);

        if (isDragFullWindow != 0)
            SetSystemParametersInfo(SPI_SETDRAGFULLWINDOWS, 1, 0, 0);
    }
}

0 个答案:

没有答案
相关问题