コード例 #1
0
ファイル: DragImage.cs プロジェクト: oqewok/gitter
        public void ShowDragVisual(Control control)
        {
            UpdatePosition();
            User32.ShowWindow(this.Handle, 8);
            User32.SetWindowPos(
                this.Handle, (IntPtr)(-1),
                0, 0, 0, 0,
                0x0010 | 0x0002 | 0x001);

            try
            {
                _hook = new LowLevelMouseHook();
                _hook.Activate(0);
            }
            catch (Win32Exception)
            {
                if (_hook != null)
                {
                    _hook.Dispose();
                    _hook = null;
                }
            }

            if (_hook == null)
            {
                _timer.Enabled = true;
                if (control != null)
                {
                    control.GiveFeedback += OnControlGiveFeedback;
                }
            }
            else
            {
                _hook.MouseMove += (s, e) =>
                {
                    if (InvokeRequired)
                    {
                        BeginInvoke(new Action <Point>(UpdatePosition), e.Location);
                    }
                    else
                    {
                        UpdatePosition(e.Location);
                    }
                };
                _hook.MouseWheel += (s, e) =>
                {
                    if (e.Delta == 0)
                    {
                        return;
                    }
                    var h = User32.WindowFromPoint(new POINT(e.X, e.Y));
                    if (h == IntPtr.Zero)
                    {
                        return;
                    }
                    User32.SendMessage(h, WM.MOUSEWHEEL, (IntPtr)(e.Delta << 16), (IntPtr)((e.Y << 16) | e.X));
                };
            }
        }