Results 1 to 4 of 4

Thread: To control system volume with c#

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2003
    Location
    CANADA
    Posts
    63

    Question To control system volume with c#

    How To - control system volume with c#???

    Thanks for help!

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2003
    Location
    CANADA
    Posts
    63
    yeah i know but how? im a newbie i don't really know how to do it

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width