/// <summary> /// Get windows of Spotify Player Window /// </summary> /// <returns></returns> public static Dictionary <IntPtr, MicrosoftSpyValues> GetSpotifyPlayerWindowByProcessName() { Dictionary <IntPtr, MicrosoftSpyValues> handles = new Dictionary <IntPtr, MicrosoftSpyValues>(); foreach (KeyValuePair <IntPtr, MicrosoftSpyValues> window in GetOpenedWindows()) { IntPtr handle = window.Key; MicrosoftSpyValues microsoftSpyValues = window.Value; if (microsoftSpyValues.ProcessName.Contains("Spotify.exe")) { handles.Add(handle, microsoftSpyValues); s_Log.Debug("handle name: " + handle + " | class name: " + microsoftSpyValues.ClassName + " | window name: " + microsoftSpyValues.WindowName + " | process name: " + microsoftSpyValues.ProcessName); } } return(handles); }
/// <summary>Returns a dictionary that contains the handle and title of all the open windows.</summary> /// <returns>A dictionary that contains the handle and title of all the open windows.</returns> private static IDictionary <IntPtr, MicrosoftSpyValues> GetOpenedWindows() { IntPtr shellWindow = GetShellWindow(); Dictionary <IntPtr, MicrosoftSpyValues> windows = new Dictionary <IntPtr, MicrosoftSpyValues>(); EnumWindows(delegate(IntPtr hWnd, int lParam) { if (hWnd == shellWindow) { return(true); } if (!IsWindowVisible(hWnd)) { return(true); } int length = GetWindowTextLength(hWnd); if (length == 0) { return(true); } StringBuilder windowsName = new StringBuilder(length); GetWindowText(hWnd, windowsName, length + 1); windows[hWnd] = new MicrosoftSpyValues(); windows[hWnd].WindowName = windowsName.ToString(); string className = GetWindowClass(hWnd); windows[hWnd].ClassName = className; string processName = GetProcessPath(hWnd); windows[hWnd].ProcessName = processName; return(true); }, 0); return(windows); }