Beispiel #1
0
        public void Init()
        {
            // Win32 interface.

            // TODO: Can these three lines be moved to contructor?
            // and maybe the raw input ones too?
            Handle   = new WindowInteropHelper(_window).Handle;
            _toolbar = new ApplicationDesktopToolbar(Handle);
            _toolbar.ToolbarEvent += OnToolbarEvent;

            // Raw input.
            try
            {
                _rawInput = new RawInput(Handle);
                _rawInput.RawInputEvent += OnRawInputEvent;
            }
            catch (Win32Exception ex)
            {
                // NOTE: This error is probably caused by the fact that you are logged in via remote desktop,
                // raw input doesn't seem to be able to find the mouse point in that cause.
                // This is non-blocking as it is only required for auto hidding

                // TODO: There may be some sort of solution to this. For example the problem might be
                // that I just need to periodically query for new devices.
                AppBarEvent(this, new AppBarEventArgs()
                {
                    Action = AppBarNotificationAction.ErrorEvent,
                    Data   = String.Format("Problem tring to register for raw input events, {0}", ex.Message),
                });
            }

            // Listen for window events.
            _source = HwndSource.FromHwnd(Handle);
            if (_source == null)
            {
                throw new AppBarException("Window is not loaded yet");
            }
            _source.AddHook(new HwndSourceHook(WndProc));

            Register();
        }
        public void Init()
        {
            // Win32 interface. 
    
            // TODO: Can these three lines be moved to contructor?
            // and maybe the raw input ones too?
            Handle = new WindowInteropHelper(_window).Handle;
            _toolbar = new ApplicationDesktopToolbar(Handle);
            _toolbar.ToolbarEvent += OnToolbarEvent;

            // Raw input.
            try
            {
                _rawInput = new RawInput(Handle);
                _rawInput.RawInputEvent += OnRawInputEvent;
            }
            catch (Win32Exception ex)
            {
                // NOTE: This error is probably caused by the fact that you are logged in via remote desktop, 
                // raw input doesn't seem to be able to find the mouse point in that cause. 
                // This is non-blocking as it is only required for auto hidding

                // TODO: There may be some sort of solution to this. For example the problem might be
                // that I just need to periodically query for new devices.
                AppBarEvent(this, new AppBarEventArgs()
                    {
                        Action = AppBarNotificationAction.ErrorEvent,
                        Data = String.Format("Problem tring to register for raw input events, {0}", ex.Message),
                    });                
            }

            // Listen for window events.
            _source = HwndSource.FromHwnd(Handle);
            if (_source == null)
                throw new AppBarException("Window is not loaded yet");
            _source.AddHook(new HwndSourceHook(WndProc));

            Register();
        }