-
Notifications
You must be signed in to change notification settings - Fork 73
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
Changed how Spotify is found #18
base: master
Are you sure you want to change the base?
Conversation
I came up with the same solution myself. However, the original code will work even when Spotify is minimized:
You have to use a VS2017 tool called Spy++ to get the window class name. It changed from "SpotifyMainWindow" to "Chrome_WidgetWin_0" a month ago. [edit]: my bad, didn't see you originally came up with the same conclusion. |
Yeah but there could be multiple windows with "Chrome_Widgetwin_0" it's not unique enough |
Now that is an interesting problem, matching a process name against a given window class name. I'm gonna code it tonight using EnumWindows(). My only concern would be how to set up a test environment with multiple windows that share the same class name. |
https://gist.github.com/GenesisFR/de0ad5710fb5eb221b5a239e819728bf Usage: In the case of Spotify, the correct handle seems to always be the first item in the list. If this were to change, you can just pick a different index. I learnt while coding this that there is no perfect solution to this problem. Also, this method takes around 1 second to execute on my computer, versus <1ms for FindWindow(). |
Optimized the method, now it takes around 7ms instead of 1 second to execute. It was caused by Process.GetProcessById() (and to a lesser extent process.ProcessName) that was super slow. |
I realize this is not going to work if it is minimized to systray. I don't have time bandwidth right now to worry about that but I'd love to get to it. Thanks @nachmore for the suggestion on how to make a better fix. Its not totally fixed yet but getting there