private void UpdateSpotifyState(int processId)
        {
            this.ProcessIdChanged = (this.ProcessId != processId);

            this.ProcessId = processId;
            _mainWindow    = IntPtr.Zero;

            if (this.ProcessId != 0)
            {
                //We use pinvoke because Process infos from Process class doesn't contains accurate informations
                _mainWindow = Win32PInvoke.FindWindow(SPOTIFY_WINDOW_CLASS_NAME, null);
                if (_mainWindow != IntPtr.Zero)
                {
                    string windowName = Win32PInvoke.GetWindowText(_mainWindow);
                    this.WindowNameChanged = (this.WindowName != null && windowName != this.WindowName);

                    bool previousIsPlayingState = this.IsPlaying;
                    this.WindowName       = windowName;
                    this.IsPlayingChanged = (previousIsPlayingState != this.IsPlaying);

                    UpdateTrackInfos();
                }
                else
                {
                    _trackInfos.ClearInfos();
                }
            }
        }
Beispiel #2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is Bitmap))
            {
                return(null);
            }

            IntPtr hBitmap = ((Bitmap)value).GetHbitmap();

            try
            {
                return(System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                           hBitmap,
                           IntPtr.Zero,
                           Int32Rect.Empty,
                           BitmapSizeOptions.FromEmptyOptions()));
            }
            catch (Win32Exception)
            {
                return(null);
            }
            finally
            {
                Win32PInvoke.DeleteObject(hBitmap);
            }
        }
 public void PlayNext()
 {
     if (!this.IsSpotifyRunning)
     {
         return;
     }
     Win32PInvoke.PostMessage(_mainWindow, 0x319, IntPtr.Zero, new IntPtr(0xB0000));
 }
        // Based on http://spotifycontrol.googlecode.com/svn/trunk/SpotifyControl/ControllerClass.vb

        public void PlayPause()
        {
            if (!this.IsSpotifyRunning)
            {
                return;
            }
            Win32PInvoke.PostMessage(_mainWindow, 0x319, IntPtr.Zero, new IntPtr(0xE0000));

            PropertyChanged.Notify(() => IsPlaying);
        }
        public void BringToTop()
        {
            if (!this.IsSpotifyRunning)
            {
                return;
            }

            Win32PInvoke.ShowWindow(_mainWindow, Win32PInvoke.WindowShowStyle.ShowNormal);
            Win32PInvoke.SetForegroundWindow(_mainWindow);
            Win32PInvoke.SetFocus(_mainWindow);
        }
        public void VolumeDown()
        {
            if (!this.IsSpotifyRunning)
            {
                return;
            }

            //This will press the ctrl key then send a the KeyDown to the spotifyHandle
            Win32PInvoke.keybd_event(Keys.ControlKey, 0x1D, Win32PInvoke.KeyEvent.None, UIntPtr.Zero);
            Win32PInvoke.PostMessage(_mainWindow, 0x100, new IntPtr((int)Keys.Down), IntPtr.Zero);

            //Wait a little
            Thread.Sleep(100);

            //Release the ctrlkey
            Win32PInvoke.keybd_event(Keys.ControlKey, 0x1D, Win32PInvoke.KeyEvent.KeyUp, UIntPtr.Zero);
        }
Beispiel #7
0
        private void EnableAppInit(RegistryKey parent, string path, string dllname, out int prevEnabled, out string prevStr)
        {
            RegistryKey key = parent.OpenSubKey("Microsoft", true);

            if (key == null)
            {
                prevEnabled = 0; prevStr = ""; return;
            }

            key = key.OpenSubKey("Windows NT", true);
            if (key == null)
            {
                prevEnabled = 0; prevStr = ""; return;
            }

            key = key.OpenSubKey("CurrentVersion", true);
            if (key == null)
            {
                prevEnabled = 0; prevStr = ""; return;
            }

            key = key.OpenSubKey("Windows", true);
            if (key == null)
            {
                prevEnabled = 0; prevStr = ""; return;
            }

            object o = key.GetValue("LoadAppInit_DLLs");

            if (o == null || !(o is int))
            {
                prevEnabled = 0; prevStr = ""; return;
            }
            prevEnabled = (int)o;

            o = key.GetValue("AppInit_DLLs");
            if (o == null || !(o is string))
            {
                prevEnabled = 0; prevStr = ""; return;
            }
            prevStr = (string)o;

            key.SetValue("AppInit_DLLs", Win32PInvoke.ShortPath(Path.Combine(path, dllname)));
            key.SetValue("LoadAppInit_DLLs", (int)1);
        }