Old 16th January 2017, 11:01   #1
chinagreenelvis
Junior Member
 
Join Date: Nov 2009
Posts: 35
Adding Global Hotkeys For Dummies

Can someone please explain to me in a very straightforward manner how to use DrO's wa_hotkeys.h to register new Global Hotkey options?

I've successfully set up a working plugin from the Winamp Developer Wiki basic guide and I know exactly what I want to register a hotkey for.

code:

int init() {
SendMessage(plugin.hwndParent, WM_WA_IPC, (WPARAM)"Bento", IPC_SETSKIN);
return 0;
}



code:

void config() {
SendMessage(plugin.hwndParent, WM_WA_IPC, (WPARAM)"Winamp Classic", IPC_SETSKIN);
}



Currently, this starts Winamp in the Bento skin, and then swaps the skin into Winamp Classic when I select the plugin for configuration. I'd like to set up both for Global Hotkeys (or one hotkey to switch back and forth).

I'm not exactly new to programming, but I've never written anything for Winamp before. It would be easier if the wa_hotkeys.h were a fully-functional example rather than commented out code, but if someone can help explain which parts of that code need to go where, I'd greatly appreciate it.
chinagreenelvis is offline   Reply With Quote
Old 16th January 2017, 12:34   #2
chinagreenelvis
Junior Member
 
Join Date: Nov 2009
Posts: 35
Well, I somehow managed to figure it out. In case any other newbs are wondering, your newly created gen_myplugin.cpp should look exactly like this (assign the hotkey in Preferences and test it out to see the confirmation message):

code:

/*

Winamp generic plugin template code.
This code should be just the basics needed to get a plugin up and running.
You can then expand the code to build your own plugin.

Updated details compiled June 2009 by culix, based on the excellent code examples
and advice of forum members Kaboon, kichik, baafie, burek021, and bananskib.
Thanks for the help everyone!

*/

#include "stdafx.h"
#include <windows.h>
#include "gen_myplugin.h"
#include "wa_ipc.h"
#include <stdio.h>

// these are callback functions/events which will be called by Winamp
int init(void);
void config(void);
void quit(void);

// this structure contains plugin information, version, name...
// GPPHDR_VER is the version of the winampGeneralPurposePlugin (GPP) structure
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
};

// hotkeys
WNDPROC WinampProc;

typedef struct {
char *name; // this is the name that will appear in the Global Hotkeys preferences panel
DWORD flags; // one or more HKF_* flags from above
UINT uMsg; // message that will be sent to winamp's main window (must always be !=NULL)
WPARAM wParam; // wParam that will be sent to winamp's main window
LPARAM lParam; // lParam that will be sent to winamp's main window
char *id; // unique string to identify this command (the string is case insensitive)
HWND wnd; // set the HWND to send message (or 0 for the main winamp window)

int extended[6]; // for future extension - always set this to zero!
} genHotkeysAddStruct;

genHotkeysAddStruct test_key = { 0 }; // this will make the compiler zero the struct for you
// though you can do it manually if you want to as well
INT test_ipc = 0; // this will hold the uMsg value to look for in the assigned window proc

void AddGlobalHotkey(genHotkeysAddStruct *hotkey, char* name, char* id, int* ipc) {
UINT genhotkeys_add_ipc = 0;
hotkey->wnd = 0;
hotkey->flags = 0;
hotkey->name = name;
hotkey->id = id;
*ipc = hotkey->uMsg = SendMessage(plugin.hwndParent, WM_WA_IPC, (WPARAM)&hotkey->id, IPC_REGISTER_WINAMP_IPCMESSAGE);
genhotkeys_add_ipc = SendMessage(plugin.hwndParent, WM_WA_IPC, (WPARAM)&"GenHotkeysAdd", IPC_REGISTER_WINAMP_IPCMESSAGE);
PostMessage(plugin.hwndParent, WM_WA_IPC, (WPARAM)hotkey, genhotkeys_add_ipc);
}

LRESULT CALLBACK WinampWnd(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
int ret = 0;
// handles the hotkey for the option
if (uMsg == test_ipc) {
MessageBox(plugin.hwndParent, L"It appears to be working.", L"", MB_OK);
}
// do stuff before the winamp proc has been called

ret = CallWindowProc(WinampProc, hwnd, uMsg, wParam, lParam);
// do other stuff after the winamp proc has been called
// then return the value from CallWindowProc(..)
return ret;
}

// 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);

AddGlobalHotkey(&test_key, "Playback: Test key", "Test_key", &test_ipc);
WinampProc = (WNDPROC)SetWindowLong(plugin.hwndParent, GWL_WNDPROC,
(LONG)WinampWnd);

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;
}

chinagreenelvis is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast 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