ReactOS 0.4.15-dev-8146-gdc0ed6d
tray.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Sound Volume Control
4 * FILE: base/applications/sndvol32/tray.c
5 * PROGRAMMERS: Eric Kohl <eric.kohl@reactos.org>
6 */
7
8#include "sndvol32.h"
9
10typedef struct _DIALOG_DATA
11{
12 HMIXER hMixer;
18
23
26
27
28static VOID
30 HWND hwnd,
33{
34 POINT ptCursor;
35 RECT rcWindow;
36 RECT rcScreen;
37 LONG x, y, cx, cy;
38
39 GetCursorPos(&ptCursor);
40
41 GetWindowRect(hwnd, &rcWindow);
42
43 GetWindowRect(GetDesktopWindow(), &rcScreen);
44
45 cx = rcWindow.right - rcWindow.left;
46 cy = rcWindow.bottom - rcWindow.top;
47
48 if (ptCursor.y + cy > rcScreen.bottom)
49 y = ptCursor.y - cy;
50 else
51 y = ptCursor.y;
52
53 if (ptCursor.x + cx > rcScreen.right)
54 x = ptCursor.x - cx;
55 else
56 x = ptCursor.x;
57
59}
60
61
62static
63VOID
65 PDIALOG_DATA pDialogData,
66 HWND hwndDlg)
67{
68 MIXERLINE mxln;
69 MIXERCONTROL mxc;
70 MIXERLINECONTROLS mxlctrl;
73 DWORD i;
74
75 /* Open the mixer */
76 if (mixerOpen(&pDialogData->hMixer, 0, PtrToUlong(hwndDlg), 0, MIXER_OBJECTF_MIXER | CALLBACK_WINDOW) != MMSYSERR_NOERROR)
77 return;
78
79 /* Retrieve the mixer information */
80 mxln.cbStruct = sizeof(MIXERLINE);
82
84 return;
85
86 pDialogData->volumeChannels = mxln.cChannels;
87
88 /* Retrieve the line information */
89 mxlctrl.cbStruct = sizeof(MIXERLINECONTROLS);
90 mxlctrl.dwLineID = mxln.dwLineID;
92 mxlctrl.cControls = 1;
93 mxlctrl.cbmxctrl = sizeof(MIXERCONTROL);
94 mxlctrl.pamxctrl = &mxc;
95
97 return;
98
99 pDialogData->volumeControlID = mxc.dwControlID;
100 pDialogData->volumeMinimum = mxc.Bounds.dwMinimum;
101 pDialogData->volumeMaximum = mxc.Bounds.dwMaximum;
102 pDialogData->volumeStep = (pDialogData->volumeMaximum - pDialogData->volumeMinimum) / (VOLUME_MAX - VOLUME_MIN);
103
104 /* Allocate a buffer for all channel volume values */
106 0,
108 if (pDialogData->volumeInitValues == NULL)
109 return;
110
112 0,
114 if (pDialogData->volumeCurrentValues == NULL)
115 return;
116
117 /* Retrieve the channel volume values */
118 mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
119 mxcd.dwControlID = mxc.dwControlID;
120 mxcd.cChannels = mxln.cChannels;
121 mxcd.cMultipleItems = 0;
123 mxcd.paDetails = pDialogData->volumeInitValues;
124
126 return;
127
128 pDialogData->maxVolume = 0;
129 for (i = 0; i < pDialogData->volumeChannels; i++)
130 {
131 pDialogData->volumeCurrentValues[i].dwValue = pDialogData->volumeInitValues[i].dwValue;
132
133 if (pDialogData->volumeInitValues[i].dwValue > pDialogData->maxVolume)
134 pDialogData->maxVolume = pDialogData->volumeInitValues[i].dwValue;
135 }
136
137 /* Initialize the volume trackbar */
140 SendDlgItemMessage(hwndDlg, IDC_LINE_SLIDER_VERT, TBM_SETPOS, TRUE, VOLUME_MAX -(pDialogData->maxVolume - pDialogData->volumeMinimum) / pDialogData->volumeStep);
141
142 /* Retrieve the mute control information */
143 mxlctrl.cbStruct = sizeof(MIXERLINECONTROLS);
144 mxlctrl.dwLineID = mxln.dwLineID;
146 mxlctrl.cControls = 1;
147 mxlctrl.cbmxctrl = sizeof(MIXERCONTROL);
148 mxlctrl.pamxctrl = &mxc;
149
151 return;
152
153 pDialogData->muteControlID = mxc.dwControlID;
154
155 /* Retrieve the mute value */
156 mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
157 mxcd.dwControlID = mxc.dwControlID;
158 mxcd.cChannels = 1;
159 mxcd.cMultipleItems = 0;
161 mxcd.paDetails = &mxcdBool;
162
164 return;
165
166 /* Initialize the mute checkbox */
168}
169
170
171static
172VOID
174 PDIALOG_DATA pDialogData,
175 HWND hwndDlg,
178{
181
182 if ((LOWORD(wParam) == IDC_LINE_SWITCH) &&
184 {
185 mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
186 mxcd.dwControlID = pDialogData->muteControlID;
187 mxcd.cChannels = 1;
188 mxcd.cMultipleItems = 0;
190 mxcd.paDetails = &mxcdMute;
191
192 mxcdMute.fValue = (SendMessage((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED);
193
194 mixerSetControlDetails((HMIXEROBJ)pDialogData->hMixer,
195 &mxcd,
197 }
198}
199
200
201static
202VOID
204 PDIALOG_DATA pDialogData,
205 HWND hwndDlg,
208{
210 DWORD dwPosition, dwVolume, i;
211
212 switch (LOWORD(wParam))
213 {
214 case TB_THUMBPOSITION:
215 break;
216
217 case TB_ENDTRACK:
219 break;
220
221 default:
222 dwPosition = VOLUME_MAX - (DWORD)SendDlgItemMessage(hwndDlg, IDC_LINE_SLIDER_VERT, TBM_GETPOS, 0, 0);
223
224 if (dwPosition == VOLUME_MIN)
225 dwVolume = pDialogData->volumeMinimum;
226 else if (dwPosition == VOLUME_MAX)
227 dwVolume = pDialogData->volumeMaximum;
228 else
229 dwVolume = (dwPosition * pDialogData->volumeStep) + pDialogData->volumeMinimum;
230
231 for (i = 0; i < pDialogData->volumeChannels; i++)
232 {
233 if (pDialogData->volumeInitValues[i].dwValue == pDialogData->maxVolume)
234 {
235 pDialogData->volumeCurrentValues[i].dwValue = dwVolume;
236 }
237 else
238 {
239 pDialogData->volumeCurrentValues[i].dwValue =
240 pDialogData->volumeInitValues[i].dwValue * dwVolume / pDialogData-> maxVolume;
241 }
242 }
243
244 mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
245 mxcd.dwControlID = pDialogData->volumeControlID;
246 mxcd.cChannels = pDialogData->volumeChannels;
247 mxcd.cMultipleItems = 0;
249 mxcd.paDetails = pDialogData->volumeCurrentValues;
250
251 mixerSetControlDetails((HMIXEROBJ)pDialogData->hMixer,
252 &mxcd,
254 break;
255 }
256}
257
258
259
263 HWND hwndDlg,
264 UINT uMsg,
267{
268 PDIALOG_DATA pDialogData;
269
270 pDialogData = (PDIALOG_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
271
272 switch (uMsg)
273 {
274 case WM_INITDIALOG:
275 OnTrayInitDialog(hwndDlg, wParam, lParam);
276
278 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pDialogData);
279
280 if (pDialogData)
281 OnTrayInitMixer(pDialogData, hwndDlg);
282 break;
283
284 case WM_COMMAND:
285 if (pDialogData)
286 OnCommand(pDialogData, hwndDlg, wParam, lParam);
287 break;
288
289 case WM_VSCROLL:
290 if (pDialogData)
291 OnVScroll(pDialogData, hwndDlg, wParam, lParam);
292 break;
293
294 case WM_DESTROY:
295 if (pDialogData)
296 {
297 if (pDialogData->volumeInitValues)
298 HeapFree(GetProcessHeap(), 0, pDialogData->volumeInitValues);
299
300 if (pDialogData->volumeCurrentValues)
301 HeapFree(GetProcessHeap(), 0, pDialogData->volumeCurrentValues);
302
303 if (pDialogData->hMixer)
304 mixerClose(pDialogData->hMixer);
305
306 HeapFree(GetProcessHeap(), 0, pDialogData);
307 pDialogData = NULL;
309 }
310 break;
311
312 case WM_ACTIVATE:
313 if (LOWORD(wParam) == WA_INACTIVE)
314 EndDialog(hwndDlg, IDOK);
315 break;
316 }
317
318 return 0;
319}
320
321/* EOF */
#define IDC_LINE_SLIDER_VERT
Definition: resources.h:25
#define IDC_LINE_SWITCH
Definition: resources.h:23
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define PtrToUlong(u)
Definition: config.h:107
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define CALLBACK_WINDOW
Definition: mmsystem.h:148
#define MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
Definition: mmsystem.h:319
#define MIXER_OBJECTF_MIXER
Definition: mmsystem.h:300
MIXERCONTROLA MIXERCONTROL
Definition: mmsystem.h:2825
#define PlaySound
Definition: mmsystem.h:2842
MIXERLINECONTROLSA MIXERLINECONTROLS
Definition: mmsystem.h:2826
#define MIXER_SETCONTROLDETAILSF_VALUE
Definition: mmsystem.h:415
#define MIXER_GETCONTROLDETAILSF_VALUE
Definition: mmsystem.h:412
#define SND_ALIAS_SYSTEMDEFAULT
Definition: mmsystem.h:175
#define mixerGetControlDetails
Definition: mmsystem.h:2855
#define mixerGetLineControls
Definition: mmsystem.h:2854
#define MIXERCONTROL_CONTROLTYPE_VOLUME
Definition: mmsystem.h:398
MIXERLINEA MIXERLINE
Definition: mmsystem.h:2824
#define MIXER_GETLINEINFOF_COMPONENTTYPE
Definition: mmsystem.h:347
#define SND_ALIAS_ID
Definition: mmsystem.h:161
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define mixerGetLineInfo
Definition: mmsystem.h:2853
struct tMIXERCONTROLDETAILS_BOOLEAN MIXERCONTROLDETAILS_BOOLEAN
#define SND_ASYNC
Definition: mmsystem.h:154
struct tMIXERCONTROLDETAILS MIXERCONTROLDETAILS
struct tMIXERCONTROLDETAILS_UNSIGNED MIXERCONTROLDETAILS_UNSIGNED
#define MIXER_GETLINECONTROLSF_ONEBYTYPE
Definition: mmsystem.h:410
#define MIXER_OBJECTF_HMIXER
Definition: mmsystem.h:301
#define MIXERCONTROL_CONTROLTYPE_MUTE
Definition: mmsystem.h:384
#define for
Definition: utility.h:88
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
#define DWORD
Definition: nt_native.h:44
#define LOWORD(l)
Definition: pedump.c:82
long LONG
Definition: pedump.c:60
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
#define TB_ENDTRACK
Definition: commctrl.h:2081
#define TBM_SETPAGESIZE
Definition: commctrl.h:2051
#define TB_THUMBPOSITION
Definition: commctrl.h:2077
#define TBM_GETPOS
Definition: commctrl.h:2031
_Out_opt_ int * cx
Definition: commctrl.h:585
#define TBM_SETRANGE
Definition: commctrl.h:2037
#define TBM_SETPOS
Definition: commctrl.h:2036
#define VOLUME_MAX
Definition: sndvol32.h:19
#define VOLUME_PAGE_SIZE
Definition: sndvol32.h:21
#define VOLUME_MIN
Definition: sndvol32.h:18
DWORD volumeChannels
Definition: tray.c:14
DWORD volumeStep
Definition: tray.c:17
DWORD volumeControlID
Definition: tray.c:13
PMIXERCONTROLDETAILS_UNSIGNED volumeCurrentValues
Definition: tray.c:22
PMIXERCONTROLDETAILS_UNSIGNED volumeInitValues
Definition: tray.c:21
DWORD maxChannel
Definition: tray.c:20
DWORD volumeMaximum
Definition: tray.c:16
DWORD maxVolume
Definition: tray.c:19
DWORD muteControlID
Definition: tray.c:24
HMIXER hMixer
Definition: tray.c:12
DWORD volumeMinimum
Definition: tray.c:15
union tagMIXERCONTROLA::@3053 Bounds
DWORD dwComponentType
Definition: mmsystem.h:1238
DWORD dwLineID
Definition: mmsystem.h:1235
DWORD cbStruct
Definition: mmsystem.h:1232
DWORD cChannels
Definition: mmsystem.h:1239
LPMIXERCONTROLA pamxctrl
Definition: mmsystem.h:1338
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
static VOID OnCommand(PDIALOG_DATA pDialogData, HWND hwndDlg, WPARAM wParam, LPARAM lParam)
Definition: tray.c:173
static VOID OnTrayInitMixer(PDIALOG_DATA pDialogData, HWND hwndDlg)
Definition: tray.c:64
struct _DIALOG_DATA DIALOG_DATA
static VOID OnTrayInitDialog(HWND hwnd, WPARAM wParam, LPARAM lParam)
Definition: tray.c:29
struct _DIALOG_DATA * PDIALOG_DATA
static VOID OnVScroll(PDIALOG_DATA pDialogData, HWND hwndDlg, WPARAM wParam, LPARAM lParam)
Definition: tray.c:203
INT_PTR CALLBACK TrayDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: tray.c:262
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
int32_t INT_PTR
Definition: typedefs.h:64
#define MAKELONG(a, b)
Definition: typedefs.h:249
#define HIWORD(l)
Definition: typedefs.h:247
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
UINT WINAPI mixerClose(HMIXER hMix)
Definition: winmm.c:386
UINT WINAPI mixerOpen(LPHMIXER lphMix, UINT uDeviceID, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen)
Definition: winmm.c:339
UINT WINAPI mixerSetControlDetails(HMIXEROBJ hmix, LPMIXERCONTROLDETAILS lpmcd, DWORD fdwDetails)
Definition: winmm.c:681
#define DWLP_USER
Definition: winuser.h:872
#define HWND_TOPMOST
Definition: winuser.h:1208
#define BST_UNCHECKED
Definition: winuser.h:199
#define WM_VSCROLL
Definition: winuser.h:1744
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define WM_COMMAND
Definition: winuser.h:1740
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2701
#define SWP_NOSIZE
Definition: winuser.h:1245
#define WA_INACTIVE
Definition: winuser.h:2622
#define WM_INITDIALOG
Definition: winuser.h:1739
#define IDOK
Definition: winuser.h:830
#define BM_SETCHECK
Definition: winuser.h:1921
#define WM_ACTIVATE
Definition: winuser.h:1612
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:656
#define SendMessage
Definition: winuser.h:5843
#define BN_CLICKED
Definition: winuser.h:1925
#define WM_DESTROY
Definition: winuser.h:1609
#define SendDlgItemMessage
Definition: winuser.h:5842
#define BST_CHECKED
Definition: winuser.h:197
#define BM_GETCHECK
Definition: winuser.h:1918
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
const CHAR * LPCTSTR
Definition: xmlstorage.h:193