|
-
May 17th, 2003, 06:06 PM
#1
Thread Starter
Member
To control system volume with c#
How To - control system volume with c#???
Thanks for help!
-
May 19th, 2003, 04:48 AM
#2
DirectSound/Show or API import.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 19th, 2003, 05:17 AM
#3
Thread Starter
Member
yeah i know but how? im a newbie i don't really know how to do it
-
May 19th, 2003, 12:34 PM
#4
I don't know how to use P/Invoke, but this is the code I used for setting the volume in C++:
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);
}
If you have the complete Visual Studio.Net you can compile this code to a Managed C++ class library:
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);
}
};
}
You must add winmm.lib to the linker input include libraries.
Actually this only sets the wave volume, I don't know how to set the real system volume.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|