2

In Windows you have a setting to "Show window contents while dragging". When this is off you are instead resizing with an outline of the window.

My WPF application has many controls on it, so it is extremely slow to resize. Is there a way to make my application resize by showing only the window outline instead of always updating the contents?

I found this question regarding WinForms but unfortunately I'm not able to adapt it to WPF. I can hook onto the HwndSource, but the message numbers may have changed in Windows 10, so the if statement in that answer is never entered... or there may be other things at work.

Also, inside the if it calls the WndProc base after is has changed a system parameter, then resetting the system parameter when it has finished calling it. But calling that method is not an option in WPF as a Window object does not have a way to forward the message.

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);
    }
}
TheHvidsten
  • 4,028
  • 3
  • 29
  • 62
  • Is this what you are looking for? https://stackoverflow.com/questions/487661/how-do-i-suspend-painting-for-a-control-and-its-children – Kory Gill Jul 27 '17 at 23:06
  • @KoryGill Might very well be. How would you suggest I suspend my main window control before resizing? I don't know which event or message is fired _before_ the resizing takes place. – TheHvidsten Jul 27 '17 at 23:38
  • As stated, your question is too broad. There's not even a good [mcve] that demonstrates the problem. That said, why not just hide the root-level element in the window when resizing starts and show it again when it's over? See https://stackoverflow.com/questions/18552487/determining-when-a-wpf-window-is-being-moved for info about detecting start and finish of resizing. – Peter Duniho Jul 28 '17 at 00:28

0 Answers0