Messagemod, a Winamp 3.x Plugin

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Environment: VC6 SP5, WinXP Pro
Short description: Adds the windowsmessage support to Winamp 3.x with a WAC plugin

Introduction

Many people use Winamp as their main MP3 player, and some have switched from Winamp 2.xx to Winamp 3.xx. Because Winamp 2.xx used the simple WM_COMMAND, WM_USER, and WM_COPYDATA to control play, pause, stop, and so forth, many other programs could control Winamp, too.

In the 3.xx versjon of Winamp, windowsmessages was removed from the player, as we know it. Messagemod is a plugin (WAC) that adds the old functionality. I usally program in MFC, so this library is primary made with MFC.

Messagemod is not complete with ALL the functions, but it has the basics. If you don’t want to learn how to code it yourself, just download the “Winamp 2x Plugin Manager” from Winamp’s home page; that will give you all the functionality that the old 2.xx has.

What Is Needed

Download the Wasabi SDK from http://www.winamp.com/nsdn/.

When you have installed (unpacked) it to somewhere (Default: C:\Wasabi SDK), please read the few text files under the \docs directory to get some info about the SDK before starting. (I’ll guess that you won’t find it useful now, but maybe later.)

Now compile the projects:

  • \Studio—This is the BFC project (project file is not in the bfc directory). Output: bfc.lib
  • \Studio\waclient—Output: waclient.lib

Unpack the sourcecode in the \Studio\Examples\MessageMod directory. Add waclient.lib and bfc.lib to the project.

Before you try to compile, please check the paths in the settings for the debug and working folders. Also, check the “Post-build step” and change it to your new paths.

We use Winamp 3.x (studio.exe) as the debug component (so we can get all the TRACE messages).

What Is a WAC?

A WAC is just a renamed DLL file. I guess the Nullsoft guys wanted to see the difference between component and system DLL’s.

Using the Code

MessageMod.cpp and MessageMod.h:

In these files, we have two classes: CMessageModApp and WACNAME. I have let the WACNAME remain unchanged, as they are in the examples, just because it would be easy to compare them with the other examples. Thanks for the easy template, Nullsoft.

The class CMessageModApp class takes care of the MFC bit of the project. The output is a shared DLL MFC DLL compilation. The class WACNAME takes care of the Winamp 3.xx bit of the project. I’ve added some useful overrides such as “runlevelcb_onShutdown”, but it is kept as simple as possible.

Winamp 3.xx makes a window called “STUDIO”. The old Winamp 2.xx made a window called “Winamp 1.x”. To handle that, I’ve made a dummy window that is named the same. The window created is global, and the handling of the WM-commands are also global.

It is the dummy window that does all the magic; look at the easy windowproc:

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg,
                            WPARAM wParam, LPARAM lParam)
{
  switch(uMsg)
  {
  case WM_CREATE:
    return 0;

  case WM_PAINT:      //The window will show transparent, to avoid
                      //it: A simple paint routine.
    {
      RECT r;
      GetClientRect(hwnd, &r);

      BeginPaint(hwnd, NULL);
      FillRect(GetDC(hwnd), &r, (HBRUSH)
                            GetStockObject(GRAY_BRUSH));
      EndPaint(hwnd, NULL);

      return 0;
    }
  case WM_COMMAND:    //This calls the HandleWMCommand routine
                      //to handle Winamp stuff
    {
      int res=HandleWMCommand(hwnd, wParam,lParam);
      return res;
    }
  case WM_USER:       //This calls the HandleWMUser routine to
                      //handle Winamp stuff
    {
      int res=HandleWMUser(hwnd, wParam,lParam);
      return res;
    }
  }

  return DefWindowProc(hwnd, uMsg, wParam, lParam);
      //Default window message...
}

The HandleWMCommand and HandleWMUser functions handle the different messages. This article will not explain how to use the the Wasabi SDK. It will just show you how it is done. It takes some time to be able to handle the Wasabi. To learn it, you’ll have to work some hours. It is clever to use Winamps forums, also.

When you have compiled the code and Winamp3 is started, you must make a simple program to send WM_COMMAND and WM_USER messages to the dummy window.

HWND Winamp=::FindWindow("Winamp 1.x",NULL);

if(Winamp==NULL)

  Winamp=::FindWindow("Winamp 3.x",NULL);

::SendMessage(Winamp, WM_COMMAND, WINAMP_PLAY, NULL);

Now, with this code above, you should be able to press Play from any other program. The WinampDefs.h is a complete list over the commands. The comments here give an overview of what is added or not.

Known Issues

Many of the functions depend on being in the same process as Winamp. All of these functions has been removed because pointers are not available through processes. If messages are sent before the STUDIO window is created, it will crash. Winamp 3.x loads the plug-ins before the main window.

Updates

Due to a lack of time, many of the features are not implemented, but can easily be done. So, if someone feels a need to finish it, please do so. Mail me if you want to publish it here as updated code, with your credits of course!

Downloads

Download demo project – 56 Kb

Download full version of the demo project – 72 Kb

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read