Beispiel #1
0
        private void WndProc(ref Message m)

        {
            if (m.Msg == MM.MM_MIXM_CONTROL_CHANGE)     // Code 0x3D1 indicates a control change

            {
                int i = (int)(m.LParam);



                if (i == spkrVolumeControlID || i == spkrMuteControlID)

                {
                    long now = DateTime.Now.Ticks;

                    string type = this.ntNameVolumeDown;

                    int percent = 0;



                    // check for Mute first

                    bool wasMuted = false;

                    if (i == spkrMuteControlID)

                    {
                        int isMuted = MM.GetVolume(spkrMuteControl, spkrComponent);

                        if (isMuted > 0)
                        {
                            wasMuted = true;
                        }
                    }



                    // now handle volume

                    if (!wasMuted || i == spkrVolumeControlID)

                    {
                        int v = MM.GetVolume(spkrVolumeControl, spkrComponent);

                        percent = ConvertToPercentage(v);
                    }



                    QueueNotification(percent);



                    Console.WriteLine(String.Format("{0} - {1}", percent, DateTime.Now.Ticks));
                }
            }
        }
        public AppContext()
            : base()
        {
            bool ok = false;

            if (Environment.OSVersion.Version.Major > 5)
            {
                // Vista & higher
                ok = true;

                MMDeviceEnumerator devEnum = new MMDeviceEnumerator();
                this.defaultDevice = devEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
                this.defaultDevice.AudioEndpointVolume.OnVolumeNotification += new AudioEndpointVolumeNotificationDelegate(AudioEndpointVolume_OnVolumeNotification);
            }
            else
            {
                this.spkrVolumeControlID = MM.GetControlID(spkrComponent, spkrVolumeControl);
                this.spkrMuteControlID   = MM.GetControlID(spkrComponent, spkrMuteControl);

                if (this.spkrVolumeControlID > 0)
                {
                    ok = true;

                    int v = MM.GetVolume(spkrVolumeControl, spkrComponent);
                    this.currentVolume = ConvertToPercentage(v);

                    this.hwnd = new Hwnd(WndProc);
                    int iw = (int)this.hwnd.Handle;

                    // ... and we can now activate the message monitor
                    bool b = MM.MonitorControl(iw);
                }
            }

            if (ok)
            {
                NotificationType            ntUp   = new NotificationType(ntNameVolumeUp);
                NotificationType            ntDown = new NotificationType(ntNameVolumeDown);
                NotificationType[]          types  = new NotificationType[] { ntUp, ntDown };
                Growl.Connector.Application app    = new Growl.Connector.Application(appName);
                app.Icon = Properties.Resources.volumeter;

                this.growl = new GrowlConnector();
                this.growl.EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.PlainText;
                this.growl.Register(app, types);

                this.timer           = new System.Timers.Timer(buffer);
                this.timer.AutoReset = false;
                this.timer.Elapsed  += new System.Timers.ElapsedEventHandler(timer_Elapsed);
            }
            else
            {
                MessageBox.Show("No speaker/line out component found to monitor");
            }
        }