Code:
#define WM_WA_IPC WM_USER
#define IPC_GETOUTPUTTIME 105
#define IPC_ISPLAYING 104
char boo[256];
char boo2[256];
char boo3[256];
char boo4[256];
char SongDuration[256];
char CurrentPosition[256];
unsigned int pos;
unsigned int length;
long SendWinampMessage( unsigned int iMsg, WPARAM wParam, LPARAM lParam )
{
HWND hWinAmp = FindWindowA( "Winamp v1.x", 0 );
DWORD ret = 0;
SendMessageTimeoutA( hWinamp, iMsg, wParam, lParam, SMTO_BLOCK, 100, &ret );
return dwRet;
}
int GetSongStatus( )
{
return SendWinampMessage( WM_WA_IPC, 0, IPC_ISPLAYING );
}
void GetTime( )
{
HWND winamp = FindWindow( "Winamp v1.x", NULL );
float F_POS = SendMessage( winamp, WM_WA_IPC, 0, IPC_GETOUTPUTTIME );
float F_LENGTH = SendMessage( winamp, WM_WA_IPC, 1, IPC_GETOUTPUTTIME );
pos = ( unsigned int )F_POS;
length = ( unsigned int )F_LENGTH;
}
void PrintTime( const unsigned int Value )
{
if( Value == 0 )
sprintf_s(boo,"00");
else if( Value < 10 )
sprintf_s(boo,"0%i",Value);
else
sprintf_s(boo,"%i",Value);
}
void PrintTime2( const unsigned int Value )
{
if( Value == 0 )
sprintf_s(boo2,"00");
else if( Value < 10 )
sprintf_s(boo2,"0%i",Value);
else
sprintf_s(boo2,"%i",Value);
}
void PrintTime3( const unsigned int Value )
{
if( Value == 0 )
sprintf_s(boo3,"00");
else if( Value < 10 )
sprintf_s(boo3,"0%i",Value);
else
sprintf_s(boo3,"%i",Value);
}
void PrintTime4( const unsigned int Value )
{
if( Value == 0 )
sprintf_s(boo4,"00");
else if( Value < 10 )
sprintf_s(boo4,"0%i",Value);
else
sprintf_s(boo4,"%i",Value);
}
void CalculateSongTimes( )
{
const static unsigned int MILISECONDS_IN_AN_HOUR = 3600000;
const static unsigned int MILISECONDS_IN_A_MINUTE = 60000;
const static unsigned int MILISECONDS_IN_A_SECOND = 1000;
const static unsigned int SECONDS_IN_AN_HOUR = 3600;
const static unsigned int SECONDS_IN_A_MINUTE = 60;
if( length > 0 )
{
PrintTime( (unsigned int)((length % SECONDS_IN_AN_HOUR) / SECONDS_IN_A_MINUTE) );
PrintTime2( (unsigned int)((length % SECONDS_IN_AN_HOUR) % SECONDS_IN_A_MINUTE) );
sprintf_s(SongDuration,"%s:%s",boo,boo2);
}
else
sprintf_s(SongDuration,"00:00");
if( pos > 0 )
{
PrintTime3( (unsigned int)((pos % MILISECONDS_IN_AN_HOUR) / MILISECONDS_IN_A_MINUTE) );
PrintTime4( (unsigned int)(((pos % MILISECONDS_IN_AN_HOUR) % MILISECONDS_IN_A_MINUTE) / MILISECONDS_IN_A_SECOND) );
sprintf_s(CurrentPosition,"%s:%s",boo3,boo4);
}
else
sprintf_s(CurrentPosition,"00:00");
int Status = GetSongStatus( );
if( Status == 0 )//1 - Playing | 3 - Paused | 0 - Stopped
sprintf_s(CurrentPosition,"00:00");
} There's no what to explain-as title says, you can get song length and current play position from WinAmp with this code.Just call GetTime( ) and CalculateSongTimes( ) functions, after that use "SongDuration" and "CurrentPosition" chars to get what you need.