How To - control system volume with c#???
Thanks for help! :)
Printable View
How To - control system volume with c#???
Thanks for help! :)
DirectSound/Show or API import.
yeah i know but how? im a newbie i don't really know how to do it:(
I don't know how to use P/Invoke, but this is the code I used for setting the volume in C++:
If you have the complete Visual Studio.Net you can compile this code to a Managed C++ class library:Code:void SetVolume(WORD vol)
{
HWAVEOUT hWO;
WAVEFORMATEX wf;
wf.cbSize = 0;
wf.nAvgBytesPerSec = 22050;
wf.nBlockAlign = 1;
wf.nChannels = 2;
wf.wBitsPerSample = 16;
wf.nSamplesPerSec = 22050;
wf.wFormatTag = WAVE_FORMAT_PCM;
waveOutOpen(&hWO, WAVE_MAPPER, &wf, reinterpret_cast<DWORD_PTR>(hwnd),
0, CALLBACK_WINDOW);
waveOutSetVolume(hWO, MAKELONG(vol, vol));
waveOutClose(hWO);
}
You must add winmm.lib to the linker input include libraries.Code:// This is the main DLL file.
#using <mscorlib.dll>
#include <windows.h>
namespace CornedBee
{
public __gc class AudioUtils
{
public:
static void SetVolume(System::UInt16 volume)
{
::HWAVEOUT hWO;
::WAVEFORMATEX wf;
wf.cbSize = 0;
wf.nAvgBytesPerSec = 22050;
wf.nBlockAlign = 1;
wf.nChannels = 2;
wf.wBitsPerSample = 16;
wf.nSamplesPerSec = 22050;
wf.wFormatTag = WAVE_FORMAT_PCM;
::waveOutOpen(&hWO, WAVE_MAPPER, &wf, 0, 0, 0);
::waveOutSetVolume(hWO, MAKELONG(volume, volume));
::waveOutClose(hWO);
}
};
}
Actually this only sets the wave volume, I don't know how to set the real system volume.