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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
#define _WIN32_WINNT 0x0500
#include "plugin.h"
#include "playSnd.h"
#include "optionsdlg.h"
#include "resource.h"
#include "m_cluiframes.h"
#include "IcoLib.h"
HINSTANCE hInst;
PLUGINLINK *pluginLink;
HWND hwndFrame = NULL, hwndMute = NULL, hwndSlider = NULL, hwndOptSlider = NULL;
HANDLE hHookSkinPlayingSound, hHookDbSettingChange, hHookSkinIconsChanged;
HHOOK hHookMouse;
bool showMute = TRUE;
char szTitle[] = "sndVol";
bool isEnabled = FALSE;
HICON hSoundOn = NULL, hSoundOff = NULL;
int isMuteVisible = FALSE;
int autoPreview = FALSE;
char *szIconId[2] = {"sndVol_Off", "sndVol_On"};
char *szIconName[2] = {"Off", "On"};
int iIconId[2] = {-IDI_SND_OFF, -IDI_SND_ON};
PLUGININFO pluginInfo={
sizeof( PLUGININFO ),
szTitle,
PLUGIN_MAKE_VERSION( 0,0,1,1 ),
"Volume control 4 Miranda's events sound",
"Denis Stanishevskiy // StDenis",
"stdenformiranda(at)fromru(dot)com",
"Copyright (c) 2005, Denis Stanishevskiy",
"",
0, 0
};
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
hInst=hinstDLL;
if(fdwReason == DLL_PROCESS_ATTACH)
DisableThreadLibraryCalls(GetModuleHandle("sndvol"));
return TRUE;
}
__declspec(dllexport) PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion)
{
return &pluginInfo;
}
HANDLE hMenuItem;
int OnSkinPlayingSound(WPARAM wParam,LPARAM lParam)
{
char * pszFile = (char *) lParam;
if(pszFile && (DBGetContactSettingByte(NULL,"Skin","UseSound",1) || (int)wParam==1))
playSnd::PlaySound(pszFile, NULL, SND_ASYNC | SND_FILENAME | SND_NOWAIT);
return 0;
}
int OnSkinIconsChanged(WPARAM wParam,LPARAM lParam)
{
hSoundOff = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)szIconId[0]);
hSoundOn = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)szIconId[1]);
int useSound = DBGetContactSettingByte(NULL,"Skin","UseSound",1);
DBWriteContactSettingByte(NULL,"Skin","UseSound",useSound);
SendMessage(hwndMute, BM_SETIMAGE,IMAGE_ICON,(LPARAM)(useSound?hSoundOn:hSoundOff));
return 0;
}
int OnSettingChanged(WPARAM wParam,LPARAM lParam)
{
if(wParam != 0 || lParam == NULL) return 0;
{
DBCONTACTWRITESETTING *dbcws=(DBCONTACTWRITESETTING*)lParam;
if(!strcmp(dbcws->szModule,"Skin"))
if(!strcmp(dbcws->szSetting,"UseSound"))
{
int useSound = dbcws->value.bVal;
SendMessage(hwndMute, BM_SETIMAGE,IMAGE_ICON,(LPARAM)(useSound?hSoundOn:hSoundOff));
return 0;
};
}
return 0;
}
static int OnOptionsInit(WPARAM wParam,LPARAM lParam)
{
OPTIONSDIALOGPAGE odp;
ZeroMemory(&odp, sizeof(odp));
odp.cbSize = sizeof(odp);
odp.pszGroup = Translate("Events");
odp.position = -200000000;
odp.hInstance = hInst;
odp.pszTemplate = MAKEINTRESOURCE(IDD_OPT);
odp.pszTitle = Translate("Sounds Volume");
odp.pfnDlgProc = (DLGPROC)OptionsDlgProc;
odp.flags = ODPF_BOLDGROUPS;
CallService(MS_OPT_ADDPAGE, wParam, (LPARAM)&odp);
return 0;
}
BOOL __inline IsMouseInside(HWND hwnd)
{
POINT pt;
HWND hwndAtPt;
GetCursorPos(&pt);
hwndAtPt = WindowFromPoint(pt);
while(hwndAtPt != NULL)
{
if(hwndAtPt == hwnd)
return TRUE;
hwndAtPt = GetParent(hwndAtPt);
}
return FALSE;
//return (hwndAtPt == hwnd) || (GetParent(hwndAtPt) == hwnd);
//GetWindowRect(hwnd, &rc);
//return PtInRect(&rc, pt);
}
LRESULT CALLBACK OnMouseHook(int code, WPARAM wParam, LPARAM lParam)
{
if(code >= 0)
{
if(wParam == WM_MOUSEWHEEL)
{
//MOUSEHOOKSTRUCTEX *mhk = (MOUSEHOOKSTRUCTEX*)lParam;
MSLLHOOKSTRUCT *mhk = (MSLLHOOKSTRUCT*)lParam;
if(IsMouseInside(hwndSlider))
{
int count = (short)HIWORD(mhk->mouseData);
PostMessage(hwndSlider, WM_MOUSEWHEEL, MAKEWPARAM(0,-count), MAKELPARAM(mhk->pt.x, mhk->pt.y));
return 1;
}
}
}
return CallNextHookEx(hHookMouse, code, wParam, lParam);
}
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
#define MUTE_W 20
#define MUTE_H 20
isMuteVisible = DBGetContactSettingByte(NULL,SERVICENAME,"MuteBtn", TRUE);
hwndMute = CreateWindow(MIRANDABUTTONCLASS,
"",
WS_CHILD | (isMuteVisible?WS_VISIBLE:0),
1,
1,
MUTE_W,
MUTE_H,
hwnd,
(HMENU)0,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),
NULL);
SendMessage(hwndMute, BUTTONSETASFLATBTN,0,0);
SendMessage(hwndMute, BM_SETIMAGE,IMAGE_ICON,(LPARAM)hSoundOn);
hwndSlider = CreateWindow(TRACKBAR_CLASS,
"",
WS_CHILD | WS_VISIBLE | TBS_NOTICKS,
MUTE_W+1,
1,
120,
MUTE_W,
hwnd,
(HMENU)0,
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),
NULL);
//SendMessage(hwndSlider, TBM_SETRANGE, FALSE, MAKELONG(-10000/3,1000));
SendMessage(hwndSlider, TBM_SETRANGE, FALSE, MAKELONG(SLIDER_MIN, SLIDER_MAX/SLIDER_DIV));
SendMessage(hwndSlider, TBM_SETPOS, TRUE, DBGetContactSettingDword(NULL,SERVICENAME,"Volume",1000)/SLIDER_DIV);
//SetWindowLong(hwndSlider, GWL_USERDATA, GetWindowLong(hwndSlider, GWL_WNDPROC));
//SetWindowLong(hwndSlider, GWL_WNDPROC, (LONG)SliderWndProc);
break;
}
case WM_COMMAND:
if((HWND)lParam == hwndMute)
{
int useSound = !DBGetContactSettingByte(NULL,"Skin","UseSound",1);
DBWriteContactSettingByte(NULL,"Skin","UseSound",useSound);
SendMessage(hwndMute, BM_SETIMAGE,IMAGE_ICON,(LPARAM)(useSound?hSoundOn:hSoundOff));
}
break;
/*
case WM_MOUSEWHEEL:
{
int count = HIWORD(wParam);
break;
}
*/
case WM_USER:
ShowWindow(hwndMute, wParam?SW_SHOW:SW_HIDE);
isMuteVisible = wParam;
case WM_HSCROLL:
{
int value = (DWORD)SendMessage(hwndSlider, TBM_GETPOS, 0, 0)*SLIDER_DIV;
if(hwndOptSlider)
SendMessage(hwndOptSlider, TBM_SETPOS, TRUE, value);
else
DBWriteContactSettingDword(NULL, SERVICENAME, "Volume", value);
playSnd::SetVolume(value);
SkinPlaySound("RecvMsg");
break;
}
case WM_SIZE:
{
RECT rect;
// = DBGetContactSettingByte(NULL,SERVICENAME,"MuteBtn", TRUE);//IsWindowVisible(hwndMute);
GetClientRect(hwnd,&rect);
#define SLIDER_H 18
SetWindowPos(hwndSlider, 0,
rect.left+(isMuteVisible?MUTE_W:0)+1, rect.top+1+ (MUTE_H-SLIDER_H)/2, rect.right-rect.left-3-(isMuteVisible?MUTE_W:0), SLIDER_H,
SWP_NOZORDER);
InvalidateRect(hwnd, &rect, FALSE);
return 0;
}
case WM_NOTIFY:
switch(((LPNMHDR)lParam)->code)
{
case NM_RELEASEDCAPTURE:
{
int value = (DWORD)SendMessage(hwndSlider, TBM_GETPOS, 0, 0)*SLIDER_DIV;
DBWriteContactSettingDword(NULL, SERVICENAME, "Volume", value);
if(hwndOptSlider) SendMessage(hwndOptSlider, TBM_SETPOS, TRUE, value);
playSnd::SetVolume(value);
//SkinPlaySound("RecvMsg");
break;
}
}
break;
}
return DefWindowProc(hwnd,msg,wParam,lParam);
}
#define WndClass "SNDVOL_WND"
int OnModulesLoaded(WPARAM wparam,LPARAM lparam)
{
if(!ServiceExists(MS_SKIN2_ADDICON))
{
hSoundOn = (HICON)LoadImage(hInst,MAKEINTRESOURCE(IDI_SND_ON),IMAGE_ICON,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0);
hSoundOff = (HICON)LoadImage(hInst,MAKEINTRESOURCE(IDI_SND_OFF),IMAGE_ICON,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0);
}
else
{
SKINICONDESC sid;
char ModuleName[MAX_PATH];
sid.cbSize = sizeof(sid);
sid.pszSection = Translate("Sound Volume");
GetModuleFileName(hInst, ModuleName, sizeof(ModuleName));
sid.pszDefaultFile = ModuleName;
#define myLOAD_ICON(n, result)\
sid.pszName = szIconId[n];\
sid.pszDescription = szIconName[n];\
sid.iDefaultIndex = iIconId[n];\
CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid);\
result = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)szIconId[n]);
myLOAD_ICON(0, hSoundOff);
myLOAD_ICON(1, hSoundOn);
hHookSkinIconsChanged = HookEvent(ME_SKIN2_ICONSCHANGED, OnSkinIconsChanged);
}
if(ServiceExists(MS_CLIST_FRAMES_ADDFRAME))
{
WNDCLASSEX wcx;
CLISTFrame f;
ZeroMemory( &wcx, sizeof( wcx ) );
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.style = 0;
wcx.lpfnWndProc = WndProc;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = hInst;
wcx.hIcon = NULL;
wcx.hCursor = LoadCursor(hInst, IDC_ARROW);
wcx.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
wcx.lpszMenuName = NULL;
wcx.lpszClassName = WndClass;
wcx.hIconSm = NULL;
//
RegisterClassEx(&wcx);
//
hwndFrame = CreateWindow(WndClass,
NULL,
WS_CHILD|WS_VISIBLE,
0,
0,
120,
MUTE_H+2,
(HWND)CallService( MS_CLUI_GETHWND, 0, 0 ),
NULL,
hInst,
NULL);
//
ZeroMemory(&f, sizeof(CLISTFrame));
f.align = alBottom;
f.cbSize = sizeof(CLISTFrame);
f.height = MUTE_H+2;
f.Flags = F_VISIBLE;
f.hWnd = hwndFrame;
f.name = "SoundVolume";
CallService(MS_CLIST_FRAMES_ADDFRAME,(int)&f,0);
}
return 0;
}
int __declspec(dllexport) Load(PLUGINLINK *link)
{
pluginLink=link;
playSnd::Init();
hHookSkinPlayingSound = HookEvent(ME_SKIN_PLAYINGSOUND, OnSkinPlayingSound);
HookEvent(ME_OPT_INITIALISE, OnOptionsInit);
HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
hHookDbSettingChange = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, OnSettingChanged);
hHookMouse = SetWindowsHookEx(WH_MOUSE_LL, &OnMouseHook, hInst, 0);
//hHookMouse = SetWindowsHookEx(WH_MOUSE, &OnMouseHook, hInst, 0);
return 0;
}
int __declspec(dllexport) Unload(void)
{
if(!ServiceExists(MS_SKIN2_ADDICON))
{
DestroyIcon(hSoundOff);
DestroyIcon(hSoundOn);
UnhookEvent(hHookSkinIconsChanged);
}
UnhookEvent(hHookSkinPlayingSound);
playSnd::Destroy();
return 0;
}
|