// Winamp Ctrl.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include <afxdllx.h>
#include "..\plugin.h"
#include "About.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
sPlugin thisplug;
CString m_WATitle;
bool flag_notify;
static AFX_EXTENSION_MODULE WinampCtrlDLL = { NULL, NULL };
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
UNREFERENCED_PARAMETER(lpReserved);
if (dwReason == DLL_PROCESS_ATTACH)
{
if (!AfxInitExtensionModule(WinampCtrlDLL, hInstance))
return 0;
new CDynLinkLibrary(WinampCtrlDLL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
AfxTermExtensionModule(WinampCtrlDLL);
}
return 1; // ok
}
lpsPlugin fnInit(char langue)
{
thisplug.nom="Winamp Ctrl";
thisplug.brief="Permet de controler Winamp sans sortir du jeu.";
thisplug.flags=PLUGIN_FLAG_ON|PLUGIN_FLAG_ABOUT|PLUGIN_TYPE_OUT|PLUGIN_FLAG_V2;
thisplug.version=TPP_VERSION;
thisplug.fnSendIn=NULL;
thisplug.fnSendOut=NULL;
flag_notify=true;
return &thisplug;
}
void fnAbout(void)
{
CAbout dlgAbout;
dlgAbout.DoModal();
}
void Send_sysmsg(LPCTSTR msg,...)
{
int lg_msg;
CString message;
char *pak;
if (thisplug.fnSendIn != NULL)
{
va_list args;
va_start(args, msg);
message.FormatV(msg, args);
lg_msg=message.GetLength();
pak=new char[lg_msg+8];
*(unsigned short *)&pak[0]=0x3F00; // Message systeme
*(unsigned short *)&pak[2]=0x1E00; // ???
*(unsigned short *)&pak[4]=0x0300; // ???
pak[6]=(lg_msg/256)&0xff; // Longueur du message
pak[7]=lg_msg&0xff;
strncpy(&pak[8],message,lg_msg);
// Envoie le message au client
thisplug.fnSendIn(pak,lg_msg+8,false);
delete pak;
}
}
int GetWinampTitle(char *str, int lg)
{
char *title,*p;
*str=0;
HWND hwndWinamp = FindWindow("Winamp v1.x",NULL);
if (hwndWinamp)
{
title=str;
GetWindowText(hwndWinamp,title,lg);
p = title+strlen(title);
while (p >= title)
{
if (!strnicmp(p,"- Winamp",8))
break;
p--;
}
if (p >= title)
p--;
while (p >= title && *p == ' ')
p--;
*++p=0;
lg=p-title;
}
else
lg=0;
return lg;
}
void *fnProcessOut(unsigned char *buff, DWORD &taille, DWORD ¶m)
{
int offset=0,type,commande=0;
type=*(short *)buff;
if (type==0x1B00)
offset=13;
if (type==0x1E00)
offset=17;
param=PLUGIN_PAK_NOCHANGE;
if (flag_notify)
{
CString newTitle;
newTitle.ReleaseBuffer(GetWinampTitle(newTitle.GetBufferSetLength(2048), 2048));
if (m_WATitle.Compare(newTitle))
{
m_WATitle=newTitle;
Send_sysmsg("Playing: %s",m_WATitle);
}
}
if (offset)
{
if (!strnicmp((char *)&buff[offset],"wa_play",7))
commande=40045;
else if (!strnicmp((char *)&buff[offset],"wa_pause",7))
commande=40046;
else if (!strnicmp((char *)&buff[offset],"wa_stop",7))
commande=40047;
else if (!strnicmp((char *)&buff[offset],"wa_prev",7))
commande=40044;
else if (!strnicmp((char *)&buff[offset],"wa_next",7))
commande=40048;
else if (!strnicmp((char *)&buff[offset],"wa_plist",8))
commande=40154;
else if (!strnicmp((char *)&buff[offset],"wa_runcd",8))
commande=40323;
else if (!strnicmp((char *)&buff[offset],"wa_chgon",8))
{
flag_notify=true;
Send_sysmsg("Notification de changement de piste activée");
param=PLUGIN_PAK_DELETE;
}
else if (!strnicmp((char *)&buff[offset],"wa_chgoff",9))
{
flag_notify=false;
Send_sysmsg("Notification de changement de piste désactivée");
param=PLUGIN_PAK_DELETE;
}
else if (!strnicmp((char *)&buff[offset],"wa_title",8))
{
m_WATitle.ReleaseBuffer(GetWinampTitle(m_WATitle.GetBufferSetLength(2048), 2048));
Send_sysmsg(m_WATitle);
// Le pak de doit pas etre envoyé au serveur
param=PLUGIN_PAK_DELETE;
}
if (commande)
{
HWND hwndWinamp = FindWindow("Winamp v1.x",NULL);
if (hwndWinamp)
PostMessage(hwndWinamp,WM_COMMAND, commande, 0); // preferable a SendMessage en cas de plantage de winamp
param=PLUGIN_PAK_DELETE;
}
}
return buff;
}
int GetWinampTitle(char *str, int lg)
{
char *title,*p;
*str=0;
HWND hwndWinamp = FindWindow("Winamp v1.x",NULL);
if (hwndWinamp)
{
title=str;
GetWindowText(hwndWinamp,title,lg);
p = title+strlen(title);
while (p >= title)
{
if (!strnicmp(p,"- Winamp",8))
break;
p--;
}
if (p >= title)
p--;
while (p >= title && *p == ' ')
p--;
*++p=0;
lg=p-title;
}
else
lg=0;
return lg;
}
Cette contribution était de : http://old.wdforge.org/newbb/viewtopic.php?forum=12&topic_id=978&post_id=4012