0

I've written a WndProc to know if current Window is flashing. It is as follows:

    private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        var retVal = IntPtr.Zero;

        switch (msg)
        {
            case (int)WindowsMessages.NCACTIVATE:
                retVal = WindowsNative.DefWindowProc(hwnd, WindowsMessages.NCACTIVATE, new IntPtr(1), new IntPtr(-1));
                IsFlashing = (int)wParam == 0;
                break;
        }

        return retVal;
    }

Now this is working perfectly with any Window except for when their SizeToContent property is set to Height (I haven't tested WidthAndHeight but I assume it won't work either); in which case, the WM_NCACTIVATE message is not sent to the Window at all. All of my windows are using custom look and feel (using WPF WindowChrome). Do you possibly know the reason or can help me with this problem?

Javid
  • 2,755
  • 2
  • 33
  • 60
  • I wonder if you noticed that `SizeToContent` is prompted in MSDN,you cannot set or get this property when a window is hosted in a browser. – Strive Sun Apr 16 '19 at 09:08
  • @StriveSun-MSFT: Hosted in a browser? I didn't mean the browser Chrome, I meant WPF WindowChrome. – Javid Apr 17 '19 at 04:58

1 Answers1

0

In theory, WM_NCACTIVTE message events are not blocked for no reason.

If you can, I suggest you redefine WM_NCACTIVATE.

like this:

    private const uint WM_NCACTIVATE = 0x0086;

    private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        var retVal = IntPtr.Zero;

        switch (msg)
        {
            case (int)WindowsMessages.NCACTIVATE:
            retVal = WindowsNative.DefWindowProc(hwnd, WindowsMessages.NCACTIVATE, new IntPtr(1), new IntPtr(-1));
            IsFlashing = (int)wParam == 0;
            break;
        }

    return retVal;
    }

Hope to help you.

Strive Sun
  • 5,988
  • 1
  • 9
  • 26
  • So are you suggesting that this problem is because of the constant? I don't think so: `NCACTIVATE = 0x0086` – Javid Apr 20 '19 at 13:53
  • It must be because of some API calls or behaviors `SizeToContent` makes. – Javid Apr 20 '19 at 13:54
  • @Javid As far as the code you're posting is concerned, there's no problem with callback functions at least. – Strive Sun Apr 22 '19 at 00:54