Just made this for the mIRC users out there. It basically is a alias that fetches the song playing and echoes it out.
/np {
.comopen fb2k Foobar2000.Application.0.7
if ($comerr) { echo comopen failed | halt }
if ($com(fb2k, Playback, 3, dispatch* pb)) {
$com(pb, FormatTitle, 3, bstr, foobar2000 now playing: % $+ artist% - % $+ title% ['[' % $+ album% ']'])
echo $com(pb).result
}
.comclose pb
.comclose fb2k
}
You can edit the format string as long as you make sure to escape percent signs (%) as these have a special meaning in mIRC scripts (variables).
just concatenate using the $+ operator as shown above.
@splint3r:
Services can interact with the desktop via the means of window station API. I used this once when I had to interact with Winamp from a service once.
bool GetCurWinampSong(string &s)
{
#define WM_WA_IPC WM_USER
#define IPC_GETLISTPOS 125
#define IPC_GETPLAYLISTTITLE 212
s="<not playing>";
/* -- Open user's window station "WinSta0". -- */
HWINSTA hWinStaUser = OpenWindowStation("WinSta0", FALSE, MAXIMUM_ALLOWED);
/* -- Set process window station to "WinSta0", this enables the process to
access objects in the window station such as desktops. -- */
if (SetProcessWindowStation(hWinStaUser)) {
/* -- Open user's desktop "Default". -- */
HDESK hDeskUser = OpenDesktop("Default", 0, FALSE, MAXIMUM_ALLOWED);
/* -- Set thread desktop to "Default". -- */
if (SetThreadDesktop(hDeskUser)) {
// Now as we are locked on to user's desktop, we can access users's windows.
HWND hwnd_winamp;
hwnd_winamp = FindWindow("Winamp v1.x", 0);
if (IsWindow(hwnd_winamp))
{
s="<other error>";
DWORD dwPid;
GetWindowThreadProcessId(hwnd_winamp, &dwPid);
HANDLE hProcess;
hProcess = OpenProcess(PROCESS_VM_READ, FALSE, dwPid);
if (!hProcess)
{
s = "<Can not open winamp process>";
return false;
}
int plpos = SendMessage(hwnd_winamp, WM_WA_IPC, 0, IPC_GETLISTPOS);
char *szTitle, *pTitle;
pTitle = (char*)SendMessage(hwnd_winamp, WM_WA_IPC, plpos, IPC_GETPLAYLISTTITLE);
SIZE_T read, datalen;
datalen = 1024;
szTitle = (char*)GlobalAlloc(GPTR, datalen+1);
if (ReadProcessMemory(hProcess, pTitle, szTitle, datalen, &read))
{
s = szTitle;
}
else
{
s = "<Could not get winamp title!>";
}
GlobalFree((HGLOBAL)szTitle);
CloseHandle(hProcess);
}
}
if (hDeskUser) {
CloseDesktop(hDeskUser);
}
}
if (hWinStaUser) {
CloseWindowStation(hWinStaUser);
}
return true;
}