Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7642069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:05:45+00:00 2026-05-31T09:05:45+00:00

I am trying to make an application which will notify current playing track’s name

  • 0

I am trying to make an application which will notify current playing track’s
name and artist to the user for that I need to monitor the track change event.

I used Winspector and found out that whenever there is a track change in
spotify WM_SETTEXT message is send.

enter image description here

For this I believe I have to set up a HOOK through my application to look for WM_SETTEXT message sent by the other application.

Now, the problem I am facing is I am not able to get any working sample code to work with. I read the documentation of setwindowshookex and also did some googling but am really lost as I have no background of C# and handling windows messages/events.

So, If you guys can provide me a small working code to wrap my head around setting up hook on another application or if you can direct me to some nice article on how to achieve this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:05:46+00:00Added an answer on May 31, 2026 at 9:05 am

    Here’s a different approach: skip the SetWindowsHook API, and instead use WinEvents, which use SetWinEventHook instead. These are somewhat similar to the windows hooks, in that both involve a callback function that is called at specific events, but WinEvents are far easier to use from C#: you can specify that WinEvents are delivered "out context", meaning the events are posted back to your own process, so you don’t need a separate DLL. (Your code does need to run a message loop on the same thread that called SetWinEventHook, however.)

    It turns out that one of the type of events that WinEvent supports is a ‘name change’ event, which is automatically fired by USER32 whenever the title text of a HWND changes, which seems is what you are looking for. (WinEvents can also be used to track focus changes and various types of state changes; see MSDN for more information.) It’s also fired by other controls when their internal UI changes – eg by a listbox when the text of a list item changes, so we have to do some filtering.

    Here’s some sample code that prints out title changes on any HWND on the desktop – you’ll see it print out a notification as the text in the clock on the taskbar changes, for example. You’ll want to modify this code to filter for just the HWND you’re tracking in Spotify. Also, this code listens to name changes on all processes/threads; you should get the threadID from the target HWND using GetWindowThreadProcessId and only listen to events from that thread.

    Note also that this is something of a fragile approach; if Spotify changes how it displays the text, or changes the format of it, you’ll need to modify your code to keep up with its changes.

    using System;
    using System.Windows;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    
    class NameChangeTracker
    {
        delegate void WinEventDelegate(IntPtr hWinEventHook, uint eventType,
            IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime);
        
        [DllImport("user32.dll")]
        static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr
           hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess,
           uint idThread, uint dwFlags);
        
        [DllImport("user32.dll")]
        static extern bool UnhookWinEvent(IntPtr hWinEventHook);
        
        const uint EVENT_OBJECT_NAMECHANGE = 0x800C;
        const uint WINEVENT_OUTOFCONTEXT = 0;
        
        // Need to ensure delegate is not collected while we're using it,
        // storing it in a class field is simplest way to do this.
        static WinEventDelegate procDelegate = new WinEventDelegate(WinEventProc);
        
        public static void Main()
        {
            // Listen for name change changes across all processes/threads on current desktop...
            IntPtr hhook = SetWinEventHook(EVENT_OBJECT_NAMECHANGE, EVENT_OBJECT_NAMECHANGE, IntPtr.Zero,
                    procDelegate, 0, 0, WINEVENT_OUTOFCONTEXT);
    
            // MessageBox provides the necessary message loop that SetWinEventHook requires.
            // In real-world code, use a regular message loop (GetMessage/TranslateMessage/
            // DispatchMessage etc or equivalent.)
            MessageBox.Show("Tracking name changes on HWNDs, close message box to exit.");
            
            UnhookWinEvent(hhook);
        }
        
        static void WinEventProc(IntPtr hWinEventHook, uint eventType,
            IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
        {
            // filter out non-HWND namechanges... (eg. items within a listbox)
            if(idObject != 0 || idChild != 0)
            {
                return;
            }
            Console.WriteLine("Text of hwnd changed {0:x8}", hwnd.ToInt32()); 
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I was trying to make a calendar application that will display the current
I'm new to android. I'm trying to make an application in which the user
I am trying to make a iPad application which information will popup inside the
I am trying to make an application that will have a set of screens
I am trying to make a application which will check it can ping outside
So I'm trying to make a simple application that quizzes the user. It asks
I am trying to make a component for an application which a user can
Trying to make a django test application which will use stored oracle's procedures to
I am trying to make a simple application which will be used to point
I'm trying to make a vector drawing application using OpenGL which will allow the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.