Solved

Volume Control

Posted on 1998-12-05
8
380 Views
Last Modified: 2013-12-03
How do you code a dialog slider control to perform the same function as the Windows master volume control.
0
Comment
Question by:wayan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 2

Expert Comment

by:trillo
ID: 1416763
Just a quetion.... Do you need help for the slider control, or for the volume settings, or both?
0
 

Author Comment

by:wayan
ID: 1416764
both, I am not sure on what API's to call and what if any structs to set up.
0
 
LVL 2

Accepted Solution

by:
trillo earned 50 total points
ID: 1416765
Which lengage are you using? C++?...
Anyway, while waiting for your answer I can tell you about the Windows' volume level: (I'll asume you use C++ in next lines)

You can use the "WaveOutGetVolume" and "WaveOutSetVolume" functions:
MMRESULT waveOutGetVolume(
    HWAVEOUT hwo, // Handle of a open waveout device
    LPDWORD pdwVolume // Adress of variable to be filled with the volume setting
   );
MMRESULT waveOutSetVolume(
    HWAVEOUT hwo,
    DWORD dwVolume
   );

The low-order word (from the second parameter of the function) contains the left-channel volume setting, and the high-order word contains the right-channel setting. A value of 0xFFFF represents full volume, and a value of 0x0000 is silence.
If a device does not support both left and right volume control, the low-order word of dwVolume specifies the volume level, and the high-order word is ignored.

You can use the HIWORD and LOWORD macros to separate the left and right channel volume values in the "WaveOutGetVolume" fucntion and you can use the MAKELONG macro to build the parameter form the left-right volume values in the "WaveOutSetVolume" function.

Trillo
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:wayan
ID: 1416766
trillo

I would like an answer in "C" , the following is out of my Resource file:

CONTROL         "Slider1",IDC_VOLUME_SLIDER,"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


0
 
LVL 2

Expert Comment

by:trillo
ID: 1416767
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
0
 
LVL 2

Expert Comment

by:trillo
ID: 1416768
All the code I posted on this page is valid for C and C++
0
 

Author Comment

by:wayan
ID: 1416769
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;
0
 
LVL 2

Expert Comment

by:trillo
ID: 1416770
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_MAPPER, &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_MAPPER, 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
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
commandline.codeplex.com required argumen except when displaying help 2 52
Dir function fails on mapped drives 28 150
VS2015 compilation and missing DLLs 9 181
SSRS troubles 4 86
This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question