Skip to content

Commit 21c87ed

Browse files
committed
[STOBJECT] Revising initialization for mixer
1 parent e3c974b commit 21c87ed

2 files changed

Lines changed: 38 additions & 66 deletions

File tree

dll/shellext/stobject/csystray.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "precomp.h"
1111

12+
#include <mmddk.h>
1213
#include <regstr.h>
1314
#include <undocshell.h>
1415
#include <shellutils.h>
@@ -393,6 +394,12 @@ BOOL CSysTray::ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
393394
MouseKeys_Update(this);
394395
break;
395396

397+
case MM_MIXM_LINE_CHANGE:
398+
{
399+
DPRINTF("MM_MIXM_LINE_CHANGE received at window processor: hMixer %lx; dwLineID %lu", wParam, lParam);
400+
break;
401+
}
402+
396403
case WM_DESTROY:
397404
KillTimer(POLL_TIMER_ID);
398405
DeregisterShellHookWindow(hWnd);

dll/shellext/stobject/volume.cpp

Lines changed: 31 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ HICON g_hIconVolume;
1414
HICON g_hIconMute;
1515

1616
HMIXER g_hMixer;
17-
UINT g_mixerId;
1817
DWORD g_mixerLineID;
1918
DWORD g_muteControlID;
2019

@@ -24,85 +23,46 @@ static BOOL g_IsMute = FALSE;
2423

2524
static HRESULT __stdcall Volume_FindMixerControl(CSysTray * pSysTray)
2625
{
27-
MMRESULT result;
28-
UINT mixerId = 0;
29-
DWORD waveOutId = 0;
30-
DWORD param2 = 0;
26+
if (g_hMixer)
27+
mixerClose(g_hMixer);
3128

32-
TRACE("Volume_FindDefaultMixerID\n");
29+
WCHAR pszWinMMErrText[MAXERRORLENGTH] = {0};
3330

34-
result = waveOutMessage((HWAVEOUT)UlongToHandle(WAVE_MAPPER), DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR)&waveOutId, (DWORD_PTR)&param2);
35-
if (result)
36-
return E_FAIL;
37-
38-
if (waveOutId == (DWORD)-1)
31+
MMRESULT result = mixerOpen(&g_hMixer, 0, (DWORD_PTR)pSysTray->GetHWnd(), 0, MIXER_OBJECTF_HMIXER | CALLBACK_WINDOW);
32+
if (result != MMSYSERR_NOERROR)
3933
{
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)))
34+
waveOutGetErrorTextW(result, pszWinMMErrText, _countof(pszWinMMErrText));
35+
ERR("Volume_FindDefaultMixer: mixerOpen failed: %lu (%S)\n", result, pszWinMMErrText);
6736
return E_FAIL;
37+
}
6838

69-
if (mixerCaps.cDestinations == 0)
70-
return S_FALSE;
71-
72-
TRACE("mixerCaps.cDestinations %d\n", mixerCaps.cDestinations);
39+
MIXERLINEW mixerLine;
40+
mixerLine.cbStruct = sizeof(mixerLine);
41+
mixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
7342

74-
DWORD idx;
75-
for (idx = 0; idx < mixerCaps.cDestinations; idx++)
43+
result = mixerGetLineInfoW((HMIXEROBJ)g_hMixer, &mixerLine, MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_COMPONENTTYPE);
44+
if (result != MMSYSERR_NOERROR)
7645
{
77-
mixerLine.cbStruct = sizeof(mixerLine);
78-
mixerLine.dwDestination = idx;
79-
if (!mixerGetLineInfoW((HMIXEROBJ)UlongToHandle(g_mixerId), &mixerLine, 0))
80-
{
81-
if (mixerLine.dwComponentType >= MIXERLINE_COMPONENTTYPE_DST_SPEAKERS &&
82-
mixerLine.dwComponentType <= MIXERLINE_COMPONENTTYPE_DST_HEADPHONES)
83-
break;
84-
TRACE("Destination %d was not speakers or headphones.\n");
85-
}
86-
}
87-
88-
if (idx >= mixerCaps.cDestinations)
46+
waveOutGetErrorTextW(result, pszWinMMErrText, _countof(pszWinMMErrText));
47+
ERR("Volume_FindDefaultMixer: mixerGetLineInfoW failed: %lu (%S)\n", result, pszWinMMErrText);
8948
return E_FAIL;
90-
91-
TRACE("Valid destination %d found.\n");
49+
}
9250

9351
g_mixerLineID = mixerLine.dwLineID;
9452

53+
MIXERLINECONTROLSW mixerLineControls;
54+
MIXERCONTROLW mixerControl;
9555
mixerLineControls.cbStruct = sizeof(mixerLineControls);
9656
mixerLineControls.dwLineID = mixerLine.dwLineID;
9757
mixerLineControls.cControls = 1;
9858
mixerLineControls.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE;
9959
mixerLineControls.pamxctrl = &mixerControl;
10060
mixerLineControls.cbmxctrl = sizeof(mixerControl);
10161

102-
if (mixerGetLineControlsW((HMIXEROBJ)UlongToHandle(g_mixerId), &mixerLineControls, MIXER_GETLINECONTROLSF_ONEBYTYPE))
62+
if (mixerGetLineControlsW((HMIXEROBJ)g_hMixer, &mixerLineControls, MIXER_OBJECTF_HMIXER | MIXER_GETLINECONTROLSF_ONEBYTYPE))
10363
return E_FAIL;
10464

105-
TRACE("Found control id %d for mute: %d\n", mixerControl.dwControlID);
65+
TRACE("Volume_FindDefaultMixer: Found control id %d for mute\n", mixerControl.dwControlID);
10666

10767
g_muteControlID = mixerControl.dwControlID;
10868

@@ -113,21 +73,21 @@ HRESULT Volume_IsMute()
11373
{
11474
MIXERCONTROLDETAILS mixerControlDetails;
11575

116-
if (g_mixerId != (UINT)-1 && g_muteControlID != (DWORD)-1)
76+
if (g_hMixer != NULL && g_muteControlID != (DWORD)-1)
11777
{
118-
BOOL detailsResult = 0;
78+
MIXERCONTROLDETAILS_BOOLEAN detailsResult;
11979
mixerControlDetails.cbStruct = sizeof(mixerControlDetails);
12080
mixerControlDetails.hwndOwner = 0;
12181
mixerControlDetails.dwControlID = g_muteControlID;
12282
mixerControlDetails.cChannels = 1;
12383
mixerControlDetails.paDetails = &detailsResult;
12484
mixerControlDetails.cbDetails = sizeof(detailsResult);
125-
if (mixerGetControlDetailsW((HMIXEROBJ)UlongToHandle(g_mixerId), &mixerControlDetails, 0))
85+
if (mixerGetControlDetailsW((HMIXEROBJ)g_hMixer, &mixerControlDetails, MIXER_OBJECTF_HMIXER | MIXER_GETCONTROLDETAILSF_VALUE))
12686
return E_FAIL;
12787

12888
TRACE("Obtained mute status %d\n", detailsResult);
12989

130-
g_IsMute = detailsResult != 0;
90+
g_IsMute = detailsResult.fValue == 1;
13191
}
13292

13393
return S_OK;
@@ -139,14 +99,13 @@ HRESULT STDMETHODCALLTYPE Volume_Init(_In_ CSysTray * pSysTray)
13999
WCHAR strTooltip[128];
140100

141101
TRACE("Volume_Init\n");
102+
g_mmDeviceChange = RegisterWindowMessageW(L"winmm_devicechange");
142103

143104
if (!g_hMixer)
144105
{
145106
hr = Volume_FindMixerControl(pSysTray);
146107
if (FAILED(hr))
147108
return hr;
148-
149-
g_mmDeviceChange = RegisterWindowMessageW(L"winmm_devicechange");
150109
}
151110

152111
g_hIconVolume = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_VOLUME));
@@ -329,6 +288,12 @@ HRESULT STDMETHODCALLTYPE Volume_Message(_In_ CSysTray * pSysTray, UINT uMsg, WP
329288

330289
case WM_MOUSEMOVE:
331290
break;
291+
292+
case MM_MIXM_LINE_CHANGE:
293+
{
294+
DPRINTF("MM_MIXM_LINE_CHANGE received: hMixer %lx; dwLineID %lu", wParam, lParam);
295+
break;
296+
}
332297
}
333298
return S_OK;
334299

0 commit comments

Comments
 (0)