ReactOS 0.4.16-dev-112-g52265ae
volume.cpp File Reference
#include "precomp.h"
#include <mmddk.h>
Include dependency graph for volume.cpp:

Go to the source code of this file.

Functions

static HRESULT __stdcall Volume_FindMixerControl (CSysTray *pSysTray)
 
HRESULT Volume_IsMute ()
 
HRESULT STDMETHODCALLTYPE Volume_Init (_In_ CSysTray *pSysTray)
 
HRESULT STDMETHODCALLTYPE Volume_Update (_In_ CSysTray *pSysTray)
 
HRESULT STDMETHODCALLTYPE Volume_Shutdown (_In_ CSysTray *pSysTray)
 
HRESULT Volume_OnDeviceChange (_In_ CSysTray *pSysTray, WPARAM wParam, LPARAM lParam)
 
static void _RunVolume (BOOL bTray)
 
static void _RunMMCpl ()
 
static void _ShowContextMenu (CSysTray *pSysTray)
 
HRESULT STDMETHODCALLTYPE Volume_Message (_In_ CSysTray *pSysTray, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult)
 

Variables

HICON g_hIconVolume
 
HICON g_hIconMute
 
HMIXER g_hMixer
 
UINT g_mixerId
 
DWORD g_mixerLineID
 
DWORD g_muteControlID
 
UINT g_mmDeviceChange
 
static BOOL g_IsMute = FALSE
 

Function Documentation

◆ _RunMMCpl()

static void _RunMMCpl ( )
static

Definition at line 221 of file volume.cpp.

222{
223 ShellExecuteW(NULL, NULL, L"mmsys.cpl", NULL, NULL, SW_NORMAL);
224}
#define NULL
Definition: types.h:112
#define L(x)
Definition: ntvdm.h:50
HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpVerb, LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
Definition: shlexec.cpp:2482
#define SW_NORMAL
Definition: winuser.h:772

Referenced by _ShowContextMenu().

◆ _RunVolume()

static void _RunVolume ( BOOL  bTray)
static

Definition at line 211 of file volume.cpp.

212{
214 NULL,
215 L"sndvol32.exe",
216 bTray ? L"/t" : NULL,
217 NULL,
219}
#define SW_SHOWNORMAL
Definition: winuser.h:773

Referenced by _ShowContextMenu(), and Volume_Message().

◆ _ShowContextMenu()

static void _ShowContextMenu ( CSysTray pSysTray)
static

Definition at line 226 of file volume.cpp.

227{
228 WCHAR strAdjust[128];
229 WCHAR strOpen[128];
230 LoadStringW(g_hInstance, IDS_VOL_OPEN, strOpen, _countof(strOpen));
231 LoadStringW(g_hInstance, IDS_VOL_ADJUST, strAdjust, _countof(strAdjust));
232
233 HMENU hPopup = CreatePopupMenu();
234 AppendMenuW(hPopup, MF_STRING, IDS_VOL_OPEN, strOpen);
235 AppendMenuW(hPopup, MF_STRING, IDS_VOL_ADJUST, strAdjust);
237
239 POINT pt;
240 SetForegroundWindow(pSysTray->GetHWnd());
242
243 DWORD id = TrackPopupMenuEx(hPopup, flags,
244 pt.x, pt.y,
245 pSysTray->GetHWnd(), NULL);
246
247 DestroyMenu(hPopup);
248
249 switch (id)
250 {
251 case IDS_VOL_OPEN:
253 break;
254 case IDS_VOL_ADJUST:
255 _RunMMCpl();
256 break;
257 }
258}
HINSTANCE g_hInstance
Definition: MainWindow.cpp:18
HWND GetHWnd()
Definition: csystray.h:54
#define FALSE
Definition: types.h:117
#define IDS_VOL_ADJUST
Definition: resource.h:33
#define IDS_VOL_OPEN
Definition: resource.h:34
#define pt(x, y)
Definition: drawing.c:79
unsigned long DWORD
Definition: ntddk_ex.h:95
GLbitfield flags
Definition: glext.h:7161
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
#define _countof(array)
Definition: sndvol32.h:70
static void _RunVolume(BOOL bTray)
Definition: volume.cpp:211
static void _RunMMCpl()
Definition: volume.cpp:221
HMENU WINAPI CreatePopupMenu(void)
Definition: menu.c:838
BOOL WINAPI SetMenuDefaultItem(_In_ HMENU, _In_ UINT, _In_ UINT)
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define TPM_BOTTOMALIGN
Definition: winuser.h:2388
#define MF_STRING
Definition: winuser.h:138
BOOL WINAPI SetForegroundWindow(_In_ HWND)
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2722
#define TPM_RIGHTALIGN
Definition: winuser.h:2381
#define TPM_NONOTIFY
Definition: winuser.h:2389
BOOL WINAPI TrackPopupMenuEx(_In_ HMENU, _In_ UINT, _In_ int, _In_ int, _In_ HWND, _In_opt_ LPTPMPARAMS)
BOOL WINAPI DestroyMenu(_In_ HMENU)
#define TPM_RETURNCMD
Definition: winuser.h:2390
BOOL WINAPI AppendMenuW(_In_ HMENU, _In_ UINT, _In_ UINT_PTR, _In_opt_ LPCWSTR)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by Volume_Message().

◆ Volume_FindMixerControl()

static HRESULT __stdcall Volume_FindMixerControl ( CSysTray pSysTray)
static

Definition at line 25 of file volume.cpp.

26{
28 UINT mixerId = 0;
29 DWORD waveOutId = 0;
30 DWORD param2 = 0;
31
32 TRACE("Volume_FindDefaultMixerID\n");
33
35 if (result)
36 return E_FAIL;
37
38 if (waveOutId == (DWORD)-1)
39 {
40 TRACE("WARNING: waveOut has no default device, trying with first available device...\n", waveOutId);
41
42 mixerId = 0;
43 }
44 else
45 {
46 TRACE("waveOut default device is %d\n", waveOutId);
47
48 result = mixerGetID((HMIXEROBJ)UlongToHandle(waveOutId), &mixerId, MIXER_OBJECTF_WAVEOUT);
49 if (result)
50 return E_FAIL;
51
52 TRACE("mixerId for waveOut default device is %d\n", mixerId);
53 }
54
55 g_mixerId = mixerId;
56 return S_OK;
57
58 MIXERCAPS mixerCaps;
59 MIXERLINE mixerLine;
60 MIXERCONTROL mixerControl;
61 MIXERLINECONTROLS mixerLineControls;
62
63 g_mixerLineID = -1;
64 g_muteControlID = -1;
65
66 if (mixerGetDevCapsW(g_mixerId, &mixerCaps, sizeof(mixerCaps)))
67 return E_FAIL;
68
69 if (mixerCaps.cDestinations == 0)
70 return S_FALSE;
71
72 TRACE("mixerCaps.cDestinations %d\n", mixerCaps.cDestinations);
73
74 DWORD idx;
75 for (idx = 0; idx < mixerCaps.cDestinations; idx++)
76 {
77 mixerLine.cbStruct = sizeof(mixerLine);
78 mixerLine.dwDestination = idx;
79 if (!mixerGetLineInfoW((HMIXEROBJ)UlongToHandle(g_mixerId), &mixerLine, 0))
80 {
83 break;
84 TRACE("Destination %d was not speakers or headphones.\n");
85 }
86 }
87
88 if (idx >= mixerCaps.cDestinations)
89 return E_FAIL;
90
91 TRACE("Valid destination %d found.\n");
92
93 g_mixerLineID = mixerLine.dwLineID;
94
95 mixerLineControls.cbStruct = sizeof(mixerLineControls);
96 mixerLineControls.dwLineID = mixerLine.dwLineID;
97 mixerLineControls.cControls = 1;
99 mixerLineControls.pamxctrl = &mixerControl;
100 mixerLineControls.cbmxctrl = sizeof(mixerControl);
101
103 return E_FAIL;
104
105 TRACE("Found control id %d for mute: %d\n", mixerControl.dwControlID);
106
107 g_muteControlID = mixerControl.dwControlID;
108
109 return S_OK;
110}
#define UlongToHandle(ul)
Definition: basetsd.h:97
#define E_FAIL
Definition: ddrawi.h:102
unsigned int idx
Definition: utils.c:41
GLuint64EXT * result
Definition: glext.h:11304
#define S_OK
Definition: intsafe.h:52
#define DRVM_MAPPER_PREFERRED_GET
Definition: mmsys.h:39
#define MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
Definition: mmsystem.h:319
UINT MMRESULT
Definition: mmsystem.h:962
#define MIXER_OBJECTF_WAVEOUT
Definition: mmsystem.h:302
#define MIXERLINE_COMPONENTTYPE_DST_HEADPHONES
Definition: mmsystem.h:320
#define WAVE_MAPPER
Definition: mmsystem.h:187
#define MIXER_GETLINECONTROLSF_ONEBYTYPE
Definition: mmsystem.h:410
#define MIXERCONTROL_CONTROLTYPE_MUTE
Definition: mmsystem.h:384
unsigned int UINT
Definition: ndis.h:50
#define TRACE(s)
Definition: solgame.cpp:4
DWORD cDestinations
Definition: mmsystem.h:1219
DWORD dwDestination
Definition: mmsystem.h:1233
DWORD dwComponentType
Definition: mmsystem.h:1238
DWORD dwLineID
Definition: mmsystem.h:1235
DWORD cbStruct
Definition: mmsystem.h:1232
LPMIXERCONTROLA pamxctrl
Definition: mmsystem.h:1338
uint32_t DWORD_PTR
Definition: typedefs.h:65
DWORD g_muteControlID
Definition: volume.cpp:19
DWORD g_mixerLineID
Definition: volume.cpp:18
UINT g_mixerId
Definition: volume.cpp:17
#define S_FALSE
Definition: winerror.h:2357
UINT WINAPI mixerGetLineControlsW(HMIXEROBJ hmix, LPMIXERLINECONTROLSW lpmlcW, DWORD fdwControls)
Definition: winmm.c:571
UINT WINAPI mixerGetDevCapsW(UINT_PTR uDeviceID, LPMIXERCAPSW lpCaps, UINT uSize)
Definition: winmm.c:314
UINT WINAPI mixerGetLineInfoW(HMIXEROBJ hmix, LPMIXERLINEW lpmliW, DWORD fdwInfo)
Definition: winmm.c:592
UINT WINAPI mixerGetID(HMIXEROBJ hmix, LPUINT lpid, DWORD fdwID)
Definition: winmm.c:404
UINT WINAPI waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
Definition: winmm.c:2538

Referenced by Volume_Init(), and Volume_OnDeviceChange().

◆ Volume_Init()

HRESULT STDMETHODCALLTYPE Volume_Init ( _In_ CSysTray pSysTray)

Definition at line 136 of file volume.cpp.

137{
138 HRESULT hr;
139 WCHAR strTooltip[128];
140
141 TRACE("Volume_Init\n");
142
143 if (!g_hMixer)
144 {
145 hr = Volume_FindMixerControl(pSysTray);
146 if (FAILED(hr))
147 return hr;
148
149 g_mmDeviceChange = RegisterWindowMessageW(L"winmm_devicechange");
150 }
151
154
156
157 HICON icon;
158 if (g_IsMute)
159 icon = g_hIconMute;
160 else
161 icon = g_hIconVolume;
162
163 LoadStringW(g_hInstance, IDS_VOL_VOLUME, strTooltip, _countof(strTooltip));
164 return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_VOLUME, icon, strTooltip);
165}
#define ID_ICON_VOLUME
Definition: precomp.h:38
#define IDS_VOL_VOLUME
Definition: resource.h:32
#define IDI_VOLMUTE
Definition: resource.h:30
#define IDI_VOLUME
Definition: resource.h:29
#define FAILED(hr)
Definition: intsafe.h:51
static HICON
Definition: imagelist.c:80
#define NIM_ADD
Definition: shellapi.h:94
HRESULT hr
Definition: shlfolder.c:183
HRESULT Volume_IsMute()
Definition: volume.cpp:112
static BOOL g_IsMute
Definition: volume.cpp:23
UINT g_mmDeviceChange
Definition: volume.cpp:21
HICON g_hIconVolume
Definition: volume.cpp:13
static HRESULT __stdcall Volume_FindMixerControl(CSysTray *pSysTray)
Definition: volume.cpp:25
HMIXER g_hMixer
Definition: volume.cpp:16
HICON g_hIconMute
Definition: volume.cpp:14
#define LoadIcon
Definition: winuser.h:5825
UINT WINAPI RegisterWindowMessageW(_In_ LPCWSTR)
#define MAKEINTRESOURCE
Definition: winuser.h:591

Referenced by Volume_Message().

◆ Volume_IsMute()

HRESULT Volume_IsMute ( )

Definition at line 112 of file volume.cpp.

113{
114 MIXERCONTROLDETAILS mixerControlDetails;
115
116 if (g_mixerId != (UINT)-1 && g_muteControlID != (DWORD)-1)
117 {
118 BOOL detailsResult = 0;
119 mixerControlDetails.cbStruct = sizeof(mixerControlDetails);
120 mixerControlDetails.hwndOwner = 0;
121 mixerControlDetails.dwControlID = g_muteControlID;
122 mixerControlDetails.cChannels = 1;
123 mixerControlDetails.paDetails = &detailsResult;
124 mixerControlDetails.cbDetails = sizeof(detailsResult);
125 if (mixerGetControlDetailsW((HMIXEROBJ)UlongToHandle(g_mixerId), &mixerControlDetails, 0))
126 return E_FAIL;
127
128 TRACE("Obtained mute status %d\n", detailsResult);
129
130 g_IsMute = detailsResult != 0;
131 }
132
133 return S_OK;
134}
unsigned int BOOL
Definition: ntddk_ex.h:94
UINT WINAPI mixerGetControlDetailsW(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcdW, DWORD fdwDetails)
Definition: winmm.c:423

Referenced by Volume_Init(), and Volume_Update().

◆ Volume_Message()

HRESULT STDMETHODCALLTYPE Volume_Message ( _In_ CSysTray pSysTray,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
LRESULT lResult 
)

Definition at line 260 of file volume.cpp.

261{
262 if (uMsg == g_mmDeviceChange)
263 return Volume_OnDeviceChange(pSysTray, wParam, lParam);
264
265 switch (uMsg)
266 {
267 case WM_USER + 220:
268 TRACE("Volume_Message: WM_USER+220\n");
270 {
271 if (lParam)
272 {
273 pSysTray->EnableService(VOLUME_SERVICE_FLAG, TRUE);
274 return Volume_Init(pSysTray);
275 }
276 else
277 {
278 pSysTray->EnableService(VOLUME_SERVICE_FLAG, FALSE);
279 return Volume_Shutdown(pSysTray);
280 }
281 }
282 return S_FALSE;
283
284 case WM_USER + 221:
285 TRACE("Volume_Message: WM_USER+221\n");
287 {
288 lResult = (LRESULT)pSysTray->IsServiceEnabled(VOLUME_SERVICE_FLAG);
289 return S_OK;
290 }
291 return S_FALSE;
292
293 case WM_TIMER:
294 if (wParam == VOLUME_TIMER_ID)
295 {
296 KillTimer(pSysTray->GetHWnd(), VOLUME_TIMER_ID);
298 }
299 break;
300
301 case ID_ICON_VOLUME:
302 TRACE("Volume_Message uMsg=%d, w=%x, l=%x\n", uMsg, wParam, lParam);
303
304 Volume_Update(pSysTray);
305
306 switch (lParam)
307 {
308 case WM_LBUTTONDOWN:
309 SetTimer(pSysTray->GetHWnd(), VOLUME_TIMER_ID, GetDoubleClickTime(), NULL);
310 break;
311
312 case WM_LBUTTONUP:
313 break;
314
315 case WM_LBUTTONDBLCLK:
316 KillTimer(pSysTray->GetHWnd(), VOLUME_TIMER_ID);
318 break;
319
320 case WM_RBUTTONDOWN:
321 break;
322
323 case WM_RBUTTONUP:
324 _ShowContextMenu(pSysTray);
325 break;
326
327 case WM_RBUTTONDBLCLK:
328 break;
329
330 case WM_MOUSEMOVE:
331 break;
332 }
333 return S_OK;
334
335 default:
336 TRACE("Volume_Message received for unknown ID %d, ignoring.\n");
337 return S_FALSE;
338 }
339
340 return S_FALSE;
341}
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define TRUE
Definition: types.h:120
#define VOLUME_TIMER_ID
Definition: precomp.h:84
#define VOLUME_SERVICE_FLAG
Definition: precomp.h:40
#define LRESULT
Definition: ole.h:14
HRESULT STDMETHODCALLTYPE Volume_Init(_In_ CSysTray *pSysTray)
Definition: volume.cpp:136
HRESULT Volume_OnDeviceChange(_In_ CSysTray *pSysTray, WPARAM wParam, LPARAM lParam)
Definition: volume.cpp:206
HRESULT STDMETHODCALLTYPE Volume_Shutdown(_In_ CSysTray *pSysTray)
Definition: volume.cpp:199
static void _ShowContextMenu(CSysTray *pSysTray)
Definition: volume.cpp:226
HRESULT STDMETHODCALLTYPE Volume_Update(_In_ CSysTray *pSysTray)
Definition: volume.cpp:167
#define WM_LBUTTONDBLCLK
Definition: winuser.h:1781
#define WM_RBUTTONUP
Definition: winuser.h:1783
#define WM_RBUTTONDBLCLK
Definition: winuser.h:1784
#define WM_MOUSEMOVE
Definition: winuser.h:1778
#define WM_LBUTTONDOWN
Definition: winuser.h:1779
UINT WINAPI GetDoubleClickTime(void)
Definition: ntwrapper.h:314
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define WM_RBUTTONDOWN
Definition: winuser.h:1782
#define WM_TIMER
Definition: winuser.h:1745
#define WM_LBUTTONUP
Definition: winuser.h:1780
#define WM_USER
Definition: winuser.h:1898
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)

◆ Volume_OnDeviceChange()

HRESULT Volume_OnDeviceChange ( _In_ CSysTray pSysTray,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 206 of file volume.cpp.

207{
208 return Volume_FindMixerControl(pSysTray);
209}

Referenced by Volume_Message().

◆ Volume_Shutdown()

HRESULT STDMETHODCALLTYPE Volume_Shutdown ( _In_ CSysTray pSysTray)

Definition at line 199 of file volume.cpp.

200{
201 TRACE("Volume_Shutdown\n");
202
203 return pSysTray->NotifyIcon(NIM_DELETE, ID_ICON_VOLUME, NULL, NULL);
204}
#define NIM_DELETE
Definition: shellapi.h:96

Referenced by Volume_Message().

◆ Volume_Update()

HRESULT STDMETHODCALLTYPE Volume_Update ( _In_ CSysTray pSysTray)

Definition at line 167 of file volume.cpp.

168{
169 BOOL PrevState;
170
171 TRACE("Volume_Update\n");
172
173 PrevState = g_IsMute;
175
176 if (PrevState != g_IsMute)
177 {
178 WCHAR strTooltip[128];
179 HICON icon;
180 if (g_IsMute)
181 {
182 icon = g_hIconMute;
183 LoadStringW(g_hInstance, IDS_VOL_MUTED, strTooltip, _countof(strTooltip));
184 }
185 else
186 {
187 icon = g_hIconVolume;
188 LoadStringW(g_hInstance, IDS_VOL_VOLUME, strTooltip, _countof(strTooltip));
189 }
190
191 return pSysTray->NotifyIcon(NIM_MODIFY, ID_ICON_VOLUME, icon, strTooltip);
192 }
193 else
194 {
195 return S_OK;
196 }
197}
#define IDS_VOL_MUTED
Definition: resource.h:36
#define NIM_MODIFY
Definition: shellapi.h:95

Referenced by Volume_Message().

Variable Documentation

◆ g_hIconMute

HICON g_hIconMute

Definition at line 14 of file volume.cpp.

Referenced by Volume_Init(), and Volume_Update().

◆ g_hIconVolume

HICON g_hIconVolume

Definition at line 13 of file volume.cpp.

Referenced by Volume_Init(), and Volume_Update().

◆ g_hMixer

HMIXER g_hMixer

Definition at line 16 of file volume.cpp.

Referenced by Volume_Init().

◆ g_IsMute

BOOL g_IsMute = FALSE
static

Definition at line 23 of file volume.cpp.

Referenced by Volume_Init(), Volume_IsMute(), and Volume_Update().

◆ g_mixerId

UINT g_mixerId

Definition at line 17 of file volume.cpp.

Referenced by Volume_FindMixerControl(), and Volume_IsMute().

◆ g_mixerLineID

DWORD g_mixerLineID

Definition at line 18 of file volume.cpp.

Referenced by Volume_FindMixerControl().

◆ g_mmDeviceChange

UINT g_mmDeviceChange

Definition at line 21 of file volume.cpp.

Referenced by Volume_Init(), and Volume_Message().

◆ g_muteControlID

DWORD g_muteControlID

Definition at line 19 of file volume.cpp.

Referenced by Volume_FindMixerControl(), and Volume_IsMute().