wayan
asked on
Volume Control
How do you code a dialog slider control to perform the same function as the Windows master volume control.
Just a quetion.... Do you need help for the slider control, or for the volume settings, or both?
ASKER
both, I am not sure on what API's to call and what if any structs to set up.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
trillo
I would like an answer in "C" , the following is out of my Resource file:
CONTROL "Slider1",IDC_VOLUME_SLIDE R,"msctls_ trackbar32 ",
TBS_AUTOTICKS | TBS_VERT | TBS_BOTH | WS_TABSTOP,54,14,26,47
-------------------------- -----
This is my case statement in the dialog callback.
case IDC_VOLUME_SLIDER:
?
?
?
?
return TRUE;
-------------------------
If you could fill in the gaps, I would be very happy
wayan
I would like an answer in "C" , the following is out of my Resource file:
CONTROL "Slider1",IDC_VOLUME_SLIDE
TBS_AUTOTICKS | TBS_VERT | TBS_BOTH | WS_TABSTOP,54,14,26,47
--------------------------
This is my case statement in the dialog callback.
case IDC_VOLUME_SLIDER:
?
?
?
?
return TRUE;
-------------------------
If you could fill in the gaps, I would be very happy
wayan
Inside your message loop you must have something like this.
switch(message)
{
case WM_INITDIALOG:
// Set here the track bar's properties
SendMessage(hwndTrackBar, TBM_SETRANGE, (WPARAM)TRUE, MAKELONG(lMinimum, lMaximum);
// wParam = Boolean value indicaten if control must be redrawn
// lParam = low and high order words indicating the minimum and maximum values.
return TRUE;
case WM_VSCROLL: // For a vertical scrollbar (as in your code)
int newValue=SendMessage (hwndTrackBar, TBM_GETPOS, 0, 0);
return TRUE;
case ... (others)
}
-----------
As you see, your code was a little wrong, you don't need the ResourceID from your control, you only need the handle. Of course my code is very simple, but it basically shows how to precess the messages.
When the user changes, scrolls, clicks, etc... on the track bar you will recieve a WM_VSCROLL message for vertical trakbars and WM_HSCROLL message for horizontal track bars.
The you use the TBM_GETPOS message to retrieve the new value.
Trillo
switch(message)
{
case WM_INITDIALOG:
// Set here the track bar's properties
SendMessage(hwndTrackBar, TBM_SETRANGE, (WPARAM)TRUE, MAKELONG(lMinimum, lMaximum);
// wParam = Boolean value indicaten if control must be redrawn
// lParam = low and high order words indicating the minimum and maximum values.
return TRUE;
case WM_VSCROLL: // For a vertical scrollbar (as in your code)
int newValue=SendMessage (hwndTrackBar, TBM_GETPOS, 0, 0);
return TRUE;
case ... (others)
}
-----------
As you see, your code was a little wrong, you don't need the ResourceID from your control, you only need the handle. Of course my code is very simple, but it basically shows how to precess the messages.
When the user changes, scrolls, clicks, etc... on the track bar you will recieve a WM_VSCROLL message for vertical trakbars and WM_HSCROLL message for horizontal track bars.
The you use the TBM_GETPOS message to retrieve the new value.
Trillo
All the code I posted on this page is valid for C and C++
ASKER
trillo this is what I think you have suggested that I do.
I have 2 more points that I would like you to clarify.
(the HOW DO I comments below)
-------------------------- ---------- -----
int iVmin = 0x0000; // Volume minimum
int iVmax = 0xFFFF; // Volume maximum
int iVpos; // Current logical slider position
DWORD dwVolume;
HWAVEOUT hwo; // Wave device handle
case WM_INITDIALOG:
// set limits
SendDlgItemMessage(hdlg, IDC_VOLUME_SLIDER,
TBM_SETRANGE ,
TRUE, MAKELONG(iVmin, iVmax));
// HOW DO I USE
WaveOutGetVolume(hwo, dwVolume);
//TO SETUP
SendDlgItemMessage(hdlg, IDC_VOLUME_SLIDER, TBM_SETPOS , ?, ?);
return TRUE;
-------------------------- ---------- ---------- ---------- -
case WM_VSCROLL:
iVpos = SendDlgItemMessage(hdlg, IDC_VOLUME_SLIDER,
TBM_GETPOS , 0, 0);
// HOW DO I USE iVpos TO SETUP
WaveOutSetVolume(hwo, dwVolume);
return TRUE;
I have 2 more points that I would like you to clarify.
(the HOW DO I comments below)
--------------------------
int iVmin = 0x0000; // Volume minimum
int iVmax = 0xFFFF; // Volume maximum
int iVpos; // Current logical slider position
DWORD dwVolume;
HWAVEOUT hwo; // Wave device handle
case WM_INITDIALOG:
// set limits
SendDlgItemMessage(hdlg, IDC_VOLUME_SLIDER,
TBM_SETRANGE ,
TRUE, MAKELONG(iVmin, iVmax));
// HOW DO I USE
WaveOutGetVolume(hwo, dwVolume);
//TO SETUP
SendDlgItemMessage(hdlg, IDC_VOLUME_SLIDER, TBM_SETPOS , ?, ?);
return TRUE;
--------------------------
case WM_VSCROLL:
iVpos = SendDlgItemMessage(hdlg, IDC_VOLUME_SLIDER,
TBM_GETPOS , 0, 0);
// HOW DO I USE iVpos TO SETUP
WaveOutSetVolume(hwo, dwVolume);
return TRUE;
a) You have to send a &reference to the function, because it will fill your variable with the volume. The trackbar's limits are the same as the volume limits, so we can use the same variable for the trakbar and the volume setting, without any interpolation.
WaveOutGetVolume(MAVE_MAPP ER, &dwVolume);
SendDlgItemMessage(hdlg, IDC_VOLUME_SLIDER, TBM_SETPOS , TRUE, dwVolume);
b) TBM_GETPOS returns the trakbar's position and, as above, we use the same variable to set the volume.
case WM_VSCROLL:
iVpos = SendDlgItemMessage(hdlg, IDC_VOLUME_SLIDER, TBM_GETPOS , 0, 0);
WaveOutSetVolume(WAVE_MAPP ER, iVpos);
return TRUE;
Note that these 2 waveout functions need, in the first oparameter, a Handle of an open waveform-audio output device, but it can also be a device identifier.
Trillo
WaveOutGetVolume(MAVE_MAPP
SendDlgItemMessage(hdlg, IDC_VOLUME_SLIDER, TBM_SETPOS , TRUE, dwVolume);
b) TBM_GETPOS returns the trakbar's position and, as above, we use the same variable to set the volume.
case WM_VSCROLL:
iVpos = SendDlgItemMessage(hdlg, IDC_VOLUME_SLIDER, TBM_GETPOS , 0, 0);
WaveOutSetVolume(WAVE_MAPP
return TRUE;
Note that these 2 waveout functions need, in the first oparameter, a Handle of an open waveform-audio output device, but it can also be a device identifier.
Trillo