| | |
| | | var styleFlag = unchecked((uint)flag); |
| | | var currentStyle = unchecked((uint)current); |
| | | var updated = enabled ? currentStyle | styleFlag : currentStyle & ~styleFlag; |
| | | NativeMethods.SetWindowLongPtr(hwnd, NativeMethods.GwlExStyle, new IntPtr(updated)); |
| | | var error = NativeMethods.GetLastError(); |
| | | if (error != 0) |
| | | if (updated == currentStyle) |
| | | { |
| | | _diagnostics.Record( |
| | | DiagnosticSeverity.Warning, |
| | | DiagnosticCodes.Win32InteropFailed, |
| | | $"{operation} failed.", |
| | | new Dictionary<string, string> { ["hwnd"] = hwnd.ToString("X"), ["error"] = error.ToString() }); |
| | | return; |
| | | } |
| | | |
| | | NativeMethods.SetWindowLongPtr(hwnd, NativeMethods.GwlExStyle, new IntPtr(unchecked((int)updated))); |
| | | // Extended-style changes (especially WS_EX_TRANSPARENT) do not reliably update hit-testing |
| | | // until the frame is refreshed. Without this, clearing click-through in edit/safe-input |
| | | // mode can leave the window visually present but permanently unclickable. |
| | | if (!NativeMethods.SetWindowPos( |
| | | hwnd, |
| | | IntPtr.Zero, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | 0, |
| | | NativeMethods.SwpNoMove | NativeMethods.SwpNoSize | NativeMethods.SwpNoZOrder | NativeMethods.SwpNoActivate | NativeMethods.SwpFrameChanged)) |
| | | { |
| | | RecordWin32Failure($"{operation}.SetWindowPos", hwnd); |
| | | } |
| | | } |
| | | |