GetDesktopWindow() private method

private GetDesktopWindow ( ) : IntPtr
return System.IntPtr
Example #1
0
 private void InitializeDirectSound()
 {
     lock (this.m_LockObject)
     {
         this.directSound = null;
         DirectSoundOut.DirectSoundCreate(ref this.device, out this.directSound, IntPtr.Zero);
         if (this.directSound != null)
         {
             this.directSound.SetCooperativeLevel(DirectSoundOut.GetDesktopWindow(), DirectSoundOut.DirectSoundCooperativeLevel.DSSCL_PRIORITY);
             DirectSoundOut.BufferDescription bufferDescription = new DirectSoundOut.BufferDescription();
             bufferDescription.dwSize        = Marshal.SizeOf(bufferDescription);
             bufferDescription.dwBufferBytes = 0u;
             bufferDescription.dwFlags       = DirectSoundOut.DirectSoundBufferCaps.DSBCAPS_PRIMARYBUFFER;
             bufferDescription.dwReserved    = 0;
             bufferDescription.lpwfxFormat   = IntPtr.Zero;
             bufferDescription.guidAlgo      = Guid.Empty;
             object obj;
             this.directSound.CreateSoundBuffer(bufferDescription, out obj, IntPtr.Zero);
             this.primarySoundBuffer = (DirectSoundOut.IDirectSoundBuffer)obj;
             this.primarySoundBuffer.Play(0u, 0u, DirectSoundOut.DirectSoundPlayFlags.DSBPLAY_LOOPING);
             this.samplesFrameSize = this.MsToBytes(this.desiredLatency);
             DirectSoundOut.BufferDescription bufferDescription2 = new DirectSoundOut.BufferDescription();
             bufferDescription2.dwSize        = Marshal.SizeOf(bufferDescription2);
             bufferDescription2.dwBufferBytes = (uint)(this.samplesFrameSize * 2);
             bufferDescription2.dwFlags       = (DirectSoundOut.DirectSoundBufferCaps.DSBCAPS_CTRLVOLUME | DirectSoundOut.DirectSoundBufferCaps.DSBCAPS_CTRLPOSITIONNOTIFY | DirectSoundOut.DirectSoundBufferCaps.DSBCAPS_STICKYFOCUS | DirectSoundOut.DirectSoundBufferCaps.DSBCAPS_GLOBALFOCUS | DirectSoundOut.DirectSoundBufferCaps.DSBCAPS_GETCURRENTPOSITION2);
             bufferDescription2.dwReserved    = 0;
             GCHandle gchandle = GCHandle.Alloc(this.waveFormat, GCHandleType.Pinned);
             bufferDescription2.lpwfxFormat = gchandle.AddrOfPinnedObject();
             bufferDescription2.guidAlgo    = Guid.Empty;
             this.directSound.CreateSoundBuffer(bufferDescription2, out obj, IntPtr.Zero);
             this.secondaryBuffer = (DirectSoundOut.IDirectSoundBuffer)obj;
             gchandle.Free();
             DirectSoundOut.BufferCaps bufferCaps = new DirectSoundOut.BufferCaps();
             bufferCaps.dwSize = Marshal.SizeOf(bufferCaps);
             this.secondaryBuffer.GetCaps(bufferCaps);
             this.nextSamplesWriteIndex = 0;
             this.samplesTotalSize      = bufferCaps.dwBufferBytes;
             this.samples = new byte[this.samplesTotalSize];
             DirectSoundOut.IDirectSoundNotify directSoundNotify = (DirectSoundOut.IDirectSoundNotify)obj;
             this.frameEventWaitHandle1 = new EventWaitHandle(false, EventResetMode.AutoReset);
             this.frameEventWaitHandle2 = new EventWaitHandle(false, EventResetMode.AutoReset);
             this.endEventWaitHandle    = new EventWaitHandle(false, EventResetMode.AutoReset);
             DirectSoundOut.DirectSoundBufferPositionNotify[] array = new DirectSoundOut.DirectSoundBufferPositionNotify[3];
             array[0]              = default(DirectSoundOut.DirectSoundBufferPositionNotify);
             array[0].dwOffset     = 0u;
             array[0].hEventNotify = this.frameEventWaitHandle1.SafeWaitHandle.DangerousGetHandle();
             array[1]              = default(DirectSoundOut.DirectSoundBufferPositionNotify);
             array[1].dwOffset     = (uint)this.samplesFrameSize;
             array[1].hEventNotify = this.frameEventWaitHandle2.SafeWaitHandle.DangerousGetHandle();
             array[2]              = default(DirectSoundOut.DirectSoundBufferPositionNotify);
             array[2].dwOffset     = uint.MaxValue;
             array[2].hEventNotify = this.endEventWaitHandle.SafeWaitHandle.DangerousGetHandle();
             directSoundNotify.SetNotificationPositions(3u, array);
         }
     }
 }