Wince volume control

Source: Internet
Author: User

First, let's take a look at these sound settings in the Registry: HKEY_CURRENT_USER/controlpanel/volume. The key values in these settings control the sound. It is explained as follows:

Volume: The main volume of the system, ranging from 0 to 0 ~ 0xffffffff.

Screen: screen knock. When the value is 0 (or 65536) silent, 1 is soft, 65538 is highlighted

Key: keyboard knock. The value is the same as that of screen.

Mute: controls other mute options. when 0x04 is set to 1, the event sound is allowed. 0x02 allows the application sound and 0x01 allows warning. note that if the application sound is not allowed, the warning bit will also be ignored.

After knowing the significance of each key value, I will start with the main system volume.

I. operations on the system master volume

First, let's look at the simplest code to change the volume:

DWORD dwvolume = 0 xaaaaaaaa;
Waveoutsetvolume (0, dwvolume );


The first parameter of waveoutsetvolume () is the device ID. Because the system volume needs to be changed, you can directly set the value to 0. The second parameter is the volume value to be set, the range is from 0 to 0 ~ 0 xffffffff.

Through the waveoutsetvolume () API, we can easily change the volume of the system device. However, if you check the registry's volume key value, because it only modifies the volume of the device, the change has not reached the registry so quickly. However, you can go to "volume and sound" in "Control Panel" to open it, and the registry value also changes. (Otherwise, separate operations on the registry do not affect the specific volume)

Therefore, I first perform volume operations on the volume in the registry, and change the volume using the waveoutsetvolume () API to achieve consistency. The specific operation code is as follows:

DWORD dwvolume = 0;
CREG * pvolumereg = NULL;

Pvolumereg = new CREG (HKEY_CURRENT_USER, text ("controlpanel // volume "));

Dwvolume = pvolumereg-> valuedw (text ("volume "));
.............. Specific Volume settings

If (waveoutsetvolume (null, dwvolume )! = Mmsyserr_noerror) whether the volume is set successfully
{
DbgMsg (zone_1, (text ("waveoutsetvolume failed, [mainlayere. cpp, setvolume]");
}
 
Pvolumereg-> setdw (text ("volume"), dwvolume); set the Registry
Delete pvolumereg;
Pvolumereg = NULL;

The CREG used above is a class for registry operations and is a base class used by our group (Walzer Note: You can search for creg in the wince500 directory to find it, in fact, Microsoft is also very lazy ). In this way, we have improved the master volume settings.

Ii. Set the hardware key sound (key value)

Although the waveoutsetvolume () API is very useful for setting the main volume, the function has very limited functions, that is, it can only change the main volume of the system; if you want to modify the hardware button sound or screen knock sound, you can't do anything.

Some very careful friends may start with the "sound" of the "control panel" and find that every time they adjust the sound on the control panel, the key value in the corresponding "controlpanel/volume" is changed. however, if you modify the Registry directly, you cannot achieve the corresponding functions in any way-the Registry has been modified because there is no notification system.

If you need to inform the system that the Registry has been modified and the system needs to change the volume according to the modified value, you need to call Microsoft's undisclosed API: audioupdatefromregistry ().

This API cannot be found in the document. If you need to call this function, you can use either of the following methods.

First, directly include the "pwinuser. H" file and then call it directly.

The second is to call the coredll. dll library, extract the function and use it.

The first method is relatively unstable, because some people's sdks do not have this pwinuser. h file, so the program cannot be found. I recommend using the second method to call this API directly (as our team leader said about the brute force call of the API, this method is really good .)

The Code is as follows:

 

1 typedef void (winapi * dll_audioupdatefromregistry) (); defines a new type pointer pointing to winapi
2
3 dll_audioupdatefromregistry = NULL;
4 hinstance hcoredll = loadlibrary (text ("coredll. dll "));
5 If (hcoredll)
6 {
7 dll_audioupdatefromregistry = (dll_audioupdatefromregistry) getprocaddress (hcoredll, _ T ("audioupdatefromregistry"); call this API
8 If (dll_audioupdatefromregistry)
9 {
10 (dll_audioupdatefromregistry )();
11}
12 else
13 {
14 return false;
15}
16 freelibrary (hcoredll );
17}
18 else
19 {
20 return false;
21}
22 return true;
23

 

In this way, you can set the key sound by modifying the key value of the registry and calling this method.

You can also use this method to set screen and mute. At this point, you have mastered the various volume settings of wince. Hope to help you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.