Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected "InputSiteWindowClass" window appears in WinUI 3 app #10319

Open
manoj-sunagar opened this issue Jan 27, 2025 · 13 comments
Open

Unexpected "InputSiteWindowClass" window appears in WinUI 3 app #10319

manoj-sunagar opened this issue Jan 27, 2025 · 13 comments
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners

Comments

@manoj-sunagar
Copy link

manoj-sunagar commented Jan 27, 2025

Describe the bug

I am experiencing an issue in my WinUI 3 application where an unexpected window with the class name InputSiteWindowClass appears, even though I am only initializing the main Window. This window is not explicitly created or referenced in my code, and it seems to be related to internal framework behavior, possibly related to input handling or focus management.

This issue doesn't occur in a similar app built using the same version of WinUI 3, which makes me believe it could be a bug related to how the framework handles certain window classes.

Steps to reproduce the bug

Create a basic WinUI 3 app (or use the sample app from GitHub).

Launch the app and inspect the UI hierarchy using Inspect.exe or Spy++.
Observe that an unexpected window with the class name InputSiteWindowClass appears, which is not explicitly instantiated in the code.

Expected behavior

Only the main Window should appear with the specified content. The InputSiteWindowClass should not be instantiated unless it is a part of the framework’s internal handling of input, which should be transparent to the user.

Screenshots

Image

NuGet package version

WinUI 3 - Windows App SDK 1.6.3: 1.6.241114003

Windows version

Windows 11 (24H2): Build 26100

Additional context

The unexpected window is detected by Testing Tool and appears as a greyed-out object.
Tried debugging the code and checking for window creation in OnLaunched, but no explicit reference to InputSiteWindowClass is found.
Similar behavior is observed in a fresh WinUI 3 app that follows the same structure, but not in another app built with WinUI 3.
Other tools like Inspect.exe and Spy++ also show this window in the UI tree.

@castorix
Copy link

This issue doesn't occur in a similar app built using the same version of WinUI 3, which makes me believe it could be a bug related to how the framework handles certain window classes.

It is not a bug, it is created by Microsoft.UI.Input when a new window is created

@manoj-sunagar
Copy link
Author

@castorix thanks for the feedback,the newly created "inputsitewindow" is greyed out in the hierarchy. And do you have any idea on this ? Because I checkedwith spy++ as well, any solution to make it visible? Or how to make it visible?thanks in advance .

@riverar
Copy link
Contributor

riverar commented Jan 28, 2025

There are many non-visible windows used throughout the OS and its apps. Is it causing problems for you?

@manoj-sunagar
Copy link
Author

@riverar ,Hi, my goal is to detect objects inside the application and use features like Object Spy in TestComplete. However, since this new window is introduced and greyed out, I cannot detect any objects within it. This issue occurs with all apps built using the WinUI3 framework.

Is there any solution to make this window visible or bypass it? I am struggling to find the root cause, but I suspect the window is being greyed out by the application itself. Any thoughts or suggestions?

@riverar
Copy link
Contributor

riverar commented Jan 28, 2025

It's an internal window, leave it alone? Why do you want to interact with it?

@manoj-sunagar
Copy link
Author

There are objects under this window and this window is blocking me to detect those objects (need help ), any solution to make it visible or bypass this? and can you confirm that this window is from Microsoft.UI.Input

this is the image:
Image

this is the image of a working app where i am able to detect the underneath objects.

Image

@castorix
Copy link

@castorix thanks for the feedback,the newly created "inputsitewindow" is greyed out in the hierarchy. And do you have any idea on this ? Because I checkedwith spy++ as well, any solution to make it visible? Or how to make it visible?thanks in advance .

It is greyed because WS_VISIBLE is not set
You can add this style (it won't be visible as its size is 0 to not overlap controls and it is a child) :

private IntPtr hWndMain = IntPtr.Zero;

        hWndMain = WinRT.Interop.WindowNative.GetWindowHandle(this);
        IntPtr hWndSiteBridge = FindWindowEx(hWndMain, IntPtr.Zero, "Microsoft.UI.Content.DesktopChildSiteBridge", null);
        IntPtr hWndInputSite = FindWindowEx(hWndSiteBridge, IntPtr.Zero, "InputSiteWindowClass", null);
        ShowWindow(hWndInputSite, SW_SHOWNORMAL);

with :

    [DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
    public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

    [DllImport("User32.dll", SetLastError = true)]
    public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

    public const int SW_HIDE = 0;
    public const int SW_SHOWNORMAL = 1;
    public const int SW_SHOWMINIMIZED = 2;
    public const int SW_SHOWMAXIMIZED = 3;

@manoj-sunagar
Copy link
Author

@castorix Thanks ! it worked but the UIA tree is still greyed out, no idea why.

Image

@manoj-sunagar
Copy link
Author

using System;
using System.Runtime.InteropServices;


namespace App1
{
    public partial class App : Application
    {
        public static class NativeMethods
        {
            [DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
            public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

            [DllImport("User32.dll", SetLastError = true)]
            public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

            public const int SW_HIDE = 0;
            public const int SW_SHOWNORMAL = 1;
            public const int SW_SHOWMINIMIZED = 2;
            public const int SW_SHOWMAXIMIZED = 3;
        }

        public static Window CurrentWindow = Window.Current;
        public IServiceProvider Services { get; }
        public new static App Current => (App)Application.Current;
        public string AppVersion { get; set; } = AssemblyInfoHelper.GetAssemblyVersion();
        public string AppName { get; set; } = "App1";

        public static T GetService<T>() where T : class
        {
            if ((App.Current as App)!.Services.GetService(typeof(T)) is not T service)
            {
                throw new ArgumentException($"{typeof(T)} needs to be registered in ConfigureServices within App.xaml.cs.");
            }

            return service;
        }

        public App()
        {
            Services = ConfigureServices();
            this.InitializeComponent();
        }

        private static IServiceProvider ConfigureServices()
        {
            var services = new ServiceCollection();
            services.AddSingleton<IThemeService, ThemeService>();
            services.AddSingleton<IJsonNavigationViewService>(factory =>
            {
                var json = new JsonNavigationViewService();
                return json;
            });

            services.AddTransient<MainViewModel>();

            return services.BuildServiceProvider();
        }

        private void MakeInputSiteWindowVisible()
        {
            IntPtr hWndMain = WinRT.Interop.WindowNative.GetWindowHandle(CurrentWindow);
            IntPtr hWndSiteBridge = NativeMethods.FindWindowEx(hWndMain, IntPtr.Zero, "Microsoft.UI.Content.DesktopChildSiteBridge", null);
            IntPtr hWndInputSite = NativeMethods.FindWindowEx(hWndSiteBridge, IntPtr.Zero, "InputSiteWindowClass", null);

            if (hWndInputSite != IntPtr.Zero)
            {
                NativeMethods.ShowWindow(hWndInputSite, NativeMethods.SW_SHOWNORMAL);
                Console.WriteLine("InputSiteWindowClass made visible.");
            }
            else
            {
                Console.WriteLine("InputSiteWindowClass not found.");
            }
        }

        protected override void OnLaunched(LaunchActivatedEventArgs args)
        {
            CurrentWindow = new Window();

            CurrentWindow.AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
            CurrentWindow.AppWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;

            if (CurrentWindow.Content is not Frame rootFrame)
            {
                CurrentWindow.Content = rootFrame = new Frame();
            }

            rootFrame.Navigate(typeof(MainPage));

            CurrentWindow.Title = CurrentWindow.AppWindow.Title = $"{AppName} v{AppVersion}";
            CurrentWindow.AppWindow.SetIcon("Assets/icon.ico");

            CurrentWindow.Activate();
            MakeInputSiteWindowVisible();

            // Set a breakpoint here
            //CurrentWindow = new Window();
            //CurrentWindow.Content = new Frame();
            //CurrentWindow.Activate();
        }
    }
}


this is jus the sample app , as same as https://github.com/microsoft/WinUI-Gallery

@castorix
Copy link

If I use Inspect, I don't get this hierarchy for a sample app (same as UI Automation interfaces)

@manoj-sunagar
Copy link
Author

that image was from testcomplete which is testing tool, i have used inspect as well .does wiui3 has some problem with UIA? this inpusitewindowclass is not allowing me to detect the objects.

Image

@castorix
Copy link

From my tests with Inspect, the children of "InputSiteWindowClass" window are just the XAML controls

@manoj-sunagar
Copy link
Author

Image

this is for the sample app https://github.com/microsoft/WinUI-Gallery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners
Projects
None yet
Development

No branches or pull requests

3 participants