aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/mediaplayer/winamp.cpp
blob: 0d701558aa23f32afd481a9085ef7a826c9863d2 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//=============================================================================
//
//   File : winamp.cpp
//   Creation date : Tue Nov  6 23:01:12 2001 GMT by Szymon Stefanek
//
//   This file is part of the KVIrc IRC client distribution
//   Copyright (C) 2001-2010 Szymon Stefanek (pragma at kvirc dot net)
//
//   This program is FREE software. You can redistribute it and/or
//   modify it under the terms of the GNU General Public License
//   as published by the Free Software Foundation; either version 2
//   of the License, or (at your option) any later version.
//
//   This program is distributed in the HOPE that it will be USEFUL,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//   See the GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program. If not, write to the Free Software Foundation,
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================

#include <windows.h>
#include <process.h>

//
// This is a winamp-kvirc interface plugin
//

// This stuff is compiled only on windows, as a separate dll module

struct winampGeneralPurposePlugin
{
	int version;
	char * description;
	int (*init)();
	void (*config)();
	void (*quit)();
	HWND hwndParent;
	HINSTANCE hDllInstance;
};

#define GPPHDR_VER 0x10

extern winampGeneralPurposePlugin * gen_plugins[256];
typedef winampGeneralPurposePlugin * (*winampGeneralPurposePluginGetter)();

int init();
void quit();
void config();

winampGeneralPurposePlugin plugin = {
	GPPHDR_VER,
	"KVIrc interface plugin 1.0",
	init,
	config,
	quit,
};

#define KVIRC_WM_USER 63112

#define KVIRC_WM_USER_GETTITLE 5000
#define KVIRC_WM_USER_GETFILE 10000
#define KVIRC_WM_USER_TRANSFER 15000

#define IPC_GETPLAYLISTFILE 211
#define IPC_GETPLAYLISTTITLE 212
#define IPC_GETLISTPOS 125

#define KVIRC_WM_USER_CHECK 13123
#define KVIRC_WM_USER_CHECK_REPLY 13124

void * lpWndProcOld = nullptr;

char szBuffer[4096];

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	if(message == WM_USER)
	{
		if(wParam == KVIRC_WM_USER)
		{
			if(lParam == KVIRC_WM_USER_CHECK)
			{
				return KVIRC_WM_USER_CHECK_REPLY;
			}
			if(lParam == KVIRC_WM_USER_GETTITLE)
			{
				int idx = (int)SendMessage(hwnd, WM_USER, 0, IPC_GETLISTPOS);
				if(idx != -1)
				{
					char * szTitle = (char *)SendMessage(hwnd, WM_USER, idx, IPC_GETPLAYLISTTITLE);
					strcpy(szBuffer, szTitle);
					return strlen(szBuffer);
				}
			}
			else if(lParam == KVIRC_WM_USER_GETFILE)
			{
				int idx = (int)SendMessage(hwnd, WM_USER, 0, IPC_GETLISTPOS);
				if(idx != -1)
				{
					char * szTitle = (char *)SendMessage(hwnd, WM_USER, idx, IPC_GETPLAYLISTFILE);
					strcpy(szBuffer, szTitle);
					return strlen(szBuffer);
				}
			}
			else if((lParam >= KVIRC_WM_USER_TRANSFER) && (lParam < (KVIRC_WM_USER_TRANSFER + 4096)))
			{
				return (LRESULT)szBuffer[lParam - KVIRC_WM_USER_TRANSFER];
			}
		}
	}
	return CallWindowProc((WNDPROC)lpWndProcOld, hwnd, message, wParam, lParam);
}

int init()
{
	lpWndProcOld = (void *)GetWindowLong(plugin.hwndParent, GWLP_WNDPROC);
	SetWindowLongPtr(plugin.hwndParent, GWLP_WNDPROC, (intptr_t)WndProc);
	return 0;
}

void quit()
{
}

void config()
{
}

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