Exemplo n.º 1
0
        /// <summary>
        /// FF: If this doesn't work (and I guess it won't), we may have to use SetCapture/ReleaseCapture Win32 api
        /// http://winapi.freetechsecrets.com/win32/WIN32SetCapture.htm
        /// </summary>
        /// <param name="wndHandle"></param>
        /// <param name="delay"></param>
        /// <returns></returns>
        public static Win32.POINT GetPointOnClick(IntPtr wndHandle, int delay = 20)
        {
            Win32.POINT clientPoint = new Win32.POINT();

            if (wndHandle != IntPtr.Zero)
            {
                Thread.Sleep(delay);
                while (true)
                {
                    // Listen to Left Mouse Click event
                    //      0	= Has not been pressed since the last call
                    //      1	= Is not currently pressed, but has been pressed since the last call
                    // -32767	= Is currently pressed
                    var keyState = Win32.Win32.GetAsyncKeyState((ushort)KeyboardHelper.VirtualKeys.VK_LBUTTON);
                    if (keyState == Int16.MinValue)
                    {
                        if (Win32.Win32.GetCursorPos(ref clientPoint))
                        {
                            // get screen coordinates
                            Win32.Win32.ClientToScreen(wndHandle, ref clientPoint);
                        }
                    }
                }
            }

            return(clientPoint);
        }
 IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
 {
     switch (msg)
     {
     case 0x0024:
         Win32.MINMAXINFO mmi     = (Win32.MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(Win32.MINMAXINFO));
         IntPtr           monitor = Win32.MonitorFromWindow(hwnd, 0x00000002 /*MONITOR_DEFAULTTONEAREST*/);
         if (monitor != IntPtr.Zero)
         {
             Win32.MONITORINFO monitorInfo = new Win32.MONITORINFO {
             };
             Win32.GetMonitorInfo(monitor, monitorInfo);
             Win32.RECT rcWorkArea    = monitorInfo.rcWork;
             Win32.RECT rcMonitorArea = monitorInfo.rcMonitor;
             mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
             mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
             mmi.ptMaxSize.x     = Math.Abs(rcWorkArea.right - rcWorkArea.left);
             mmi.ptMaxSize.y     = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
             if (!CachedMinTrackSize.Equals(mmi.ptMinTrackSize) || CachedMinHeight != MinHeight && CachedMinWidth != MinWidth)
             {
                 mmi.ptMinTrackSize.x = (int)((CachedMinWidth = MinWidth) * WindowCompositionTarget.TransformToDevice.M11);
                 mmi.ptMinTrackSize.y = (int)((CachedMinHeight = MinHeight) * WindowCompositionTarget.TransformToDevice.M22);
                 CachedMinTrackSize   = mmi.ptMinTrackSize;
             }
         }
         Marshal.StructureToPtr(mmi, lParam, true);
         handled = true;
         break;
     }
     return(IntPtr.Zero);
 }
Exemplo n.º 3
0
 private IntPtr ReplacementWndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
 {
     if (msg == (uint)Win32.WM_LBUTTONDOWN || msg == (uint)Win32.WM_LBUTTONDBLCLK)
     {
         Win32.POINT loc = new Win32.POINT();
         loc.X = MousePosition.X;
         loc.Y = MousePosition.Y;
         Win32.ScreenToClient(DropDownHandle, ref loc);
         Win32.RECT dropdown_rect = new Win32.RECT();
         Win32.GetClientRect(DropDownHandle, out dropdown_rect);
         if (dropdown_rect.Left <= loc.X && loc.X < dropdown_rect.Right && dropdown_rect.Top <= loc.Y && loc.Y < dropdown_rect.Bottom)
         {
             int index = (int)Win32.SendMessage(DropDownHandle, Win32.LB_ITEMFROMPOINT, IntPtr.Zero, (IntPtr)(loc.X + (loc.Y << 16)));
             if (index >> 16 == 0)
             {
                 Object o = Items[index];
                 IEnableableComboBoxItem enableableComboBoxItem = o as IEnableableComboBoxItem;
                 if (enableableComboBoxItem != null && !enableableComboBoxItem.Enabled)
                 {
                     return(IntPtr.Zero);
                 }
             }
         }
     }
     return(Win32.CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Simple capture implementation using C# high level functions.
        /// It should only work when BlueStack is fully visible (NOT background mode).
        /// </summary>
        /// <param name="rect"></param>
        /// <returns></returns>
        public bool DotNetSnapShot(Rectangle rect)
        {
            IntPtr hWnd = GetHWnd();

            FreeCurrentImage();
            if (rect.IsEmpty)
            {
                rect = GetBSArea(hWnd);
            }
            Point topleft     = new Point(rect.Left, rect.Top);
            Point bottomright = new Point(rect.Right, rect.Bottom);

            if (!Win32.Win32.ClientToScreen(hWnd, ref topleft))
            {
                return(false);
            }

            //Create a new bitmap.
            BitMap = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);

            // Create a graphics object from the bitmap.
            using (var gfxScreenshot = Graphics.FromImage(BitMap))
            {
                // Take the screenshot from the upper left corner to the right bottom corner.
                gfxScreenshot.CopyFromScreen(topleft.X, topleft.Y, 0, 0, new Size(rect.Width, rect.Height), CopyPixelOperation.SourceCopy);
            }
            if (!FillDataFromBitmap())
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 5
0
 private void UpdateTreeViewExpandingState()
 {
     Win32.POINT point = new Win32.POINT();
     if (Win32.GetCursorPos(ref point))
     {
         Point pos = new Point(point.X, point.Y);
         pos = treeView.PointFromScreen(pos);
         HitTestResult result = VisualTreeHelper.HitTest(treeView, pos);
         if (result != null)
         {
             TreeViewItem selectedItem = Utils.FindVisualParent <TreeViewItem>(result.VisualHit);
             if (selectedItem != null)
             {
                 if (mHoveredItem != selectedItem)
                 {
                     mHoveredItem    = selectedItem;
                     mStartHoverTime = DateTime.Now;
                 }
                 else
                 {
                     if (mHoveredItem.Items.Count > 0 && !mHoveredItem.IsExpanded &&
                         DateTime.Now - mStartHoverTime > TimeSpan.FromSeconds(2))
                     {
                         mHoveredItem.IsExpanded = true;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
        void OnSizeLocationChanged()
        {
            try
            {
                if (this.Visibility == System.Windows.Visibility.Visible)
                {
                    Point             offset     = _placementTarget.TranslatePoint(new Point(), Owner);
                    Point             size       = new Point(_placementTarget.ActualWidth, _placementTarget.ActualHeight);
                    HwndSource        hwndSource = (HwndSource)HwndSource.FromVisual(Owner);
                    CompositionTarget ct         = hwndSource.CompositionTarget;
                    offset = ct.TransformToDevice.Transform(offset);
                    size   = ct.TransformToDevice.Transform(size);

                    Win32.POINT screenLocation = new Win32.POINT(offset);
                    Win32.ClientToScreen(hwndSource.Handle, ref screenLocation);
                    Win32.POINT screenSize = new Win32.POINT(size);
                    try
                    {
                        Win32.MoveWindow(((HwndSource)HwndSource.FromVisual(this)).Handle, screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y, true);
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }
        }
Exemplo n.º 7
0
        private void Move()
        {
            if ((DoubleUtil.IsZero(_draggingContainer.ActualWidth) || DoubleUtil.IsZero(_draggingContainer.ActualHeight)) &&
                _draggingContainer.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
            {
                return;
            }

            var screenPos = new Win32.POINT();

            if (!Win32.GetCursorPos(ref screenPos))
            {
                return;
            }

            var draggingPoint = _treeView.PointFromScreen(new Point(screenPos.X, screenPos.Y));

            if (DoubleUtil.GreaterThan(draggingPoint.X, _treeView.ActualWidth) || DoubleUtil.LessThan(draggingPoint.X, 0) ||
                DoubleUtil.LessThan(draggingPoint.Y, 0) || DoubleUtil.GreaterThan(draggingPoint.Y, _treeView.ActualHeight))
            {
                _overDragArea = OverlapArea.Out;
                OnOverlapItem?.Invoke(_overDragArea, _overlapItem, _draggingContainer);
                return;
            }

            _overlapItem = GetOverlapItem(_treeView, draggingPoint);
            OnOverlapItem?.Invoke(_overDragArea, _overlapItem, _draggingContainer);
        }
Exemplo n.º 8
0
        private void Move()
        {
            if (DoubleUtil.IsZero(_draggingContainer.ActualWidth) || DoubleUtil.IsZero(_draggingContainer.ActualHeight))
            {
                return;
            }

            var screenPos = new Win32.POINT();

            if (!Win32.GetCursorPos(ref screenPos))
            {
                return;
            }

            var draggingPoint = _itemsControl.PointFromScreen(new Point(screenPos.X, screenPos.Y));

            if (DoubleUtil.GreaterThan(draggingPoint.X, _itemsControl.ActualWidth) || DoubleUtil.LessThan(draggingPoint.X, 0) ||
                DoubleUtil.LessThan(draggingPoint.Y, 0) || DoubleUtil.GreaterThan(draggingPoint.Y, _itemsControl.ActualHeight))
            {
                _overDragArea = OverlapArea.Out;
                OnOverlapItem?.Invoke(_overDragArea, _overlapItem, _draggingContainer);
                return;
            }

            _overlapItem = GetOverlapItem(_itemsControl, draggingPoint);
            OnOverlapItem?.Invoke(_overDragArea, _overlapItem, _draggingContainer);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Returns a pixel from the client area of BlueStack.
 /// Capture will be done or refreshed automatically has needed
 /// </summary>
 /// <param name="point"></param>
 /// <param name="forceCapture">If set to true, then a new Capture of the full client area will be done first</param>
 /// <returns>An int 0x00RRGGBB, or -1 as an error</returns>
 static public int GetPixel(Point point, bool forceCapture = false)
 {
     if (!TakeFullScreenCapture(forceCapture))
     {
         return(-1);
     }
     return(FastFindWrapper.GetPixel(point.X, point.Y, DEFAULT_SNAP));
 }
Exemplo n.º 10
0
        /// <summary>
        /// Sends a win32 message to get the scrollbars' position.
        /// </summary>
        /// <returns>a POINT structre containing horizontal
        ///       and vertical scrollbar position.</returns>
        private unsafe Win32.POINT GetScrollPos()
        {
            Win32.POINT res = new Win32.POINT();
            IntPtr      ptr = new IntPtr(&res);

            Win32.SendMessage(Handle, Win32.EM_GETSCROLLPOS, 0, ptr);
            return(res);
        }
Exemplo n.º 11
0
            public override void GetMouseInfo(WindowFrame window, out int mx, out int my, out uint buttons)
            {
                Win32.POINT mp = new Win32.POINT();
                Win32.GetCursorPos(ref mp);

                mx      = mp.X; my = mp.Y;
                buttons = (uint)((((Win32.GetKeyState(1) & 1) != 0) ? 1 : 0) | (((Win32.GetKeyState(2) & 1) != 0) ? 2 : 0));
            }
Exemplo n.º 12
0
        /// <summary>
        /// マウスをタッチイベントとしてシミュレートする
        /// </summary>
        void MouseToTouch()
        {
            if (!control.Created)
            {
                return;
            }

            // マウス座標と左ボタンの状態を得る
            Point p         = System.Windows.Forms.Cursor.Position; // スクリーン座標系
            bool  lButton   = (System.Windows.Forms.Form.MouseButtons & MouseButtons.Left) != 0;
            bool  clickDown = lButton & !lastLButtonStatus;

            lastLButtonStatus = lButton;

            // クライアント座標系に変換。
            IntPtr controlHanle = control.Handle;

            Win32.POINT pt = new Win32.POINT()
            {
                X = p.X, Y = p.Y
            };
            Win32.ScreenToClient(controlHanle, ref pt);
            p = new Point(pt.X, pt.Y);

            //
            if (clickDown && mouseInput == null)
            {
                if (control.ClientRectangle.Contains(p))
                {
                    mouseInput = new Touch()
                    {
                        ID       = -1,
                        Duration = 0,
                        Src      = IntPtr.Zero,
                        LifeTime = 30,
                        Primary  = true,
                        Current  = new Touch.TouchStatus()
                        {
                            Touched = true, InRange = true, X = p.X, Y = p.Y, Width = 10, Height = 10,
                        },
                        Previous = new Touch.TouchStatus(),
                    };
                    activeItems.Add(mouseInput);
                }
            }

            if (mouseInput != null)
            {
                mouseInput.Current.X = p.X;
                mouseInput.Current.Y = p.Y;
            }

            if (mouseInput != null && !lButton)
            {
                mouseInput.Current.Touched = false;
                mouseInput = null;
            }
        }
Exemplo n.º 13
0
 public void SaveState(bool saveScrollBars)
 {
     savedSelStart = SelectionStart;
     savedSelLen   = SelectionLength;
     if (saveScrollBars)
     {
         savedScrollPos = GetScrollPos();
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Returns a pixel from the client area of BlueStack.
        /// Capture will be done or refreshed automatically has needed
        /// </summary>
        /// <param name="point"></param>
        /// <param name="forceCapture">If set to true, then a new Capture of the full client area will be done first</param>
        /// <returns>A C# Color structure representing the color of that pixel. Returns Color.Empty as an error</returns>
        static public Color GetPixelColor(Point point, bool forceCapture = false)
        {
            if (!TakeFullScreenCapture(forceCapture))
            {
                return(Color.Empty);
            }
            int value = FastFindWrapper.GetPixel(point.X, point.Y, DEFAULT_SNAP);

            return(System.Drawing.Color.FromArgb(value));
        }
    public void MoveCursor(int x, int y)
    {
        Win32.POINT p = new Win32.POINT
        {
            x = x,
            y = y
        };

        Win32.SetCursorPos(p.x, p.y);
    }
Exemplo n.º 16
0
        /// <summary>
        /// WM_TOUCH メッセージから TouchEvent を発火します。
        /// </summary>
        /// <param name="m"></param>
        public void DecodeTouch(ref Message m)
        {
            if (m.Msg != Win32.WM_TOUCH)
            {
                // WM_TOUCHではない。
                return;
            }

            int touchInputSize = Marshal.SizeOf(inputBuffer[0]);
            int inputCount     = (ushort)m.WParam.ToInt32();

            if (inputCount > inputBuffer.Length)
            {
                Win32.CloseTouchInputHandle(m.LParam);
                m.Result = IntPtr.Zero;
                return;
            }

            if (!Win32.GetTouchInputInfo(m.LParam, inputCount, inputBuffer, touchInputSize))
            {
                Win32.CloseTouchInputHandle(m.LParam);
                m.Result = IntPtr.Zero;
                Debug.Print("Error on GetTouchInputInfo.");
                return;
            }

            for (int i = 0; i < inputCount; i++)
            {
                TouchEvent e = inputBuffer[i];

                Win32.POINT p = new Win32.POINT()
                {
                    X = e.X / 100, Y = e.Y / 100
                };
                Win32.ScreenToClient(m.HWnd, ref p);
                e.X      = p.X;
                e.Y      = p.Y;
                e.Width  = e.HasContact ? e.Width / 100 : 0;
                e.Height = e.HasContact ? e.Height / 100 : 0;

                //Debug.Print("ID{4}-{7} x{0} y{1} w{2} h{3} P{5} R{6}",
                //    e.X, e.Y, e.Width, e.Height, e.ID,
                //    e.Primary, e.InRange,
                //    (e.Down ? "D" : e.Up ? "U" : "M")
                //    );

                if (TouchEvent != null)
                {
                    TouchEvent(this, e);
                }
            }

            Win32.CloseTouchInputHandle(m.LParam);
            return;
        }
Exemplo n.º 17
0
        protected virtual void HandlePrintPage(object sender, sdp.PrintPageEventArgs e)
        {
            using (var graphics = e.Graphics.ToEto(false))
            {
                var bounds    = e.MarginBounds;
                var container = _control.GetContainerControl();
                if (container != null)
                {
                    container.SuspendLayout();
                    container.Width  = (int)Math.Max(bounds.Width, _preferredSize.Width);
                    container.Height = (int)Math.Max(bounds.Height, _preferredSize.Height);
                    container.ResumeLayout();

                    // create an offscreen bitmap to paint to
                    var bitmapSize = bounds.Size;
                    if (_controlBitmap == null || _controlBitmap.Size != bitmapSize)
                    {
                        _controlBitmap?.Dispose();
                        _controlBitmap = new sd.Bitmap(bitmapSize.Width, bitmapSize.Height, sd.Imaging.PixelFormat.Format32bppArgb);
                    }

                    // setup a graphics object to paint to
                    sd.Graphics g   = sd.Graphics.FromImage(_controlBitmap);
                    var         hdc = g.GetHdc();

                    // set the offset for the current page
                    var y         = _currentPage * bounds.Height;
                    var oldOffset = new Win32.POINT();
                    Win32.OffsetWindowOrgEx(hdc, 0, y, ref oldOffset);

                    // send the WM_PRINT message
                    Win32.SendMessage(
                        container.Handle,
                        Win32.WM.PRINT,
                        hdc,
                        (IntPtr)(Win32.PRF.CHILDREN | Win32.PRF.CLIENT | Win32.PRF.ERASEBKGND | Win32.PRF.NONCLIENT));

                    // restore offset
                    Win32.OffsetWindowOrgEx(hdc, oldOffset.x, oldOffset.y, ref oldOffset);

                    g.ReleaseHdc(hdc);
                    g.Dispose();

                    // draw the image to the print graphics context
                    e.Graphics.DrawImage(_controlBitmap, bounds);
                }

                graphics.TranslateTransform(bounds.Left, bounds.Top);
                var args = new PrintPageEventArgs(graphics, bounds.Size.ToEto(), _currentPage);
                Callback.OnPrintPage(Widget, args);
                _currentPage++;
                e.HasMorePages = _currentPage < PageCount;
            }
        }
Exemplo n.º 18
0
        private void DrawUnderline(IntPtr hdc, uint col, int x, int y, int length)
        {
            //Underlineがつくことはあまりないだろうから毎回Penを作る。問題になりそうだったらそのときに考えよう
            IntPtr pen  = Win32.CreatePen(0, 1, col);
            IntPtr prev = Win32.SelectObject(hdc, pen);

            Win32.POINT pt = new Win32.POINT();
            Win32.MoveToEx(hdc, x, y, out pt);
            Win32.LineTo(hdc, x + length, y);
            Win32.SelectObject(hdc, prev);
            Win32.DeleteObject(pen);
        }
Exemplo n.º 19
0
        private bool ClientToWindow(IntPtr hWnd, ref Rectangle rect)
        {
            Rect rWindow = new Rect();
            Rect rClient = new Rect();

            Win32.Win32.GetWindowRect(hWnd, out rWindow);
            Win32.Win32.GetClientRect(hWnd, out rClient);
            Point topleft = new Point(rClient.Left, rClient.Top);

            Win32.Win32.ClientToScreen(hWnd, ref topleft);
            rect.Offset(topleft.X - rWindow.Left, topleft.Y - rWindow.Top);
            return(true);
        }
Exemplo n.º 20
0
 private void on_size_and_location_changing()
 {
     if ((XPorter.Bus.Main_Handle.MainTab.SelectedItem == Item) && (this.IsVisible))
     {
         HwndSource        hwnd_source     = (HwndSource)HwndSource.FromVisual(Owner);
         CompositionTarget compose_target  = hwnd_source.CompositionTarget;
         Point             offset          = compose_target.TransformToDevice.Transform(XPorter.Bus.Global_Offset_Tabs);
         Point             size            = compose_target.TransformToDevice.Transform(XPorter.Bus.Global_Size_Tabs);
         Win32.POINT       screen_location = new Win32.POINT(offset);
         Win32.ClientToScreen(hwnd_source.Handle, ref screen_location);
         Win32.POINT screen_size = new Win32.POINT(size);
         Win32.MoveWindow(((HwndSource)HwndSource.FromVisual(this)).Handle, screen_location.X, screen_location.Y, screen_size.X, screen_size.Y, true);
     }
 }
Exemplo n.º 21
0
        public static void Load()
        {
            WindowMainMenu window = new WindowMainMenu();

            Win32.POINT point = new Win32.POINT();
            Win32.GetCursorPos(out point);

            double x = SystemParameters.WorkArea.Width;  //得到屏幕工作区域宽度
            double y = SystemParameters.WorkArea.Height; //得到屏幕工作区域高度

            window.Left = point.X - window.Width;
            window.Top  = point.Y - window.Height;

            window.Show();
        }
Exemplo n.º 22
0
            public static void dock_panel_prev_mouse_down(object sender, MouseButtonEventArgs e)
            {
                ContentControl connector_panel = (ContentControl)((DockPanel)sender).TemplatedParent;
                Panel          trgt_panel      = connector_panel.Parent as Panel;
                MainWindow     m_window        = (MainWindow)MainWindow.GetWindow((DockPanel)sender);

                Old_P = e.GetPosition(m_window);
                System.Windows.Point cn_xy = e.GetPosition(connector_panel);

                //------------------------------------------------------------------------------------//
                System.Windows.Point offset     = Target_Panel.TranslatePoint(new System.Windows.Point(), XPorter.Bus.Main_Handle);
                System.Windows.Point size       = new System.Windows.Point(Target_Panel.ActualWidth, Target_Panel.ActualHeight);
                HwndSource           hwndSource = (HwndSource)HwndSource.FromVisual(XPorter.Bus.Main_Handle);
                CompositionTarget    ct         = hwndSource.CompositionTarget;

                offset = ct.TransformToDevice.Transform(offset);
                size   = ct.TransformToDevice.Transform(size);
                Win32.POINT screenLocation = new Win32.POINT(offset);
                Win32.ClientToScreen(hwndSource.Handle, ref screenLocation);
                Win32.POINT screenSize = new Win32.POINT(size);

                System.Windows.Forms.Cursor.Clip = new System.Drawing.Rectangle(screenLocation.X + (int)cn_xy.X,
                                                                                screenLocation.Y + (int)cn_xy.Y, screenSize.X - (int)connector_panel.Width + 1,
                                                                                screenSize.Y - (int)connector_panel.Height + 1);
                //if (m_window.WindowState == System.Windows.WindowState.Normal)                                                      //if position is normal we can clip mouse
                //{
                //    System.Windows.Forms.Cursor.Clip = new System.Drawing.Rectangle(
                //        (int)m_window.Left + (int)cn_xy.X + 4,
                //        (int)m_window.Top + (int)cn_xy.Y + 2 + XPorter.Bus.Top,
                //        (int)m_window.Width - (int)connector_panel.Width - 7,
                //        (int)m_window.Height - (int)connector_panel.Height - 4 - XPorter.Bus.Top - XPorter.Bus.Bottom);
                //}
                //else
                //{
                //    System.Drawing.Rectangle MaximizePadding = new System.Drawing.Rectangle(
                //        (int)SystemParameters.WorkArea.Left, (int)SystemParameters.WorkArea.Top,
                //        (int)(SystemParameters.PrimaryScreenWidth - SystemParameters.WorkArea.Right),
                //        (int)(SystemParameters.PrimaryScreenHeight - SystemParameters.WorkArea.Bottom));

                //    System.Windows.Forms.Cursor.Clip = new System.Drawing.Rectangle(
                //       MaximizePadding.Left - 3 + (int)cn_xy.X,
                //       MaximizePadding.Top + (int)cn_xy.Y + XPorter.Bus.Top - 5,
                //       (int)trgt_panel.ActualWidth - MaximizePadding.Width - (int)connector_panel.ActualWidth - 7,
                //       (int)trgt_panel.ActualHeight - MaximizePadding.Height -
                //       (int)connector_panel.ActualHeight - 4 - XPorter.Bus.Top - XPorter.Bus.Bottom);
                //}
                ((DockPanel)sender).CaptureMouse();
            }
Exemplo n.º 23
0
        public DeviceStatus(RawDevice device)
        {
            this.device = device;

            debugCursor      = new DebugCursor();
            debugCursor.Name = "DebugCursor";
            Win32.POINT position = Win32.GetCursorPosition();
            Location = new Point(position.x, position.y);

            Thread t = new Thread(ThreadWorker);

            t.Name = "Cursor for device: " + device.Handle;
            t.SetApartmentState(ApartmentState.STA);
            t.IsBackground = true;
            t.Start();
        }
        private void Move()
        {
            if (_draggingContainer.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
            {
                return;
            }

            var screenPos = new Win32.POINT();

            if (!Win32.GetCursorPos(ref screenPos))
            {
                return;
            }

            var posToPanel   = treeView.PointFromScreen(new Point(screenPos.X, screenPos.Y));
            var draggingRect = new Rect(posToPanel.X - _cacheMouseDownPosToChild.X, posToPanel.Y - _cacheMouseDownPosToChild.Y, _draggingContainer.ActualWidth, _draggingContainer.ActualHeight);

            if (DoubleUtil.GreaterThan(draggingRect.X, treeView.ActualWidth * 3 / 4) ||
                DoubleUtil.LessThan(draggingRect.Right, treeView.ActualWidth / 4) ||
                DoubleUtil.LessThan(draggingRect.Bottom, 0) ||
                DoubleUtil.GreaterThan(draggingRect.Y, treeView.ActualHeight))
            {
                return;
            }

            var sourcePos = _draggingContainer.TranslatePoint(new Point(), treeView);
            var isSuccess = false;

            if (MoveDirection(sourcePos, draggingRect))
            {
                isSuccess = MoveUp(treeView, draggingRect, ref _draggingContainer, ref _lastOverlapContainer, ref _startOverlapTime);
            }
            else
            {
                isSuccess = MoveDown(treeView, draggingRect, ref _draggingContainer, ref _lastOverlapContainer, ref _startOverlapTime);
            }

            if (isSuccess && _draggingContainer != null)
            {
                _draggingContainer.Focus();
                _draggingContainer.Opacity = 0.2;

                _testSource.ItemsChangedFlag = !_testSource.ItemsChangedFlag;
            }
        }
Exemplo n.º 25
0
        public void Reposition()
        {
            _repositionCallback = null;

            System.Windows.Point offset     = _placementTarget.TranslatePoint(new System.Windows.Point(), _owner);
            System.Windows.Point size       = new System.Windows.Point(_placementTarget.ActualWidth, _placementTarget.ActualHeight);
            HwndSource           hwndSource = (HwndSource)HwndSource.FromVisual(_owner);
            CompositionTarget    ct         = hwndSource.CompositionTarget;

            offset = ct.TransformToDevice.Transform(offset);
            size   = ct.TransformToDevice.Transform(size);

            Win32.POINT screenLocation = new Win32.POINT(offset);
            Win32.ClientToScreen(hwndSource.Handle, ref screenLocation);
            Win32.POINT screenSize = new Win32.POINT(size);

            Win32.MoveWindow(_form.Handle, screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y, true);
        }
Exemplo n.º 26
0
    private void button1_Click(object sender, EventArgs e)
    {
        Win32.POINT p = new Win32.POINT();
        //p.x = Convert.ToInt16(txtMouseX.Text);
        //p.y = Convert.ToInt16(txtMouseY.Text);
        p.x = 100;
        p.y = 100;
        Win32.ClientToScreen(this.Handle, ref p);
        Win32.SetCursorPos(p.x, p.y);



        //// Set the Current cursor, move the cursor's Position,
        //// and set its clipping rectangle to the form.
        //this.Cursor = new Cursor(Cursor.Current.Handle);
        //Cursor.Position = new Point(Cursor.Position.X - 50, Cursor.Position.Y - 50);
        //Cursor.Clip = new Rectangle(this.Location, this.Size);
    }
Exemplo n.º 27
0
        /// <summary>
        /// Moves the cursor to (10,10)
        /// when the STOP action is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Stop_Clicked(object sender, RoutedEventArgs e)
        {
            //Console.WriteLine("Stop Button clicked.");
            //timer.Enabled = true;
            Win32.POINT p = new Win32.POINT();
            p.x = 10;
            p.y = 10;
            Win32.SetCursorPos(p.x, p.y);

            //Point p = upLeftButton.PointToScreen(new Point(0, 0));
            ////Console.WriteLine("P({0},{1})", p.X, p.Y);
            //UpdateBounds();

            /*foreach (Point point in this.testPoints)
             * {
             *  BoundsCheck(point);
             * }*/
        }
Exemplo n.º 28
0
        protected override void OnLayout(LayoutEventArgs levent)
        {
            if (root != null && this.Parent != null)
            {
                //This is needed to maximize and minimize properly, there is some issue in the ListView Control
                Win32.POINT pt      = new Win32.POINT();
                IntPtr      hResult = SendMessage(Handle, LVM_GETORIGIN, IntPtr.Zero, ref pt);

                origin = pt;
                root.InvalidateAll();
                int x = Math.Max(this.HGap, this.Size.Width / 2 - root.SubtreeWidth / 2);
                int y = Math.Max(this.VGap, this.Size.Height / 2 - root.SubtreeHeight / 2);
                PositionSnapshots(root, x, y);
                Invalidate();

                whiteIcon.Position = new Point(x + origin.X, y + root.SubtreeHeight - 20 + origin.Y);
            }
        }
Exemplo n.º 29
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            if (AdornedElement != null)
            {
                var screenPos = new Win32.POINT();
                if (Win32.GetCursorPos(ref screenPos))
                {
                    var pos  = AdornedElement.PointFromScreen(new Point(screenPos.X, screenPos.Y));
                    var rect = new Rect(new Point(pos.X - _posRelative.X, pos.Y - _posRelative.Y), _adornerElementSize);

                    //System.Diagnostics.Trace.TraceInformation("Adorner Pos = {0},{1},{2},{3}", rect.X, rect.Y, rect.Width, rect.Height);

                    drawingContext.DrawRectangle(_imageBrush, null, rect);
                }
            }
        }
Exemplo n.º 30
0
        void DataTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (e.AddedItems.Count > 0)
                {
                    if ((e.AddedItems[0] as TabItem) != null)
                    {
                        if (IsChild((e.AddedItems[0] as TabItem), _placementTarget))
                        {
                            Show();
                            Point _offset = _placementTarget.TranslatePoint(new Point(), Owner);
                            if (offset.X < _offset.X || offset.Y < _offset.Y)
                            {
                                offset = _offset;

                                Point             size       = new Point(_placementTarget.ActualWidth, _placementTarget.ActualHeight);
                                HwndSource        hwndSource = (HwndSource)HwndSource.FromVisual(Owner);
                                CompositionTarget ct         = hwndSource.CompositionTarget;
                                offset = ct.TransformToDevice.Transform(offset);
                                size   = ct.TransformToDevice.Transform(size);

                                Win32.POINT screenLocation = new Win32.POINT(offset);
                                Win32.ClientToScreen(hwndSource.Handle, ref screenLocation);
                                Win32.POINT screenSize = new Win32.POINT(size);

                                Win32.MoveWindow(((HwndSource)HwndSource.FromVisual(this)).Handle, screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y, true);
                            }
                        }
                        else
                        {
                            Hide();
                        }
                    }
                    else
                    {
                        Hide();
                    }
                }
            }
            catch
            {
            }
        }
Exemplo n.º 31
0
 public void SaveState(bool saveScrollBars)
 {
     savedSelStart = SelectionStart;
     savedSelLen = SelectionLength;
     if (saveScrollBars)
         savedScrollPos = GetScrollPos();
 }
Exemplo n.º 32
0
    public void SetBits(Bitmap bitmap, byte opacity)
    {
        if (!Bitmap.IsCanonicalPixelFormat(bitmap.PixelFormat) || !Bitmap.IsAlphaPixelFormat(bitmap.PixelFormat))
            throw new ApplicationException("The bitmap must be 32 bits per pixel with an alpha channel.");

        IntPtr oldBits = IntPtr.Zero;
        IntPtr screenDC = Win32.GetDC(IntPtr.Zero);
        IntPtr hBitmap = IntPtr.Zero;
        IntPtr memDc = Win32.CreateCompatibleDC(screenDC);
        Win32.POINT topLoc = new Win32.POINT(Left, Top);
        Win32.SIZE bitMapSize = new Win32.SIZE(bitmap.Width, bitmap.Height);
        Win32.BLENDFUNCTION blendFunc = new Win32.BLENDFUNCTION();
        Win32.POINT srcLoc = new Win32.POINT(0, 0);
        blendFunc.BlendOp = Win32.AC_SRC_OVER;
        blendFunc.SourceConstantAlpha = opacity;
        blendFunc.AlphaFormat = Win32.AC_SRC_ALPHA;
        blendFunc.BlendFlags = 0;

        try
        {
            hBitmap = bitmap.GetHbitmap(Color.FromArgb(0));
            oldBits = Win32.SelectObject(memDc, hBitmap);
            Win32.UpdateLayeredWindow(Handle, screenDC, ref topLoc, ref bitMapSize, memDc, ref srcLoc, 0, ref blendFunc, Win32.ULW_ALPHA);
        }
        finally
        {
            if (hBitmap != IntPtr.Zero)
            {
                Win32.SelectObject(memDc, oldBits);
                Win32.DeleteObject(hBitmap);
            }
            Win32.ReleaseDC(IntPtr.Zero, screenDC);
            Win32.DeleteDC(memDc);
        }
    }
Exemplo n.º 33
0
        private void prvStyledDashedLine(Graphics g, int LinePattern, Color LineColor, int LineWidth, int x1, int y1, int x2, int y2,
            out int iTab, out double dPos)
        {
            IntPtr hdc = g.GetHdc();
            Win32.POINT oP = new Win32.POINT();

            double dPatternPosition = 0;

            double dxx = (x2 - x1);
            double dyy = (y2 - y1);
            double dLen = Math.Sqrt(dxx * dxx + dyy * dyy);

            iTab = 0;
            dPos = 0;
            if (dLen == 0) return;

            double dX = (x2 - x1) / dLen;
            double dY = (y2 - y1) / dLen;

            double x = x1;
            double y = y1;
            int ix1 = 0, ix2 = 0, iy1 = 0, iy2 = 0;
            do
            {
                if ((iTab & 1) == 0)
                { // draw forecolor
                    ix1 = (int)(x + dX * dPatternPosition);
                    iy1 = (int)(y + dY * dPatternPosition);

                    dPatternPosition += dashArray[iTab] - dPos;
                    if (dPatternPosition >= dLen)
                    {
                        dPos = dashArray[iTab] - (dPatternPosition - dLen);
                        dPatternPosition = dLen;
                    }
                    else
                    {
                        iTab++;
                        if (iTab >= dashArrayLen) iTab = 0;
                        dPos = 0;
                    }
                    ix2 = (int)(x + dX * dPatternPosition);
                    iy2 = (int)(y + dY * dPatternPosition);

                    Win32.GDI.MoveToEx(hdc, ix1, iy1, ref oP);
                    Win32.GDI.LineTo(hdc, ix2, iy2);

                    //g.DrawLine(new Pen(LineColor), ix1, iy1, ix2, iy2);
                }
                else
                { // draw background
                    dPatternPosition += dashArray[iTab] - dPos;
                    if (dPatternPosition >= dLen)
                    {
                        dPos = dashArray[iTab] - (dPatternPosition - dLen);
                        dPatternPosition = dLen;
                    }
                    else
                    {
                        iTab++;
                        if (iTab >= dashArrayLen) iTab = 0;
                        dPos = 0;
                    }
                }
            } while (dPatternPosition < dLen);

            g.ReleaseHdc();

            return;  // correct this
        }
Exemplo n.º 34
0
	/// <summary>
	/// Redraws the bitmap overlay.
	/// </summary>
	/// <returns>True if successful, false otherwise.</returns>
	protected bool RefreshBitmap()
	{
		// The bitmap must be 32-bit RGBA
		if (_bitmap == null || _bitmap.PixelFormat != PixelFormat.Format32bppArgb)
			return false;

		// Create a memory DC that's compatible with the screen
		IntPtr screenDC = Win32.GetDC(IntPtr.Zero);
		if (screenDC == IntPtr.Zero)
			return false;

		IntPtr memDC = GDI32.CreateCompatibleDC(screenDC);
		if (memDC == IntPtr.Zero)
		{
			Win32.ReleaseDC(IntPtr.Zero, screenDC);
			return false;
		}

		// Prepare to draw the bitmap
		IntPtr hBitmap = IntPtr.Zero;
		IntPtr oldBitmap = IntPtr.Zero;

		bool success = false;

		try
		{
			// Select the bitmap into the memory DC
			hBitmap = _bitmap.GetHbitmap(Color.FromArgb(0));  // grab a GDI handle from this GDI+ bitmap
			oldBitmap = GDI32.SelectObject(memDC, hBitmap);

			// Call UpdateLayeredWindow to effectively blit the contents of the memory DC into the form while performing alpha blending
			Win32.POINT windowTopLeft = new Win32.POINT(Left, Top);

			Win32.SIZE bitmapSize = new Win32.SIZE(_bitmap.Width, _bitmap.Height);
			Win32.POINT bitmapTopLeft = new Win32.POINT(0, 0);

			byte blendAlpha = 0;
			if (_bitmapOpacity < 0)
				blendAlpha = 0;
			else if (_bitmapOpacity > 1)
				blendAlpha = 255;
			else
				blendAlpha = (byte)(_bitmapOpacity * 255);

			GDI32.BLENDFUNCTION blendFunc = new GDI32.BLENDFUNCTION();
			blendFunc.BlendOp = GDI32.AC_SRC_OVER;
			blendFunc.BlendFlags = 0;
			blendFunc.SourceConstantAlpha = blendAlpha;
			blendFunc.AlphaFormat = GDI32.AC_SRC_ALPHA;

			Win32.UpdateLayeredWindow(Handle, screenDC, ref windowTopLeft, ref bitmapSize, memDC, ref bitmapTopLeft, 0, ref blendFunc, Win32.ULW_ALPHA);

			success = true;
		}
		finally
		{
			// Clean up the resources
			if (hBitmap != IntPtr.Zero)
			{
				GDI32.SelectObject(memDC, oldBitmap);
				GDI32.DeleteObject(hBitmap);
			}

			GDI32.DeleteDC(memDC);
			Win32.ReleaseDC(IntPtr.Zero, screenDC);
		}

		return success;
	}
Exemplo n.º 35
0
        /// <summary>
        /// WM_TOUCH メッセージから TouchEvent を発火します。
        /// </summary>
        /// <param name="m"></param>
        public void DecodeTouch(ref Message m)
        {
            if (m.Msg != Win32.WM_TOUCH)
            {
                // WM_TOUCHではない。
                return;
            }

            int touchInputSize = Marshal.SizeOf(inputBuffer[0]);
            int inputCount = (ushort)m.WParam.ToInt32();
            if (inputCount > inputBuffer.Length)
            {
                Win32.CloseTouchInputHandle(m.LParam);
                m.Result = IntPtr.Zero;
                return;
            }

            if (!Win32.GetTouchInputInfo(m.LParam, inputCount, inputBuffer, touchInputSize))
            {
                Win32.CloseTouchInputHandle(m.LParam);
                m.Result = IntPtr.Zero;
                Debug.Print("Error on GetTouchInputInfo.");
                return;
            }

            for (int i = 0; i < inputCount; i++)
            {
                TouchEvent e = inputBuffer[i];

                Win32.POINT p = new Win32.POINT() { X = e.X / 100, Y = e.Y / 100 };
                Win32.ScreenToClient(m.HWnd, ref p);
                e.X = p.X;
                e.Y = p.Y;
                e.Width = e.HasContact ? e.Width / 100 : 0;
                e.Height = e.HasContact ? e.Height / 100 : 0;

                //Debug.Print("ID{4}-{7} x{0} y{1} w{2} h{3} P{5} R{6}",
                //    e.X, e.Y, e.Width, e.Height, e.ID,
                //    e.Primary, e.InRange,
                //    (e.Down ? "D" : e.Up ? "U" : "M")
                //    );

                if (TouchEvent != null)
                {
                    TouchEvent(this, e);
                }
            }

            Win32.CloseTouchInputHandle(m.LParam);
            return;
        }
Exemplo n.º 36
0
        /// <summary>
        /// マウスをタッチイベントとしてシミュレートする
        /// </summary>
        void MouseToTouch()
        {
            if (!control.Created) { return; }

            // マウス座標と左ボタンの状態を得る
            Point p = System.Windows.Forms.Cursor.Position; // スクリーン座標系
            bool lButton = (System.Windows.Forms.Form.MouseButtons & MouseButtons.Left) != 0;
            bool clickDown = lButton & !lastLButtonStatus;
            lastLButtonStatus = lButton;

            // クライアント座標系に変換。
            IntPtr controlHanle = control.Handle;
            Win32.POINT pt = new Win32.POINT() { X = p.X, Y = p.Y };
            Win32.ScreenToClient(controlHanle, ref pt);
            p = new Point(pt.X, pt.Y);

            //
            if (clickDown && mouseInput == null)
            {
                if (control.ClientRectangle.Contains(p))
                {
                    mouseInput = new Touch()
                    {
                        ID = -1,
                        Duration = 0,
                        Src = IntPtr.Zero,
                        LifeTime = 30,
                        Primary = true,
                        Current = new Touch.TouchStatus() { Touched = true, InRange = true, X = p.X, Y = p.Y, Width = 10, Height = 10, },
                        Previous = new Touch.TouchStatus(),
                    };
                    activeItems.Add(mouseInput);
                }
            }

            if (mouseInput != null)
            {
                mouseInput.Current.X = p.X;
                mouseInput.Current.Y = p.Y;
            }

            if (mouseInput != null && !lButton)
            {
                mouseInput.Current.Touched = false;
                mouseInput = null;
            }
        }
Exemplo n.º 37
0
        void Reposition()
        {
            _repositionCallback = null;

            Point offset = _placementTarget.TranslatePoint(new Point(), _owner);
            Point size = new Point(_placementTarget.ActualWidth, _placementTarget.ActualHeight);
            HwndSource hwndSource = (HwndSource)HwndSource.FromVisual(_owner);
            CompositionTarget ct = hwndSource.CompositionTarget;
            offset = ct.TransformToDevice.Transform(offset);
            size = ct.TransformToDevice.Transform(size);

            Win32.POINT screenLocation = new Win32.POINT(offset);
            Win32.ClientToScreen(hwndSource.Handle, ref screenLocation);
            Win32.POINT screenSize = new Win32.POINT(size);

            Win32.MoveWindow(_form.Handle, screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y, true);
            //_form.SetBounds(screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y);
            //_form.Update();
        }
Exemplo n.º 38
0
 private void DrawUnderline(IntPtr hdc, uint col, int x, int y, int length)
 {
     //Underline���‚����Ƃ͂��܂�Ȃ����낤���疈��Pen����B���ɂȂ肻���������炻�̂Ƃ��ɍl���悤
     IntPtr pen = Win32.CreatePen(0, 1, col);
     IntPtr prev = Win32.SelectObject(hdc, pen);
     Win32.POINT pt = new Win32.POINT();
     Win32.MoveToEx(hdc, x, y, out pt);
     Win32.LineTo(hdc, x+length, y);
     Win32.SelectObject(hdc, prev);
     Win32.DeleteObject(pen);
 }
Exemplo n.º 39
0
 /// <summary>
 /// Sends a win32 message to get the scrollbars' position.
 /// </summary>
 /// <returns>a POINT structre containing horizontal
 ///       and vertical scrollbar position.</returns>
 private unsafe Win32.POINT GetScrollPos()
 {
     Win32.POINT res = new Win32.POINT();
     IntPtr ptr = new IntPtr(&res);
     Win32.SendMessage(Handle, Win32.EM_GETSCROLLPOS, 0, ptr);
     return res;
 }
Exemplo n.º 40
0
        void OnSizeLocationChanged()
        {
            Point offset = _placementTarget.TranslatePoint(new Point(), Owner);
            Point size = new Point(_placementTarget.ActualWidth, _placementTarget.ActualHeight);
            HwndSource hwndSource = (HwndSource)HwndSource.FromVisual(Owner);
            CompositionTarget ct = hwndSource.CompositionTarget;
            offset = ct.TransformToDevice.Transform(offset);
            size = ct.TransformToDevice.Transform(size);

            Win32.POINT screenLocation = new Win32.POINT(offset);
            Win32.ClientToScreen(hwndSource.Handle, ref screenLocation);
            Win32.POINT screenSize = new Win32.POINT(size);

            Win32.MoveWindow(((HwndSource)HwndSource.FromVisual(this)).Handle, screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y, true);
        }