예제 #1
0
 private static void WinEventProc_start(IntPtr hWinEventHook_start, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
 {
     if (idObject != 0 || idChild != 0)
     {
         return;
     }
     //specifically looking for spotify via hwnd_spotify
     //across all process(hwnd).
     if (!psi.isSpotifyAvailable() || hwnd.ToInt32() != psi.getSpotifyWindowHandle().ToInt32())
     {
         return;
     }
     //Console.WriteLine("checking hwnd");
     if (eventType != EVENT_OBJECT_CREATE)
     {
         return;
     }
     //Console.WriteLine("create event");
     if (SetWinEventHook(0x0800c, 0x800c, IntPtr.Zero, procDelegate, Convert.ToUInt32(psi.getSpotifyPID()), 0, 0) ==
         IntPtr.Zero)
     {
         throw new Exception($"SetWinEventHook failed with{Marshal.GetLastWin32Error()}");
     }
 }
예제 #2
0
    //Constructor for NameChangeTracker
    public NameChangeTracker(ToastForm myForm)
    {
        NameChangeTracker.myForm = myForm;
        psi    = new ProcessInformation();
        tmd    = new TrackMetadata();
        notify = new Notify();
        //Console.WriteLine(psi.getSpotifyPID());

        // Listen for name change changes for spotify(check pid!=0).
        hWinEventHook = SetWinEventHook(0x0800c, 0x800c, IntPtr.Zero, procDelegate, Convert.ToUInt32(psi.getSpotifyPID()), 0, 0);
        // Listen for create window event across all processes/threads on current desktop.(check pid=0)
        hWinEventHook_start = SetWinEventHook(0x00008000, 0x00008000, IntPtr.Zero, procDelegate_start, 0, 0, 0);
    }