Dec 10, 2011 08:40 AM
(This post was last modified: Dec 10, 2011 08:41 AM by nathan72389.)
a few months back b4 my old laptop died i was working on a project that would allow me to update my signature with the song info that i was listening to. (dynamic sig). at the end of the day, i got it all working, but there was one part that so simple to do i almost couldent believe that i ws googling how to do it.
Get the song info.
well, after staring at pointless vb6 code that used alot of api's (find window....ect) i decided to update the whole mess that everyone had posted and do it up in pure .net.
here we go...
![[Image: attachment.php?aid=901]](https://hackforums.net/attachment.php?aid=901)
from there i could simply upload the string to my host and generate the image with the string.
but anyway, thats for another day, lets look at how to get that info.
From doing a bit of googling i found out that there was just a few ways that would work, the first was simply making a plugin that would export the info. The problem with this is that, (in short) my delphi skills suck. The other option (which was the most popular) is to simply grab the window title, so lets do that.
Pow!
ok, lets walk through there
declare a new timer (yeah yeah, blah blah threads, a timer works just fine)
when the form loads, start the timer
when the timer ticks simply use the function to get the window title and check it aginst the previous one to see if it changed i set it to check the length also because i was getting a single char blank string.
then simply insert it at the top of the listview.
the great thing about this is that it works even when my media player is minimized.
so, there we go...
go have some fun.
Get the song info.
well, after staring at pointless vb6 code that used alot of api's (find window....ect) i decided to update the whole mess that everyone had posted and do it up in pure .net.
here we go...
from there i could simply upload the string to my host and generate the image with the string.
but anyway, thats for another day, lets look at how to get that info.
From doing a bit of googling i found out that there was just a few ways that would work, the first was simply making a plugin that would export the info. The problem with this is that, (in short) my delphi skills suck. The other option (which was the most popular) is to simply grab the window title, so lets do that.
Code
Public Class Form1
Dim WithEvents tTimer As New Timer
Dim Last As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tTimer.Interval = 100
tTimer.Start()
End Sub
Dim cur As String
Private Sub tTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tTimer.Tick
cur = FindProcessTitle("mediamonkey")
If cur IsNot Nothing And cur.Length > 10 Then
If Not Last = cur Then
Last = cur
ListView1.Items.Insert(0, New ListViewItem With {.Text = cur})
ListView1.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent)
End If
End If
End Sub
Function FindProcessTitle(ByVal processName As String) As String
If Process.GetProcessesByName(processName)(0) IsNot Nothing Then
Return Process.GetProcessesByName(processName)(0).MainWindowTitle
Else
Return Nothing
End If
End Function
End ClassPow!
ok, lets walk through there
declare a new timer (yeah yeah, blah blah threads, a timer works just fine)
when the form loads, start the timer
when the timer ticks simply use the function to get the window title and check it aginst the previous one to see if it changed i set it to check the length also because i was getting a single char blank string.
then simply insert it at the top of the listview.
the great thing about this is that it works even when my media player is minimized.
so, there we go...
go have some fun.

