Exemplo n.º 1
0
        public static bool IsMainSpotifyProcess(uint pid)
        {
            List <IntPtr> windows = NativeWindows.GetProcessWindows(pid);
            IntPtr        hWnd    = windows.FirstOrDefault(h => spotifyMainWindowNames.Contains(NativeWindows.GetClassName(h)));

            return(hWnd != IntPtr.Zero);
        }
Exemplo n.º 2
0
        public static IntPtr GetMainWindowHandle(uint pid)
        {
            if (pid == 0)
            {
                return(IntPtr.Zero);
            }

            List <IntPtr> windows             = NativeWindows.GetProcessWindows(pid);
            List <IntPtr> possibleMainWindows = windows.Where(h =>
            {
                string className  = NativeWindows.GetClassName(h);
                string windowName = NativeWindows.GetWindowTitle(h);
                return(!string.IsNullOrWhiteSpace(windowName) && spotifyMainWindowNames.Contains(className));
            }).ToList();

            if (possibleMainWindows.Count > 1)
            {
                IEnumerable <string> classNames = possibleMainWindows.Select(h => $"\"{NativeWindows.GetClassName(h)}\"");
                logger.Warn($"More than one ({possibleMainWindows.Count}) possible main windows located for Spotify: {string.Join(", ", classNames)}");
            }

            return(possibleMainWindows.FirstOrDefault());
        }