PDA

View Full Version : Using ML from a General Purpose plug-in


saivert
11th July 2005, 19:04
Syntax of ML API:
SendMessage(g_hwndML, WM_ML_IPC, param, ML_IPC_*);

Include stuff and Set up some vars:

#include "ml.h"
HWND g_hwndML;
int config_useml=0;


First we need to get the handle to media library from within our general purpose plugin:

/* Register the "LibraryGetWnd" custom message */
long libhwndipc = (LONG)SendMessage(plugin.hwndParent,
WM_WA_IPC, WPARAM("LibraryGetWnd"),
IPC_REGISTER_WINAMP_IPCMESSAGE);

/* Now send the message and get the HWND */
g_hwndML = (HWND)SendMessage(plugin.hwndParent,
WM_WA_IPC, -1, LPARAM(libhwndipc));

/* Enable use of Media Library if Media Library
is available */
if (g_hwndML) config_useml=1;

Then we set up a winampMediaLibraryPlugin struct:

winampMediaLibraryPlugin ml_plugin =
{
MLHDR_VER,
"Your funky ML plug-in title",
ml_init,
ml_quit,
ml_PluginMessageProc,
0, // Must be 0 !!
0, // Must be 0 !!
0, // Must be 0 !!
};


Then set up some empty functions. Since ML doesn't call these functions when you inject a plug-in during run-time
we define them as empty ones. You can put code here and call them yourself if you need to.

int ml_init() { return 0; }
void ml_quit() { return; }


Then it is time for the PluginMessageProc thing:

int PluginMessageProc(int message_type,
int param1, int param2, int param3) {

// check for any global messages here
if (message_type >= ML_MSG_TREE_BEGIN &&
message_type <= ML_MSG_TREE_END)
{
if (param1 != myParam) return 0;
// local messages for a tree item

switch (message_type) {
case ML_MSG_TREE_ONCREATEVIEW:
{
/* When we get the ML_MSG_TREE_ONCREATEVIEW message
we are supposed to create our dialog which is
hosted in ML and return it's window handle.
Media Library will then do
DestroyWindow(hwnd_ourdialog);
when you click on another view
inside Media Library.
At least that's what I think. */

return (int)CreateDialog(plugin.hDllInstance,
MAKEINTRESOURCE(IDD_VIEW_EX),
(HWND)0, dlgproc);
}
case ML_MSG_TREE_ONCLICK:
return onTreeItemClick(param1,param2,(HWND)param3);
}
}
else if (message_type == ML_MSG_CONFIG)
{
config((HWND)param1);
return 1;
}
return 0;
}

Here is the onTreeItemClick function:

int onTreeItemClick(int param, int action,
HWND hwndParent) // if param is not yours, return 0
{
// Here you just display a menu when people
// right-click tree-view item.
if (action == ML_ACTION_RCLICK)
{
POINT p;
GetCursorPos(&p);
int r=TrackPopupMenu(any_valid_menu_handle_here,
TPM_RETURNCMD|TPM_RIGHTBUTTON|
TPM_LEFTBUTTON|TPM_NONOTIFY,
p.x,p.y,0,hwndParent,NULL);
switch (r)
{
case ID_ABOUT:
DialogBox(plugin.hDllInstance,
MAKEINTRESOURCE(IDD_ABOUT),
hwndParent,
about_dlgproc);
break;
case ID_CONFIG:
config(hwndParent);
break;
}
}
return 1;
}


Now for the finale. Inject our ML plug-in:

SendMessage(g_hwndML, WM_ML_IPC,
(WPARAM)&ml_plugin, ML_IPC_ADD_PLUGIN);

To remove our plug-in again (e.g in your quit function) do this:

SendMessage(g_hwndML, WM_ML_IPC, (WPARAM)&ml_plugin,
ML_IPC_REMOVE_PLUGIN);