-
November 12th, 2009, 09:30 AM
#1
I need some help for something simple!!
Hi guys,
I need to make a winamp plugin (General Purpose), which will send the text "WinampIsActive" via network (To: 127.0.0.1 Port: 1024) when winamp gets the focus (keyboard focus). I also need need it to send the text "WinampIsInactive" when it loses it.
The thing is, I have'nt been coding in C++ for years; I'm really rusty so I need you help. It dosen't look too complicated; I have the base that works to make the plugin; here's the .h & .cpp code:
gen_myplugin.h:
Code:
#ifndef gen_myplugin_h
#define gen_myplugin_h
#include <windows.h>
#define GPPHDR_VER 0x10
#define PLUGIN_NAME "My first generic Winamp plugin!"
typedef struct {
int version; // version of the plugin structure
char *description; // name/title of the plugin
int (*init)(); // function which will be executed on init event
void (*config)(); // function which will be executed on config event
void (*quit)(); // function which will be executed on quit event
HWND hwndParent; // hwnd of the Winamp client main window (stored by Winamp when dll is loaded)
HINSTANCE hDllInstance; // hinstance of this plugin DLL. (stored by Winamp when dll is loaded)
} winampGeneralPurposePlugin;
#endif
gen_myplugin.cpp:
Code:
#include "stdafx.h"
#include <windows.h>
#include "gen_myplugin.h"
int init(void);
void config(void);
void quit(void);
winampGeneralPurposePlugin plugin = {
GPPHDR_VER, // version of the plugin, defined in "gen_myplugin.h"
PLUGIN_NAME, // name/title of the plugin, defined in "gen_myplugin.h"
init, // function name which will be executed on init event
config, // function name which will be executed on config event
quit, // function name which will be executed on quit event
0, // handle to Winamp main window, loaded by winamp when this dll is loaded
0 // hinstance to this dll, loaded by winamp when this dll is loaded
};
// event functions follow
int init() {
//A basic messagebox that tells you the 'init' event has been triggered.
//If everything works you should see this message when you start Winamp once your plugin has been installed.
//You can change this later to do whatever you want (including nothing)
MessageBox(plugin.hwndParent, L"Init event triggered for gen_myplugin. Plugin installed successfully!", L"", MB_OK);
return 0;
}
void config() {
//A basic messagebox that tells you the 'config' event has been triggered.
//You can change this later to do whatever you want (including nothing)
MessageBox(plugin.hwndParent, L"Config event triggered for gen_myplugin.", L"", MB_OK);
}
void quit() {
//A basic messagebox that tells you the 'quit' event has been triggered.
//If everything works you should see this message when you quit Winamp once your plugin has been installed.
//You can change this later to do whatever you want (including nothing)
MessageBox(0, L"Quit event triggered for gen_myplugin.", L"", MB_OK);
}
// This is an export function called by winamp which returns this plugin info.
// We wrap the code in 'extern "C"' to ensure the export isn't mangled if used in a CPP file.
extern "C" __declspec(dllexport) winampGeneralPurposePlugin * winampGetGeneralPurposePlugin() {
return &plugin;
}
Source: (http://dev.winamp.com/wiki/Beginner'...c_Plugin_Guide)
Thanx in advance!
Ps: For those who want to know why I wanna make this plugin, well it is simply to bypass a focus issue in EventGhost that happens when winamp has no taskbar button (http://www.eventghost.org/forum/view...php?f=2&t=1986). That's the only solution I could think of!
-
November 12th, 2009, 10:15 AM
#2
Re: I need some help for something simple!!
I don't know anything about winamp, but I do know a little about plugins. Looks like you don't get much of an API. According to the above, Winamp only notifies the plugin during init, config, and quit. None of those tell any info about the focus state. It looks like you do get a handle to the winamp main HWND so you'll probably have to hook the wndproc to get notification messages for windows messages.
-
November 12th, 2009, 10:19 AM
#3
Re: I need some help for something simple!!
I think so too! But I never figured out how to implant succesfully a wndproc (
If it's not too much to ask, could you make me a working sample that works with a given HWND?
-
November 12th, 2009, 11:10 AM
#4
Re: I need some help for something simple!!
It's a little much to ask because I haven't done it in a long time so I had to plod my way through it. It's roughly like this:
Code:
HWND m_hHookedWnd; //assume this is valid HWND
WNDPROC m_OrigDlgProc=NULL;
LRESULT MyCustomWndProc(HWND hWnd,UINT msg,WPARAM wp,LPARAM lp)
{
switch(msg){
case WM_SETFOCUS:
//do something
break; //or return TRUE to bypass default handling
}
//call original proc for everything else
return m_OrigDlgProc(hWnd,msg,wp,lp);
}
void HookWndProc()
{
//replace the wndproc with new proc and keep a pointer to the original proc
m_OrigDlgProc=(WNDPROC)::GetWindowLong(m_hHookedWnd,GWL_WNDPROC);
::SetWindowLong(m_hHookedWnd,GWL_WNDPROC,(LONG)MyCustomWndProc);
}
-
November 12th, 2009, 01:15 PM
#5
Re: I need some help for something simple!!
Allright! Looks simple! Very informative
Just to be sure;
- I must call HookWndProc() in the "init", right?
- Is there anything to do to deactivate the hook? Something I'd need to put in the "quit" ?
-
November 12th, 2009, 01:29 PM
#6
Re: I need some help for something simple!!
Yes. Just call SetWindowLong again and pass the pointer to the original wndproc
-
November 12th, 2009, 01:35 PM
#7
Re: I need some help for something simple!!
Allright, thanx Gonna try that tonight!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|