Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Runtime.InteropServices;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12.  
  13. namespace SlackyAsi
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         public string getSong()
  23.         {
  24.             try
  25.             {
  26.                 Process processes = Process.GetProcessesByName("spotify").FirstOrDefault();
  27.                 if (processes.MainWindowTitle.Length > 10) // Halb lahendus
  28.                 {
  29.                     var raw = processes.MainWindowTitle;
  30.                     var song = raw.Substring(10, raw.Length - 10);
  31.  
  32.                     return "Now Playing: " + song;
  33.                 }
  34.                 return "N/A";
  35.             } catch {
  36.                 return "Spotify not running.";
  37.             }
  38.         }
  39.  
  40.         protected override void WndProc(ref Message m)
  41.         {
  42.             base.WndProc(ref m);
  43.             if (m.Msg == 0x0312)
  44.             {
  45.                 switch (((int)m.WParam))
  46.                 {
  47.                     case 13370:
  48.                         {
  49.                             MessageBox.Show(getSong());
  50.                             break;
  51.                         }
  52.                 }
  53.             }
  54.         }
  55.  
  56.         private void Form1_Load(object sender, EventArgs e)
  57.         {
  58.             RegisterHotKey(this.Handle, 13370, 0x0002, 120);
  59.         }
  60.  
  61.         private void button1_Click(object sender, EventArgs e)
  62.         {
  63.             MessageBox.Show(getSong());
  64.         }
  65.  
  66.         [DllImport("user32.dll")]
  67.         private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
  68.  
  69.         [DllImport("user32.dll")]
  70.         private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement