Exemplo n.º 1
0
        public WindowTitleWatcher(IntPtr hWnd)
        {
            if (hWnd == IntPtr.Zero)
            {
                throw new ArgumentException($"{nameof(hWnd)} is null", nameof(hWnd));
            }

            this.hWnd         = hWnd;
            this.CurrentTitle = NativeWindows.GetWindowTitle(this.hWnd);
        }
Exemplo n.º 2
0
 private void CheckTimer_Elapsed(object sender, ElapsedEventArgs e)
 {
     lock (this.currentTitleLock)
     {
         string oldTitle = this.CurrentTitle;
         string newTitle = NativeWindows.GetWindowTitle(this.hWnd);
         if (!string.Equals(oldTitle, newTitle, StringComparison.CurrentCulture))
         {
             this.CurrentTitle = newTitle;
             this.OnTitleChanged(oldTitle, newTitle);
         }
     }
 }
Exemplo n.º 3
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());
        }