Beispiel #1
0
 private void OnLeftSizeToolPositionChanged(object sender, DragObjectEventArgs e)
 {
     WindowApi.RECT rect = new WindowApi.RECT();
     WindowApi.GetWindowRect(this.handle, ref rect);
     rect.left -= (int)e.Delta.X;
     WindowApi.MoveWindow(this.handle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, false);
 }
Beispiel #2
0
        public static Process StartDetached(string filename, string arguments, string startFolder, bool hidden = true)
        {
            var process = new Process();

            process.StartInfo = new ProcessStartInfo(filename)
            {
                Arguments        = arguments,
                UseShellExecute  = true,
                WorkingDirectory = startFolder,
            };

            if (hidden)
            {
                process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                process.Start();
            }
            else
            {
                process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                process.Start();

                for (int i = 0; process.MainWindowHandle == IntPtr.Zero && i < 30; i++)
                {
                    System.Threading.Thread.Sleep(10);
                }

                // set user the focus to the window, if there is one.
                if (process.MainWindowHandle != IntPtr.Zero)
                {
                    _ = WindowApi.SetForegroundWindow(process.MainWindowHandle);
                }
            }

            return(process);
        }
        static BitmapSource GetWindowIcon(IntPtr windowHandle)
        {
            var hIcon = default(IntPtr);

            hIcon = WindowApi.SendMessage(windowHandle, (int)Message.WM_GETICON, WindowApi.ICON_BIG, IntPtr.Zero);

            if (hIcon == IntPtr.Zero)
            {
                hIcon = WindowApi.GetClassLongPtr(windowHandle, WindowApi.GCL_HICON);
            }

            if (hIcon == IntPtr.Zero)
            {
                //TODO: define this constant in the api. it's messy in here.
                hIcon = WindowApi.LoadIcon(IntPtr.Zero, (IntPtr)0x7F00 /*IDI_APPLICATION*/);
            }

            if (hIcon != IntPtr.Zero)
            {
                return(Imaging.CreateBitmapSourceFromHIcon(hIcon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
            }
            else
            {
                throw new InvalidOperationException("Could not load window icon.");
            }
        }
Beispiel #4
0
 public void GetWindowAtPoint()
 {
     var wa = new WindowApi();
     var window = wa.WindowFromPoint(new Point(1000, 500));
     var newWindow = new Window(window.Ptr, new Rectangle(100, 100, 600, 600));
     wa.SetWindow(newWindow);
 }
Beispiel #5
0
        private void OnPaint(int width, int height)
        {
            _pixelBuffer.EnsureAlloc(width, height);
            _ixenSurface.ComputeLayout(width, height);
            _skImageInfo = new SKImageInfo(width, height, SKColorType.Bgra8888, SKAlphaType.Premul);
            _painted     = false;

            try
            {
                using (_skSurface = SKSurface.Create(_skImageInfo, _pixelBuffer.Ptr, _pixelBuffer.RowBytes))
                {
                    if (_skSurface != null)
                    {
                        _ixenSurface.Render(_skSurface.Canvas);
                        _painted = true;
                    }
                }
            }
            finally
            {
                if (_painted)
                {
                    WindowApi.SetWindowPixelsBuffer(_windowPtr, _pixelBuffer.Ptr);
                }
            }
        }
Beispiel #6
0
 /// <summary>
 /// Show button for translate
 /// </summary>
 private void ShowTranslationButton()
 {
     this.SetDesktopLocation(Cursor.Position.X - 15, Cursor.Position.Y + 15);
     this.Visible = true;
     this.Focus();
     WindowApi.SetForegroundWindow(this.Handle);
 }
Beispiel #7
0
        public static string ConvertKeyToString(Keys vKey)
        {
            if (vKey >= Keys.F1 && vKey <= Keys.F12)
            {
                return(vKey.ToString());
            }

            byte[] keyboardState       = new byte[255];
            bool   keyboardStateStatus = WindowApi.GetKeyboardState(keyboardState);

            if (!keyboardStateStatus)
            {
                return("");
            }

            uint   virtualKeyCode        = (uint)vKey;
            uint   scanCode              = WindowApi.MapVirtualKey(virtualKeyCode, 0);
            IntPtr inputLocaleIdentifier = WindowApi.GetKeyboardLayout(0);

            StringBuilder result = new StringBuilder();

            WindowApi.ToUnicodeEx(virtualKeyCode, scanCode, keyboardState, result, (int)5, (uint)0, inputLocaleIdentifier);

            return(result.ToString().ToUpper());
        }
Beispiel #8
0
 public void BringToFront()
 {
     var wa = new WindowApi();
     var window = wa.WindowFromPoint(new Point(1000, 500));
     wa.BringToFront(window);
     var frontWindow = wa.GetForegroundWindow();
     Expect(window.Ptr, Is.EqualTo(frontWindow.Ptr));
 }
 public frmProgram()
 {
     InitializeComponent();
     recorderPath = AppDomain.CurrentDomain.BaseDirectory + DateTime.Now.ToString("MMddHHmmss") + ".mp4";
     //初始化所有桌面程序
     programList = WindowApi.GetAllDesktopWindows().Where(x => !string.IsNullOrEmpty(x.szWindowName)).ToList();
     this.cboProgram.DataSource = programList.Select(x => x.szWindowName).ToList();
 }
Beispiel #10
0
        internal static bool NormalWindow(WindowApi window)
        {
            if (IsHiddenWindowStoreApp(window, window.ClassName))
            {
                return(false);
            }

            return(!window.Styles.IsToolWindow && window.IsVisible);
        }
Beispiel #11
0
 public void GetWindowPos()
 {
     var wa = new WindowApi();
     var window = wa.WindowFromPoint(new Point(1000, 500));
     var newWindow = new Window(window.Ptr, new Rectangle(100, 100, 700, 700));
     wa.SetWindow(newWindow);
     var result = wa.WindowFromPoint(new Point(200, 200));
     Expect(result.Area, Is.EqualTo(new Rectangle(100, 100, 700, 700)));
 }
Beispiel #12
0
        static Exception GenerateInstallFailureException()
        {
            var errorCode = Marshal.GetLastWin32Error();

            var existingOwner = ClipboardApi.GetClipboardOwner();
            var ownerTitle    = WindowApi.GetWindowTitle(existingOwner);

            return(new InvalidOperationException($"Could not install a clipboard hook for the main window. The window '{ownerTitle}' currently owns the clipboard. The last error code was {errorCode}."));
        }
Beispiel #13
0
        /// <summary>
        /// 每帧录制帧数回调
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        protected virtual void VideoStreamer_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            this.VideoWriter.WriteVideoFrame((Bitmap)eventArgs.Frame.Clone());

            //每100帧回收一次虚拟内存
            if ((TotalFrame++) % 100 == 0)
            {
                WindowApi.ClearMemory();
            }
        }
Beispiel #14
0
        /// <summary>
        /// 摄像头回调
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void Camera_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            this.VideoWriter.WriteVideoFrame((Bitmap)eventArgs.Frame.Clone());

            //每100帧回收一次虚拟内存
            if ((TotalFrame++) % 100 == 0)
            {
                WindowApi.ClearMemory();
            }
        }
Beispiel #15
0
        public IxenWindow(IxenSurface ixenSurface)
        {
            _pixelBuffer = new PixelBuffer();
            _ixenSurface = ixenSurface;
            _windowPtr   = WindowApi.CreateWindow(_ixenSurface.InitOptions.Title, _ixenSurface.InitOptions.Width, _ixenSurface.InitOptions.Height);

            if (_windowPtr == IntPtr.Zero)
            {
                throw new Exception("Could not initialize WIN32 Window");
            }
        }
        public IDataSource GetDataSource()
        {
            var activeWindowHandle = WindowApi.GetForegroundWindow();

            var windowTitle = WindowApi.GetWindowTitle(activeWindowHandle);
            var windowIcon  = GetWindowIcon(activeWindowHandle);

            var iconBytes = imagePersistenceService.ConvertBitmapSourceToByteArray(windowIcon);

            return(new DataSource(iconBytes, windowTitle));
        }
Beispiel #17
0
        /// <summary>
        /// Override clipboard changed event
        /// </summary>
        /// <param name="m"></param>
        protected override void WndProc(ref Message m)
        {
            // defined in winuser.h
            const int wmDrawclipboard = 0x308;
            const int wmChangecbchain = 0x030D;

            try
            {
                switch (m.Msg)
                {
                case wmDrawclipboard:
                    IDataObject iData = Clipboard.GetDataObject();
                    Object      oData = null;
                    if (iData != null)
                    {
                        oData = iData.GetData(DataFormats.UnicodeText);
                    }

                    string textData = String.Empty;
                    if (oData != null)
                    {
                        textData = oData.ToString().Trim();
                    }

                    if (!string.IsNullOrEmpty(textData) && _flagCheckTranslate)
                    {
                        _clipboardData = textData;
                        ShowTranslationButton();
                    }

                    break;

                case wmChangecbchain:
                    if (m.WParam == _nextClipboardViewer)
                    {
                        _nextClipboardViewer = m.LParam;
                    }
                    else
                    {
                        WindowApi.SendMessage(_nextClipboardViewer, m.Msg, m.WParam, m.LParam);
                    }
                    break;

                default:
                    base.WndProc(ref m);
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Beispiel #18
0
        void Start()
        {
#if !UNITY_EDITOR
            WindowApi.Frontize();
            WindowApi.HideTitleBar();
            WindowApi.EnableWindowDrag();
#endif
            if (KeyApi.IsKeyEventObservable())
            {
                Debug.Log("accessibility OK");
            }
        }
Beispiel #19
0
        private void Start()
        {
#if !UNITY_EDITOR
            //強制的に再生時のKeyNoteよりも前に持ってきます。
            WindowApi.Frontize();
            WindowApi.HideTitleBar();
            WindowApi.EnableWindowDrag();
#endif

            vrmLoadController.VrmLoaded += OnVRMLoaded;

            StartCoroutine(LoadAvatar());
        }
Beispiel #20
0
        /// <summary>
        /// 开始
        /// </summary>
        /// <param name="frameEventHandler"></param>
        public override void Start(NewFrameEventHandler frameEventHandler = null)
        {
            if (hwnd == IntPtr.Zero)
            {
                MessageBox.Show($"没有找到程序【{programName}】!");
                return;
            }
            //首先获取一张,并设置成此大小
            Bitmap programBmp = WindowApi.GetWindowCapture(hwnd);

            base.ScreenWidth = programBmp.Width % 2 == 0 ? programBmp.Width : programBmp.Width - 1;
            base.ScreenHight = programBmp.Height % 2 == 0 ? programBmp.Height : programBmp.Height - 1;
            //开始录制
            base.Start(null);
            this.frameEventHandler = frameEventHandler;
        }
Beispiel #21
0
        private void Update()
        {
            if (canvasObject != null)
            {
                var size = widthAll ? new Vector2(Screen.width, Screen.width * aspectRatio) : new Vector2(Screen.height / aspectRatio, Screen.height);
                if (imageSize.sizeDelta.x.CompareTo(size.x) != 0 || imageSize.sizeDelta.y.CompareTo(size.y) != 0)
                {
                    imageSize.sizeDelta = size;
                }
            }

            // リサイズすると再設定が必要なので
            // nativeのdidResizedNotificationでもダメだった
            if (shouldSetTransparent)
            {
                WindowApi.Transparentize();
            }
        }
Beispiel #22
0
        public IEnumerable <WindowApi> GetWindows(Predicate <WindowApi> match)
        {
            Guard.Against.Null(match, nameof(match));

            var windows = new List <WindowApi>();

            User32.EnumWindows((handle, _) =>
            {
                var window = new WindowApi(handle);
                if (match(window))
                {
                    windows.Add(window);
                }

                return(true);
            }, IntPtr.Zero);

            return(windows);
        }
Beispiel #23
0
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.T))
            {
#if !UNITY_EDITOR
                if (transparent)
                {
                    Camera.main.backgroundColor = Color.green;
                    WindowApi.Opacify();
                }
                else
                {
                    Camera.main.clearFlags      = CameraClearFlags.Color;
                    Camera.main.backgroundColor = Color.clear;
                    WindowApi.Transparentize();
                }
#endif

                transparent = !transparent;
            }
            else if (Input.GetKeyDown(KeyCode.E))
            {
                if (monitoring)
                {
                    MouseApi.Release();
                    KeyApi.Release();
                }
                else
                {
                    MouseApi.ObserveLeftMouseDown(() => Debug.Log("left mouse down"));
                    MouseApi.ObserveLeftMouseUp(() => Debug.Log("left mouse up"));
                    MouseApi.ObserveRightMouseDown(() => Debug.Log("right mouse down"));
                    MouseApi.ObserveRightMouseUp(() => Debug.Log("right mouse up"));

                    // accessibility permission is required
                    KeyApi.ObserveKeyDown(code => Debug.Log($"key down: {code}"));
                    KeyApi.ObserveKeyUp(code => Debug.Log($"key up: {code}"));
                }

                monitoring = !monitoring;
            }
        }
Beispiel #24
0
        /// <summary>
        /// 捕捉每帧
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        protected override void VideoStreamer_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap programBmp = WindowApi.GetWindowCapture(hwnd);
            Bitmap newBitmap  = new Bitmap(this.ScreenWidth, this.ScreenHight);

            //修改图片大小
            using (Graphics graphics = Graphics.FromImage(newBitmap))
            {
                graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                graphics.DrawImage(programBmp, 0, 0, base.ScreenWidth, base.ScreenHight);
            }
            var newFrameEvent = new NewFrameEventArgs(newBitmap);

            base.VideoStreamer_NewFrame(sender, newFrameEvent);
            try
            {
                frameEventHandler.Invoke(sender, newFrameEvent);
            }
            catch { }
        }
        public void Start()
        {
            _cancellationTokenSource = new CancellationTokenSource();
            CancellationToken token = _cancellationTokenSource.Token;

            Task listener = Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    IntPtr newFocusedWindowHandle = WindowApi.GetForegroundWindow();
                    string newFocusedWindowTitle  = WindowApi.GetWindowTitle(newFocusedWindowHandle);

                    //Only trigger event & update when focused window title is different
                    if (newFocusedWindowTitle != null && newFocusedWindowTitle != FocusedWindowInfo?.Title)
                    {
                        int threadId = WindowApi.GetWindowProcessId(newFocusedWindowHandle, out int processId);
                        WindowInfo newFocusedWindowInfo = new WindowInfo()
                        {
                            Title     = newFocusedWindowTitle,
                            Handle    = newFocusedWindowHandle,
                            ProcessId = processId,
                            ThreadId  = threadId
                        };
                        FocusedWindowTitleChanged?.Invoke(this, new FocusedWindowTitleChangedEventArgs()
                        {
                            OldFocusedWindow = FocusedWindowInfo,
                            NewFocusedWindow = newFocusedWindowInfo
                        });
                        FocusedWindowInfo = newFocusedWindowInfo;
                    }

                    Thread.Sleep(PollDelayMilliseconds);
                    if (token.IsCancellationRequested)
                    {
                        break;
                    }
                }
            }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
        }
Beispiel #26
0
        void ShowKestrelLog_OnClick(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
            var    service = GetServiceByTag(sender);
            var    pid     = service.ProcId;
            IntPtr mainWindowHandle;

            do
            {
                mainWindowHandle = Process.GetProcessById(pid).MainWindowHandle;
                var pr = ParentProcessUtilities.GetParentProcess(pid);
                pid = pr?.Id ?? 0;
            } while (mainWindowHandle == IntPtr.Zero && pid != 0);

            if (mainWindowHandle != IntPtr.Zero)
            {
                WindowApi.ShowWindow(mainWindowHandle);
            }
            else
            {
                MessageBox.Show("Last Kestrel process was attached to none console window style.\n So if you want to see Kestrel log window, please stop and start Microserice again.", "There is not kestrel window-habdle");
            }
        }
Beispiel #27
0
        /// <summary>
        /// 默认函数
        /// </summary>
        /// <param name="parentWindow">父窗口</param>
        /// <param name="message">显示的内容</param>
        public Waiting(Window parentWindow, string message)
        {
            InitializeComponent();
            this.ShowInTaskbar = false;
            if (parentWindow == null)
            {
                parentWindow = Application.Current.MainWindow;
            }
            this.Owner = parentWindow;
            this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            //this.ProgressBar1.Content = message;
            this.Width  = parentWindow.ActualWidth;
            this.Height = parentWindow.ActualHeight;

            //top = parentWindow.Top;
            //left = parentWindow.Left;
            RECT rect = WindowApi.GetInstance().GetWindowLocation(parentWindow.Title);

            top  = rect.Top;
            left = rect.Left;

            this.Loaded += Waiting_Loaded;
        }
Beispiel #28
0
 public void GetWindowRect()
 {
     var wa = new WindowApi();
     var window = wa.WindowFromPoint(new Point(1000, 500));
     Console.WriteLine(window.Area);
 }
Beispiel #29
0
        public void Pose(object o, PoseEventArgs e)
        {
            var myo = (Myo)o;
            if (myo.Pose == MyoSharp.Poses.Pose.DoubleTap)
            {
                if (!absoluteTL.ContainsKey(myo))
                {
                    absoluteTL.Add(myo, Math3D.FromQuaternion(myo.Orientation));
                    Console.WriteLine("Calibrated Top Left!");
                    UpdateBlob(myo, new Point(clientRes.Width, clientRes.Height));
                }
                else
                {
                    absoluteTL.Remove(myo);
                    UpdateBlob(myo, new Point(0, 0));
                }
            }
            else if (myo.Pose == MyoSharp.Poses.Pose.Fist)
            {
                if (absoluteTL.ContainsKey(myo))
                {
                    var position = GetPixelPosition(myo);
                    var api = new WindowApi();
                    var window = api.WindowFromPoint(position);
                    if (window != null)
                    {
                        if (!SelectedWindow.ContainsKey(myo))
                        {
                            SelectedWindow.Add(myo, api.GetRoot(window));
                            if (SelectedWindow.ContainsKey(myo)) {
                                if (!DragOffset.ContainsKey(myo))
                                {
                                    DragOffset.Add(myo, new Point(position.X - SelectedWindow[myo].Area.Location.X, position.Y - SelectedWindow[myo].Area.Location.Y));
                                }
                            }
                        }
                    }
                }
            }

            else
            {
                if (absoluteTL != null)
                {
                    if (SelectedWindow.ContainsKey(myo))
                    {
                        var position = GetPixelPosition(myo);
                        var api = new WindowApi();
                        var newWindow = new Window(SelectedWindow[myo].Ptr, new Rectangle(position.X - DragOffset[myo].Value.X, position.Y - DragOffset[myo].Value.Y, SelectedWindow[myo].Area.Width, SelectedWindow[myo].Area.Height));
                        SelectedWindow.Remove(myo);
                        api.SetWindow(newWindow);
                        api.BringToFront(newWindow);
                        blobs.Add(myo, position);
                    }
                    if (rectangles.ContainsKey(myo)) {
                        DeleteRect(myo);
                    }
                    DragOffset.Remove(myo);
                }
            }
        }
Beispiel #30
0
 private static bool IsHiddenWindowStoreApp(WindowApi window, string className)
 => (className == "ApplicationFrameWindow" || className == "Windows.UI.Core.CoreWindow") && window.IsCloaked;
 /// <summary>
 /// This function toggles the visibility for the exit confirmation window.
 /// </summary>
 public void OpenExitConfirmationWindow()
 {
     WindowApi.OpenWindow(WindowTypes.ExitConfirmation);
 }
Beispiel #32
0
        private void Start()
        {
            _receivedMessageHandler.Commands.Subscribe(message =>
            {
                switch (message.Command)
                {
                case MessageCommandNames.ChangeBackground:
                    {
                        if (message.ToBoolean())
                        {
                            if (canvasObject != null)
                            {
                                canvasObject.SetActive(false);
                            }

                            UnityEngine.Camera.main.backgroundColor = Color.clear;
                            shouldSetTransparent = true;
                        }
                        else
                        {
                            WindowApi.Opacify();
                            shouldSetTransparent = false;
                            if (canvasObject != null)
                            {
                                canvasObject.SetActive(true);
                            }

                            UnityEngine.Camera.main.backgroundColor = Color.green;
                        }

                        break;
                    }

                case MessageCommandNames.ChangeBackgroundImageDirection:
                    {
                        widthAll = message.ToBoolean();
                        break;
                    }
                }
            });

            try
            {
                var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/background.jpg";
                if (File.Exists(path))
                {
                    var data = File.ReadAllBytes(path);

                    canvasObject = new GameObject("Background");
                    var imageObject = new GameObject("Image");
                    imageObject.transform.SetParent(canvasObject.transform);

                    var canvas = canvasObject.AddComponent <Canvas>();

                    canvas.renderMode  = RenderMode.ScreenSpaceCamera;
                    canvas.worldCamera = UnityEngine.Camera.main;
                    canvasObject.AddComponent <CanvasScaler>();
                    rawImage = imageObject.AddComponent <RawImage>();

                    //画像読み込み
                    var tex = new Texture2D(1, 1);
                    tex.LoadImage(data);

                    //ImageObjectのサイズを画像サイズに合わせる(Canvasをはみ出た分はトリム=中央クロップになる)
                    imageSize   = rawImage.GetComponent <RectTransform>();
                    aspectRatio = (float)tex.height / tex.width;
                    if (widthAll)
                    {
                        imageSize.sizeDelta = new Vector2(Screen.width, Screen.width * aspectRatio);
                    }
                    else
                    {
                        imageSize.sizeDelta = new Vector2(Screen.height / aspectRatio, Screen.height);
                    }

                    rawImage.texture = tex;
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
Beispiel #33
0
 /// <summary>
 /// Opens the code window.
 /// </summary>
 public void OpenCodeWindow()
 {
     WindowApi.OpenWindow(WindowTypes.CodeMenu);
     Game.MainCamera.Dragging.DisableDragging();
     Game.MainCamera.Zooming.DisableZooming();
 }
Beispiel #34
0
 /// <summary>
 /// Closes the block programming window.
 /// </summary>
 public void CloseWindow()
 {
     Game.MainCamera.Dragging.EnableDragging();
     Game.MainCamera.Zooming.EnableZooming();
     WindowApi.CloseLastWindow();
 }
Beispiel #35
0
 /// <summary>
 /// Opens the the exit confirmation window.
 /// </summary>
 public void OpenExitConfirmation()
 {
     WindowApi.OpenWindow(WindowTypes.ExitConfirmation);
     Game.MainCamera.Dragging.DisableDragging();
     Game.MainCamera.Zooming.DisableZooming();
 }