forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Another annoying Q from me.. API help

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Tue Mar 10, 2009 11:47 pm    Post subject: Another annoying Q from me.. API help Reply with quote

I'm still trying to find a way to know if WinAmp classic is playing, paused or stopped. Only way to do this is via an api, which I have yet to figure out.

I found some vb code that does it, but no clue how to convert it over to VDS.

Anyone willing and able to convert the following for me please?

Code:
Public Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Const WM_USER = &H400
Public Const WA_GETSTATUS = 104
Global hWndWinAMP As Long

Sub Main()
WAClass = "Winamp v1.x" 'Users can change winamp class with a command line IRRC, so yeah.
hWndWinAMP = FindWindow(WAClass, vbNullString)
If hWndWinAMP <> 0 Then
    MsgBox WinAMP_GetStatus
Else
    MsgBox "Could not find Winamp!", vbOKOnly, "WA Status"
End If
End Sub

Function WinAMP_GetStatus() As String
    Dim Status As Long
   
    Status = SendMessage(hWndWinAMP, WM_USER, 0, WA_GETSTATUS)
   
    Select Case Status
       Case 1
          WinAMP_GetStatus = "PLAYING"
       Case 3
          WinAMP_GetStatus = "PAUSED"
       Case Else
          WinAMP_GetStatus = "STOPPED"
    End Select

End Function


And this is from the SDK for Winamp:

Code:
#define IPC_ISPLAYING 104
/* int res = SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_ISPLAYING);
** If it returns 1, it is playing. if it returns 3, it is paused,
** if it returns 0, it is not playing.
*/


Thanks in advance,
~Garrett

P.S. Sorry, I know I've been a bit of a high maintenance one here lately Sad

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Wed Mar 11, 2009 9:37 am    Post subject: Reply with quote

There's more you can do, like FF, RW, Jump to time etc., but I didn't get into all of that.
For some reason trying to Play from the Paused state restarts the song.. so I left that out.
Code:

%%hwnd = @strdel(@winexists("#Winamp v1.x"),1,1)

if @not(%%hwnd)
   warn Winamp is not open.
   exit
end

loadlib user32.dll

REM WM_USER/WM_WA_IPC = $0400
REM IPC_STARTPLAY     = 102
REM IPC_ISPLAYING     = 104
%%ret = @lib(user32,SendMessageA,INT:,%%hwnd,$0400,0,104)
if @equal(%%ret,1)
  info Winamp is currently Playing.
end
if @equal(%%ret,0)
  %y = @ask(Winamp is currently Stopped. Restart Song?)
  if @equal(%y,1)
    %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,$0400,0,102)
  end
end

if @equal(%%ret,3)
  info Winamp is currently Paused.
end

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Wed Mar 11, 2009 11:27 am    Post subject: Reply with quote

Got bored, so I had to try a few more things out.
Code:

%%STARTPLAY     = 102
%%ISPLAYING     = 104
%%GETTIME       = 105
%%SETTIME       = 106
%%GETINFO       = 126
%%GETSHUFFLE    = 250
%%GETREPEAT     = 251
%%SETSHUFFLE    = 252
%%SETREPEAT     = 253
%%WM_USER       = $0400
%%WM_COMMAND    = $0111
%%WABUTTON1     = 40044
%%WABUTTON2     = 40045
%%WABUTTON3     = 40046
%%WABUTTON4     = 40047
%%WABUTTON5     = 40048
%%FF5S          = 40060
%%RW5S          = 40061

Title Winamp Control
  DIALOG CREATE,Winamp Control,-1,0,160,180
  DIALOG ADD,EDIT,EDIT1,7,5,70,19,,,READONLY
  DIALOG ADD,EDIT,EDIT2,7,78,77,19,,,READONLY
  DIALOG ADD,EDIT,EDIT3,62,5,45,19,,,READONLY
  DIALOG ADD,EDIT,EDIT4,62,54,57,19,,,READONLY
  DIALOG ADD,EDIT,EDIT5,62,115,40,19,,,READONLY
  DIALOG ADD,BUTTON,BUTTON1,91,7,30,24,<<,RW 5 Seconds
  DIALOG ADD,BUTTON,BUTTON2,91,46,30,24,>>,FF 5 Seconds
  DIALOG ADD,BUTTON,BUTTON3,124,7,30,24,|<,Previous Track
  DIALOG ADD,BUTTON,BUTTON4,124,46,30,24,>|,Next Track
  DIALOG ADD,CHECK,CHECK1,155,19,60,18,Shuffle,,,CLICK
  DIALOG ADD,CHECK,CHECK2,155,90,60,18,Repeat,,,CLICK
  DIALOG ADD,BUTTON,Play,85,86,64,18,Play
  DIALOG ADD,BUTTON,Stop,129,86,64,18,Stop
  DIALOG ADD,BUTTON,Pause,108,86,64,18,Pause
  DIALOG ADD,TRACKBAR,TRACKBAR1,34,1,159,24,0,,,HORIZONTAL,CLICK
  DIALOG DISABLE,EDIT1
  DIALOG DISABLE,EDIT2
  DIALOG DISABLE,EDIT3
  DIALOG DISABLE,EDIT4
  DIALOG DISABLE,EDIT5
  DIALOG SHOW
  loadlib user32.dll
:Timer
  %%hwnd = @strdel(@winexists("#Winamp v1.x"),1,1)
  if @not(%%hwnd)
    dialog set,edit1,Not Open.
    dialog disable,trackbar1
    dialog disable,button1
    dialog disable,button2
    dialog disable,button3
    dialog disable,button4
    dialog disable,check1
    dialog disable,check2
    dialog disable,play
    dialog disable,stop
    dialog disable,pause
    goto evloop
  end
  dialog enable,trackbar1
  dialog enable,button1
  dialog enable,button2
  dialog enable,button3
  dialog enable,button4
  dialog enable,check1
  dialog enable,check2
  dialog enable,play
  dialog enable,stop
  dialog enable,pause
  %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_USER,0,%%ISPLAYING)
  if @equal(%%ret,1)
    dialog set,edit1,Playing.
  end
  if @equal(%%ret,0)
    dialog set,edit1,Stopped.
  end

  if @equal(%%ret,3)
    dialog set,edit1,Paused.
  end
 
  %%time = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_USER,1,%%GETTIME)
  %%tmin = @div(%%time,60)
  %%tsec = @mod(%%time,60)
 
  %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_USER,0,%%GETTIME)
  %%time = @prod(%%time,10)
  if @both(@greater(%%ret,0),@greater(%%time,0))
    %%currpos = @format(@div(%%ret,%%time),3.0)
  end
 
  %%ctime = @div(%%ret,1000)
  %%cmin = @div(%%ctime,60)
  %%csec = @mod(%%ctime,60)
  if @equal(@len(%%tsec),1)
    %%tsec = 0%%tsec
  end
  if @equal(@len(%%csec),1)
    %%csec = 0%%csec
  end
  dialog set,edit2,%%cmin:%%csec/%%tmin:%%tsec
  dialog set,trackbar1,%%currpos
 
  %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_USER,0,%%GETINFO)
  dialog set,edit3,%%ret Khz
  %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_USER,1,%%GETINFO)
  dialog set,edit4,%%ret Kbps
  %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_USER,2,%%GETINFO)
  dialog set,edit5,%%ret Ch
 
  %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_USER,0,%%GETSHUFFLE)
  if @equal(%%ret,1)
    dialog set,check1,1
  else
    dialog set,check1
  end
 
  %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_USER,0,%%GETREPEAT)
  if @equal(%%ret,1)
    dialog set,check2,1
  else
    dialog set,check2
  end
:Evloop
  wait event,1
  goto @event()
:Check1CLICK
  if @equal(@dlgtext(check1),1)
    %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_USER,1,%%SETSHUFFLE)
  else
    %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_USER,0,%%SETSHUFFLE)
  end
  goto evloop
:Check2CLICK
  if @equal(@dlgtext(check2),1)
    %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_USER,1,%%SETREPEAT)
  else
    %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_USER,0,%%SETREPEAT)
  end
  goto evloop
:PlayBUTTON
  %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_COMMAND,%%WABUTTON2,0)
  goto evloop
:PauseBUTTON
  %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_COMMAND,%%WABUTTON3,0)
  goto evloop
:StopBUTTON
  %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_COMMAND,%%WABUTTON4,0)
  goto evloop
:BUTTON1BUTTON
  %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_COMMAND,%%RW5S,0)
  goto evloop
:BUTTON2BUTTON
  %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_COMMAND,%%FF5S,0)
  goto evloop
:BUTTON3BUTTON
  %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_COMMAND,%%WABUTTON1,0)
  goto evloop
:BUTTON4BUTTON
  %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_COMMAND,%%WABUTTON5,0)
  goto evloop
:TRACKBAR1CLICK
  %%trackpos = @prod(@dlgtext(trackbar1),10)
  %%time = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_USER,1,%%GETTIME)
  %%newpos = @prod(%%time,%%trackpos)
  %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,%%WM_USER,%%newpos,%%SETTIME)
  goto evloop
:Close
  exit

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Wed Mar 11, 2009 5:35 pm    Post subject: Reply with quote

OMG! Thank you thank you thank you!!!! I had the other codes from previous posts here, but just could not get any code working to find out when Winamp was playing or paused. Now my program is finally complete!!!!

The following code allows you to use your media keys from your media keyboard to control Winamp Classic. Build your own code around it though, this is just the eventloop and timer loop

Code:
  LOADLIB USER32
  %%KeyPresses = 0

:EVENTLOOP
  WAIT EVENT,"0.1"
  %E = @event()
  IF %E
    GOTO %E
  END
  GOTO EVENTLOOP

:TIMER
  %%hwnd = @strdel(@winexists("#Winamp v1.x"),1,1)
  IF @not(%%hwnd)
    GOTO EVENTLOOP
  END
  %%VK_MEDIA_NEXT_TRACK = 0
  %%VK_MEDIA_PREV_TRACK = 0
  %%VK_MEDIA_STOP = 0
  %%VK_MEDIA_PLAY_PAUSE = 0
  %%VK_CONTROL = 0
  %%VK_MEDIA_NEXT_TRACK = @lib(user32,GetAsyncKeyState,INT:,INT:$B0)
  %%VK_MEDIA_PREV_TRACK = @lib(user32,GetAsyncKeyState,INT:,INT:$B1)
  %%VK_MEDIA_STOP = @lib(user32,GetAsyncKeyState,INT:,INT:$B2)
  %%VK_MEDIA_PLAY_PAUSE = @lib(user32,GetAsyncKeyState,INT:,INT:$B3)
  %%VK_CONTROL = @lib(user32,GetAsyncKeyState,INT:,INT:$11)
  IF @not(@equal(%%VK_MEDIA_NEXT_TRACK,0))
    REPEAT
      WAIT "0.1"
      %%VK_MEDIA_NEXT_TRACK = @lib(user32,GetAsyncKeyState,INT:,INT:$B0)
    UNTIL @equal(%%VK_MEDIA_NEXT_TRACK,0)
    %A = @sendmsg(#Winamp v1.x,$0111,40048,)
  END
  IF @not(@equal(%%VK_MEDIA_PREV_TRACK,0))
    REPEAT
      WAIT "0.1"
      %%VK_MEDIA_PREV_TRACK = @lib(user32,GetAsyncKeyState,INT:,INT:$B1)
    UNTIL @equal(%%VK_MEDIA_PREV_TRACK,0)
    %A = @sendmsg(#Winamp v1.x,$0111,40044,)
  END
  IF @not(@equal(%%VK_MEDIA_STOP,0))
    REPEAT
      WAIT "0.1"
      %%VK_MEDIA_STOP = @lib(user32,GetAsyncKeyState,INT:,INT:$B2)
    UNTIL @equal(%%VK_MEDIA_STOP,0)
    %A = @sendmsg(#Winamp v1.x,$0111,40047,)
  END
  IF @not(@equal(%%VK_MEDIA_PLAY_PAUSE,0))
    REPEAT
      WAIT "0.1"
      %%VK_MEDIA_PLAY_PAUSE = @lib(user32,GetAsyncKeyState,INT:,INT:$B3)
    UNTIL @equal(%%VK_MEDIA_PLAY_PAUSE,0)
    %%ret = @lib(user32,SendMessageA,INT:,%%hwnd,$0400,0,104)
    IF @equal(%%ret,0)
      REM STOPPED
      %A = @sendmsg(#Winamp v1.x,$0111,40045,)
    END
    IF @equal(%%ret,1)
      REM PLAYING
      %A = @sendmsg(#Winamp v1.x,$0111,40046,)
    END
    IF @equal(%%ret,3)
      REM PAUSED
      %A = @sendmsg(#Winamp v1.x,$0111,40046,)
    END
  END
  GOTO EVENTLOOP

:CLOSE
  FREELIB USER32
  EXIT

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Wed Mar 11, 2009 5:43 pm    Post subject: Reply with quote

Geez, you could at least say thank you Wink
I never really looked at the Winamp SDK before, although I did have it.. I must have downloaded it when you mentioned it before but never got around to it.
Opened my eyes to a few things that could have been useful a long time ago when I actually used Winamp... I've fallen to the dark side and just use WMP now.
Glad it helped.

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Wed Mar 11, 2009 5:58 pm    Post subject: Reply with quote

Laughing Razz Very Happy

I still prefer to use Winamp Classic to this day. Mainly because it requires less resources and! Tada! The random play on Winamp Classic seems to work better than any other player I've ever tried, including Windows Media Player and iTunes. Also, it's so much easier making and editing playlists with Winamp Classic. Windows Media Player seems like a nightmare to me working with playlists.

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Thu Mar 12, 2009 2:37 pm    Post subject: Reply with quote

Wow can you still download Winamp?
_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Thu Mar 12, 2009 6:31 pm    Post subject: Reply with quote

I believe you can still get Winamp Classic on the net in many places. As well as some of the very first versions of it ever released. Just google the following quoted text for a ton of returns on it: "download winamp classic"
_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group