private static void ShowSpotify() { if (Spotify.IsRunning()) { var hWnd = Spotify.GetSpotify(); // check Spotify's current window state var placement = new Win32.WINDOWPLACEMENT(); Win32.GetWindowPlacement(hWnd, ref placement); int showCommand = Win32.Constants.SW_SHOW; // if Spotify is minimzed we need to send a restore so that the window // will come back exactly like it was before being minimized (i.e. maximized // or otherwise) otherwise if we call SW_RESTORE on a currently maximized window // then instead of staying maximized it will return to normal size. if (placement.showCmd == Win32.Constants.SW_SHOWMINIMIZED) { showCommand = Win32.Constants.SW_RESTORE; } Win32.ShowWindow(hWnd, showCommand); Win32.SetForegroundWindow(hWnd); Win32.SetFocus(hWnd); } }
private static void ShowSpotify() { if (Spotify.IsAvailable()) { Win32.ShowWindow(Spotify.GetSpotify(), 1); Win32.SetForegroundWindow(Spotify.GetSpotify()); Win32.SetFocus(Spotify.GetSpotify()); } }
private static void Minimize() { var remainingSleep = 2000; IntPtr hWnd; // Since Minimize is often called during startup, the hWnd is often not created yet // wait a maximum of remainingSleep for it to appear and then minimize it if it did. while ((hWnd = Spotify.GetSpotify()) == IntPtr.Zero && remainingSleep > 0) { Thread.Sleep(100); remainingSleep -= 100; } if (hWnd != IntPtr.Zero) { // disgusting but sadly neccessary. Let Spotify initialize a bit before minimizing it // otherwise the window hides itself and doesn't respond to taskbar clicks. // I tried to work around this by waiting for the window size to initialize (via GetWindowRect) // but that didn't work, there is some internal initialization that needs to occur. Thread.Sleep(500); Win32.ShowWindow(hWnd, Win32.Constants.SW_SHOWMINIMIZED); } }
private static void Minimize() { var hWnd = Spotify.GetSpotify(); Win32.ShowWindow(hWnd, Win32.Constants.SW_SHOWMINIMIZED); }