PowerBuilder Forum

Members Login
Username 
 
Password 
    Remember Me  
Post Info TOPIC: Controlling Winamp via the Winamp API


Veteran Member

Status: Offline
Posts: 40
Date:
Controlling Winamp via the Winamp API


This will be my little repository haven of bits and pieces of info I pick up on the topic of making PowerBuilder control Winamp.

With a short lesson on API calls, and setting up a few basic Global External Functions, and the project was off-and-running!

The two needed External Functions are:
1.) SendMessage
2.) FindWindow


-- Edited by thekl0wn on Friday 27th of March 2009 04:25:39 PM

__________________


Veteran Member

Status: Offline
Posts: 40
Date:

Opening an instance of Winamp

The first thing that has to be done, is opening an instance of Winamp.  Now, for the methods I'll be using this, I won't have to worry with Winamp already being open.  However, it would probably be wise to test for Winamp first, using the FindWindow function.

I'll use the Run( ) command to open Winamp.  I've stored two things in a settings file, which I retrieve at runtime and place into variables:

1.)  The current version of Winamp I'm using.  The method I use simply run Winamp, and before playing anything, look at the title in the Taskbar.  This should be the value you store (I only store the numeric value...  5.49).  You will need this in the FindWindow function.

2.)  The path of the folder Winamp is in.  The executable should always be winamp.exe, and there are further reasons related to writing playlist output for only storing the folder of the exectable, rather than the entire executable path.

So, using the ProfileString( ) function, I get the folder, tack on 'winamp.exe', and use the run function...  That runs it.  However, I'm a bit more controlling than that, and prefer to use the /CLASS switch to open Winamp.


__________________


Veteran Member

Status: Offline
Posts: 40
Date:

Once you have executed the Run( ) command, you will have to find the window, using the FindWindowA API call. If you executed Winamp with the /CLASS switch, you should use that class in the FindWindow( ) call.

For example:
String ls_ver, ls_folder, ls_exe, ls_settings

ls_settings = 'Test Winamp Settings.ini' //path to the file with my settings
is_class = 'WAC' //class name of instance of winamp (WinAmpControl) // instance variable
ls_ver = ProfileString( ls_settings, 'WINAMP', 'VERSION', '' ) //winamp version
ls_folder = ProfileString( ls_settings, 'WINAMP', 'FOLDER', '' ) //folder where winamp lives
ls_exe = ls_folder + ' winamp.exe' //add executable name
ls_exe += ' /CLASS="' + ls_class + '"' //add class switch
is_win_name = 'Winamp ' + ls_ver //name which will appear when Winamp first
opened // instance variable

Run( ls_exe, Minimized! ) // run Winamp!


Timer( .2 )

Now personally, I put all of this code in a separate response window, so that I could use the Timer event to find the Winamp window.  Why?  The box I was testing this on was slow, and the version of Winamp was new, which means it loaded anything but fast.  I could have placed my FindWindow calls into a DO UNTIL loop, but that ramped my CPU usage up.  Right after the Run( ) command is executed in the code, I triggered the Timer event.  Inside the Timer event is as follows:

Long ll_h

ll_h = FindWindow( is_class, is_win_name )

IF ll_h <> 0 THEN
CloseWithReturn( This, ll_h ) // return with Winamp handle
END IF


-- Edited by thekl0wn on Wednesday 8th of April 2009 02:19:31 PM

__________________
Page 1 of 1  sorted by
 
Quick Reply

Please log in to post quick replies.

Tweet this page Post to Digg Post to Del.icio.us


Create your own FREE Forum
Report Abuse
Powered by ActiveBoard