Пример #1
0
        //--------------------------------------------------------------------------
        public void suspendProcess(int processId, Action <object> callback)
        {
            Task.Run(() => {
                try {
                    ProcessTrackingInfo info;
                    lock (this) {
                        if (!_runningProcess.TryGetValue(processId, out info))
                        {
                            callback(new { error = "can't find process: " + processId });
                            return;
                        }
                    }


                    foreach (ProcessThread pT in info.process.Threads)
                    {
                        IntPtr thread = PInvokes.OpenThread(ThreadAccess.SUSPEND_RESUME,
                                                            false,
                                                            (uint)pT.Id);
                        if (thread == IntPtr.Zero)
                        {
                            continue;
                        }

                        SuspendThread(thread);

                        CloseHandle(thread);
                    }

                    callback(new { data = "success" });
                } catch (Exception ex) {
                    callback(new { error = "unknown exception: " + ex.ToString() });
                }
            });
        }
Пример #2
0
        public static void FocusControl(string className, string text)
        {
            var hWnd     = PInvokes.GetForegroundWindow();
            var hControl = PInvokes.FindWindowEx(hWnd, IntPtr.Zero, className, text);

            PInvokes.SetFocus(hControl);
        }
Пример #3
0
 public static Rect GetCurrentWindowRect()
 {
     PInvokes.GetWindowRect(CurrentWindowHandle, out var rect);
     return(new Rect(new System.Windows.Point()
     {
         X = rect.Left, Y = rect.Top
     }, new System.Windows.Point()
     {
         X = rect.Right, Y = rect.Bottom
     }));
 }
 public static bool IpReleaseAddress(IP_ADAPTER_INDEX_MAP adapter)
 {
     if (PInvokes.IpReleaseAddress(ref adapter) == PInvokes.ERROR_SUCCESS)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #5
0
        public static void ShowConsole()
        {
            var handle = PInvokes.GetConsoleWindow();

            if (handle == IntPtr.Zero)
            {
                PInvokes.AllocConsole();
                return;
            }

            PInvokes.ShowWindowAsync(handle, PInvokes.SW.Show);
        }
Пример #6
0
        public static void InitialConsole(bool disableCloseButton = false)
        {
            PInvokes.AllocConsole();
            var handle = PInvokes.GetConsoleWindow();

#if !DEBUG
            PInvokes.ShowWindowAsync(handle, PInvokes.SW.Hide);
            if (disableCloseButton)
            {
                DisableCloseButton();
            }
#endif
            SetConsoleCtrlHandler(handlerDelegate, true);
        }
    public static IP_INTERFACE_INFO GetInterfaceInfo()
    {
        int size = 0;
        int r    = PInvokes.GetInterfaceInfo(null, ref size);

        Byte[] buffer = new Byte[size];
        r = PInvokes.GetInterfaceInfo(buffer, ref size);
        if (r != PInvokes.ERROR_SUCCESS)
        {
            throw new Exception("GetInterfaceInfo returned an error.");
        }
        IP_INTERFACE_INFO info = IP_INTERFACE_INFO.FromByteArray(buffer);

        return(info);
    }
Пример #8
0
        public static Rect GetCurrentWindowCaretPosition()
        {
            var guiInfo = new GUITHREADINFO();

            guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo);

            PInvokes.GetGUIThreadInfo(0, out guiInfo);

            var lt = new Point((int)guiInfo.rcCaret.Left, (int)guiInfo.rcCaret.Top);
            var rb = new Point((int)guiInfo.rcCaret.Right, (int)guiInfo.rcCaret.Bottom);

            PInvokes.ClientToScreen(guiInfo.hwndCaret, out lt);
            PInvokes.ClientToScreen(guiInfo.hwndCaret, out rb);
            Console.WriteLine(lt.ToString() + rb.ToString());
            //SystemInformation.WorkingArea
            return(new Rect(new System.Windows.Point()
            {
                X = lt.X, Y = lt.Y
            }, new System.Windows.Point()
            {
                X = rb.X, Y = rb.Y
            }));
        }
Пример #9
0
 public static void Show(IntPtr hWnd)
 {
     PInvokes.ShowWindowAsync(hWnd, PInvokes.SW.Show);
     PInvokes.SetForegroundWindow(hWnd);
 }
Пример #10
0
 public IWindow Show(IntPtr hWnd)
 {
     PInvokes.ShowWindowAsync(hWnd, PInvokes.SW.Show);
     PInvokes.SetForegroundWindow(hWnd);
     return(new Window(hWnd));
 }
Пример #11
0
        public static void HideConsole()
        {
            var handle = PInvokes.GetConsoleWindow();

            PInvokes.ShowWindowAsync(handle, PInvokes.SW.Hide);
        }
Пример #12
0
        public static MessageToken <TipItem> ShowMessage(System.Windows.FrameworkElement balloon,
                                                         ObservableCollection <TipItem> data, int?timeout,
                                                         NotifyPosition position = NotifyPosition.ActiveScreen, PopupAnimation animation = PopupAnimation.None)
        {
            var dispatcher = balloon.Dispatcher;

            if (!dispatcher.CheckAccess())
            {
                return(dispatcher.Invoke(DispatcherPriority.Normal,
                                         (Func <MessageToken <TipItem> >)(() =>
                                                                          ShowMessage(balloon, data, timeout, position, animation))) as
                       MessageToken <TipItem>);
            }

            if (balloon == null)
            {
                throw new ArgumentNullException("balloon");
            }
            if (timeout.HasValue && timeout < 500)
            {
                var msg = "Invalid timeout of {0} milliseconds. Timeout must be at least 500 ms";
                msg = String.Format(msg, timeout);
                throw new ArgumentOutOfRangeException("timeout", msg);
            }

            if (LogicalTreeHelper.GetParent(balloon) is Popup parent)
            {
                parent.Child = null;
                var msg =
                    "Cannot display control [{0}] in a new balloon popup - that control already has a parent. You may consider creating new balloons every time you want to show one.";
                msg = String.Format(msg, balloon);
                throw new InvalidOperationException(msg);
            }

            var popup = new Popup();

            popup.AllowsTransparency = true;
            popup.PopupAnimation     = animation;
            popup.Placement          = PlacementMode.AbsolutePoint;
            popup.StaysOpen          = true;
            popup.DataContext        = data;

            Point point;

            switch (position)
            {
            case NotifyPosition.Caret:
            {
                var rect = Utils.Window.GetCurrentWindowCaretPosition();
                var X    = (rect.Left + rect.Width / 2 - balloon.ActualWidth / 2);
                var Y    = (rect.Bottom + rect.Height / 2 - balloon.ActualHeight / 2);
                if (X == 0 && Y == 0)
                {
                    goto case NotifyPosition.ActiveWindowCenter;
                }

                point = new Point(X, Y);
                break;
            }

            case NotifyPosition.ActiveWindowCenter:
            {
                var rect = Utils.Window.GetCurrentWindowRect();
                var X    = (rect.X + rect.Width / 2 - balloon.ActualWidth / 2);
                var Y    = (rect.Y + rect.Height / 2 - balloon.ActualHeight / 2);
                point = new Point(X, Y);
                break;
            }

            case NotifyPosition.ActiveScreen:
            {
                var screen = Screen.FromHandle(Utils.Window.CurrentWindowHandle);
                if (screen.Equals(Screen.PrimaryScreen))
                {
                    var p = TrayInfo.GetTrayLocation();
                    point = new Point(p.X, p.Y);
                    break;
                }

                var bounds = screen.Bounds;
                var X      = bounds.X + bounds.Width;
                var Y      = bounds.Y + bounds.Height;
                point = new Point(X, Y);
                break;
            }

            case NotifyPosition.Default:
            {
                var p = TrayInfo.GetTrayLocation();
                point = new Point(p.X, p.Y);
                break;
            }


            default:
                throw new ArgumentOutOfRangeException(nameof(position) + " not supported", position, null);
            }


            popup.Child            = balloon;
            popup.HorizontalOffset = point.X + 1;
            popup.VerticalOffset   = point.Y - 2;
            balloon.Focusable      = true;

            IInputElement element = null;

            popup.Opened += (s, a) =>
            {
                element = Keyboard.FocusedElement;
                var source = (HwndSource)PresentationSource.FromVisual(balloon);
                var handle = source.Handle;
                PInvokes.SetForegroundWindow(handle);
                Keyboard.Focus(balloon);
            };

            popup.IsOpen = true;
            popup.Focus();

            var r = new MessageToken <TipItem>(popup);

            popup.Closed += (s, a) =>
            {
                Keyboard.Focus(element);
                r.Close();
            };

            void TimerTick(object sender, EventArgs e)
            {
                r.Timer.Tick -= TimerTick;
                r.Close();
            }

            if (timeout.HasValue)
            {
                r.Timer = new DispatcherTimer {
                    Interval = TimeSpan.FromMilliseconds(timeout.Value)
                };
                r.Timer.Tick += TimerTick;
                r.Timer.Start();
            }

            return(r);
        }