Go Back   Winamp Forums > Developer Center > Winamp Development

Reply
Thread Tools Search this Thread Display Modes
Old 10th August 2003, 11:42   #1
Pamplemousse_mk
Registered User
 
Join Date: Jun 2002
Posts: 2
how to receive Winamp command message?

Hello,

I would like to develop a general purpose plug-in. I would like to intercept Winamp message, i.e. for ex. when user push the Play button, my plugin will execute "void myFunction()".

I have downloaded gen_test4 project from this forum (thanks to the authors). I have tried to do this, as I have read in MSDN:

in gen_test4.h:
class CGen_test4App : public CWinApp {
public:
BEGIN_MSG_MAP( CGen_test4App )
MESSAGE_HANDLER(40045, myFunction)
END_MSG_MAP()
...}

in gen_test4.cpp
BEGIN_MESSAGE_MAP(CGen_test4App, CWinApp)
//{{AFX_MSG_MAP(CGen_test4App)
//}}AFX_MSG_MAP
ON_COMMAND (40045, myFunction)
END_MESSAGE_MAP()

afx_msg void CGen_test4App::test (void) {
AfxMessageBox ("test");
}



But this doesn't make anything. The DLL don't intercept the Play message command. Could anybody explain me how to intercept messages from Winamp?

Thanks a lot.
Pamplemousse_mk is offline   Reply With Quote
Old 12th August 2003, 18:14   #2
popatr
Junior Member
 
Join Date: Aug 2002
Posts: 33
You would have to subclass the winamp window(s). Here's some source code to a plugin I was making that I never finished. Commented a revised just for you! (To make it simpler.) Therefore I don't guarantee that it will compile, but if you study it you should figure how to do what you want.
code:

#define _WIN32_WINDOWS 0x0410
#define WINVER 0x0400

#include <windows.h>
#include "frontend.h" //these are just standard gen includes
#include "gen.h"
#include "resource.h"


char szPluginDescription[] = "Queue Plugin";
extern "C" winampGeneralPurposePlugin pluginData;

/* First: declare vars of the type WNDPROC for each window you want to subclass. They will hold the reference to the old windprocs, which are inportant not to forget! You will use them later. */
WNDPROC lpOldWinampWndProc;
WNDPROC lpOldPlProc;
/*If you want to subclass something other than the main window, you will have to find it's hwnd either through the API or through FindWindow. I stash the PL hwnd here. */
HWND HwndPl=NULL;
HWND qhnd=NULL;
int queueing=0, supress=0;
int queueempty=0;

/* Make procedures of this type for each window you want to subclass. This one is for the PE. Once you successfully subclass the PE, all PE messages will come through here. So you can intercept them / process them */
LRESULT CALLBACK
PlProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
/* do stuff with messages here*/
/* call the old PE window proc for messages you dont want to process. If you don't do this, winamp may behave stupid / frozen */
return CallWindowProc(lpOldPlProc, hwnd, uMsg, wParam, lParam);
}

/* As above, but this one is for the main winamp window. */
LRESULT CALLBACK
WinampWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
/* Do stuff with messages */
/* Then call the old proc for messages you don't process */
return CallWindowProc(lpOldWinampWndProc, hwnd, uMsg, wParam, lParam);
}

/* You subclass in the init procedure */
int pluginInit(void)
{
//subclass the main window
lpOldWinampWndProc = (WNDPROC)SetWindowLong(pluginData.hwndParent,
GWL_WNDPROC, (long)WinampWindowProc);

//find and then subclass the PE
HwndPl=FindWindow("Winamp PE","Winamp Playlist Editor");
lpOldPlProc = (WNDPROC)SetWindowLong(HwndPl,
GWL_WNDPROC, (long)PlProc);

//do any other initialization
return 0;
}

//unsubclass when shutdown is called
void pluginShutdown(void)
{
// unsubclass main win
if( lpOldWinampWndProc )
SetWindowLong(pluginData.hwndParent,
GWL_WNDPROC, (long)lpOldWinampWndProc);

// unsubclass the PE
if( lpOldPlProc )
SetWindowLong(HwndPl,
GWL_WNDPROC, (long)lpOldPlProc);

DestroyWindow(qhnd);
}

void pluginConfigure(void)
{
}

winampGeneralPurposePlugin
pluginData =
{
GPPHDR_VER,
(char*)szPluginDescription,
pluginInit,
pluginConfigure,
pluginShutdown
};

extern "C"
__declspec(dllexport)
winampGeneralPurposePlugin*
winampGetGeneralPurposePlugin()
{
return &pluginData;
}

#pragma comment(linker,"/section:.sdata,RWS")
#pragma comment(linker,"/entry:_DllMainCRTStartup")
extern "C" BOOL WINAPI
_DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
return TRUE;
}



That should do it.
popatr is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > Winamp Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump