internal void setAppBarPosition(NativeMethods.Rect rect)
 {
     Top    = rect.Top / dpiScale;
     Left   = rect.Left / dpiScale;
     Width  = (rect.Right - rect.Left) / dpiScale;
     Height = (rect.Bottom - rect.Top) / dpiScale;
 }
Exemple #2
0
        private void setGridPosition()
        {
            double top  = SystemInformation.WorkingArea.Top / DpiHelper.DpiScale;
            double left = SystemInformation.WorkingArea.Left / DpiHelper.DpiScale;

            if (_desktopManager.ShellWindow != null || _desktopManager.AllowProgmanChild)
            {
                top  = (0 - SystemInformation.VirtualScreen.Top + SystemInformation.WorkingArea.Top) / DpiHelper.DpiScale;
                left = (0 - SystemInformation.VirtualScreen.Left + SystemInformation.WorkingArea.Left) / DpiHelper.DpiScale;
            }

            grid.Width = WindowManager.PrimaryMonitorWorkArea.Width / DpiHelper.DpiScale;

            if (Settings.Instance.TaskbarMode == 1)
            {
                // special case, since work area is not reduced with this setting
                // this keeps the desktop going beneath the TaskBar
                // get the TaskBar's height
                double             dpiScale     = 1;
                NativeMethods.Rect workAreaRect = _appBarManager.GetWorkArea(ref dpiScale, Screen.PrimaryScreen, false, false);

                grid.Height = (WindowManager.PrimaryMonitorWorkArea.Height / DpiHelper.DpiScale) - ((Screen.PrimaryScreen.Bounds.Bottom - workAreaRect.Bottom) / dpiScale);

                if (Settings.Instance.TaskbarPosition == 1)
                {
                    top += (workAreaRect.Top - SystemInformation.WorkingArea.Top) / dpiScale;
                }
            }
            else
            {
                grid.Height = WindowManager.PrimaryMonitorWorkArea.Height / DpiHelper.DpiScale;
            }

            grid.Margin = new Thickness(left, top, 0, 0);
        }
        internal virtual void afterAppBarPos(bool isSameCoords, NativeMethods.Rect rect)
        {
            // apparently the taskbars like to pop up when app bars change
            if (Settings.Instance.EnableTaskbar && !Startup.IsShuttingDown)
            {
                AppBarHelper.SetWinTaskbarState(AppBarHelper.WinTaskbarState.AutoHide);
                AppBarHelper.SetWinTaskbarVisibility((int)NativeMethods.SetWindowPosFlags.SWP_HIDEWINDOW);
            }

            if (!isSameCoords)
            {
                var timer = new DispatcherTimer {
                    Interval = TimeSpan.FromSeconds(0.1)
                };
                timer.Start();
                timer.Tick += (sender1, args) =>
                {
                    // set position again, since WPF may have overridden the original change from AppBarHelper
                    setAppBarPosition(rect);

                    if (Screen.Primary && WindowManager.Instance.DesktopWindow != null)
                    {
                        WindowManager.Instance.DesktopWindow.ResetPosition();
                    }

                    timer.Stop();
                };
            }
        }
Exemple #4
0
        /// <summary>
        /// Responds to the condition in which the value of the Popup.IsOpen property
        /// changes from false to true.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        protected override void OnOpened(EventArgs e)
        {
            base.OnOpened(e);

            isFirstMouseUp = true;

            PopupAnimation = PopupAnimation.None;

            if (Child != null)
            {
                hwndSource = (HwndSource)PresentationSource.FromVisual(this.Child);
            }
            if (hwndSource != null)
            {
                hwndSource.AddHook(WindowProc);
                // Set popup non-topmost to fix bug with tooltips
                NativeMethods.Rect rect = new NativeMethods.Rect();
                if (NativeMethods.GetWindowRect(hwndSource.Handle, ref rect))
                {
                    NativeMethods.SetWindowPos(hwndSource.Handle, new IntPtr(-2), rect.Left, rect.Top, (int)this.Width,
                                               (int)this.Height,
                                               NativeMethods.SWP_NOMOVE | NativeMethods.SWP_NOSIZE |
                                               NativeMethods.SWP_NOACTIVATE);
                }
            }
            openedPopups.Add(this);

            Activate();
        }
Exemple #5
0
        /// <summary>
        /// Gets the size of the main window for the process.
        /// </summary>
        /// <param name="process"> The process to size. </param>
        /// <returns> The size of the main window. </returns>
        public static Size GetWindowSize(this Process process)
        {
            var data = new NativeMethods.Rect();

            NativeMethods.GetWindowRect(process.MainWindowHandle, out data);
            return(new Size(data.Right - data.Left, data.Bottom - data.Top));
        }
Exemple #6
0
        public void ResetPosition()
        {
            double top           = System.Windows.Forms.SystemInformation.WorkingArea.Top / DpiHelper.DpiScale;
            double taskbarHeight = 0;

            if (Settings.Instance.TaskbarMode == 1)
            {
                // special case, since work area is not reduced with this setting
                // this keeps the desktop going beneath the TaskBar

                // get the TaskBar's height
                double             dpiScale     = 1;
                AppBarScreen       screen       = AppBarScreen.FromPrimaryScreen();
                NativeMethods.Rect workAreaRect = _appBarManager.GetWorkArea(ref dpiScale, screen, false, false);
                taskbarHeight = (screen.Bounds.Bottom - workAreaRect.Bottom) / dpiScale;

                // top TaskBar means we should push down
                if (Settings.Instance.TaskbarPosition == 1)
                {
                    top = workAreaRect.Top / dpiScale;
                }
            }

            Width  = WindowManager.PrimaryMonitorWorkArea.Width / DpiHelper.DpiScale;
            Height = (WindowManager.PrimaryMonitorWorkArea.Height / DpiHelper.DpiScale) - taskbarHeight;

            grid.Width  = Width;
            grid.Height = Height;

            Top  = top;
            Left = System.Windows.Forms.SystemInformation.WorkingArea.Left / DpiHelper.DpiScale;
        }
Exemple #7
0
        /// <summary>
        /// Draws the specified text at the specified position using the specified alignment.
        /// </summary>
        /// <param name="text">The text to draw.</param>
        /// <param name="position">The position on the canvas, where to draw the text.</param>
        /// <param name="align">The text alignment.</param>
        /// <returns>The position of drawn text.</returns>
        public Rectangle DrawText(string text, Rectangle position, HorizontalAlignment align)
        {
            if (this.hdc != null)
            {
                int format = NativeMethods.DT_SINGLELINE | NativeMethods.DT_NOCLIP;
                if (align == HorizontalAlignment.Right)
                {
                    format |= NativeMethods.DT_RIGHT;
                }
                else if (align == HorizontalAlignment.Left)
                {
                    format |= NativeMethods.DT_LEFT;
                }
                else
                {
                    format |= NativeMethods.DT_CENTER;
                }

                // first pass - calculate the rectangle
                format |= NativeMethods.DT_CALCRECT;
                NativeMethods.Rect r = new NativeMethods.Rect(position.Left, position.Top, position.Right, position.Bottom);
                if (NativeMethods.DrawText(this.hdc, text, -1, ref r, format) == 0)
                {
                    throw new InvalidOperationException(Properties.Resources.E_InvalidCanvasOperation);
                }

                // second pass - draw the text (center vertically)
                format &= ~NativeMethods.DT_CALCRECT;
                if (position.Width == 0)
                {
                    int xoffset = position.Height / 4;
                    r.Left  += xoffset;
                    r.Right += xoffset;
                }
                else
                {
                    r.Left  = position.Left;
                    r.Right = position.Right;
                }

                int textHeight = r.Bottom - r.Top;
                int yoffset    = (position.Height - textHeight) / 2;
                r.Top    += yoffset;
                r.Bottom += yoffset;

                if (NativeMethods.DrawText(this.hdc, text, -1, ref r, format) == 0)
                {
                    throw new InvalidOperationException(Properties.Resources.E_InvalidCanvasOperation);
                }

                return(Rectangle.FromLTRB(r.Left, r.Top, r.Right, r.Bottom));
            }
            else
            {
                return(Rectangle.Empty);
            }
        }
Exemple #8
0
        internal override void afterAppBarPos(bool isSameCoords, NativeMethods.Rect rect)
        {
            base.afterAppBarPos(isSameCoords, rect);

            if (!isSameCoords)
            {
                setShadowPosition();
            }
        }
        internal override void afterAppBarPos(bool isSameCoords, NativeMethods.Rect rect)
        {
            base.afterAppBarPos(isSameCoords, rect);

            if (useFullWidthAppearance)
            {
                bdrTaskbar.Width = getDesiredWidth();
            }

            // set maxwidth always
            bdrTaskbar.MaxWidth = getDesiredWidth();
        }
        internal override void afterAppBarPos(bool isSameCoords, NativeMethods.Rect rect)
        {
            base.afterAppBarPos(isSameCoords, rect);

            if (Settings.Instance.FullWidthTaskBar)
            {
                bdrTaskbar.Width = getDesiredWidth();
            }

            // set maxwidth always
            bdrTaskbar.MaxWidth = getDesiredWidth();
        }
Exemple #11
0
        /// <summary>
        /// Implements custom placement for ribbon popup
        /// </summary>
        /// <param name="popupsize"></param>
        /// <param name="targetsize"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        private CustomPopupPlacement[] CustomPopupPlacementMethod(Size popupsize, Size targetsize, Point offset)
        {
            if (this.DropDownPopup != null &&
                this.SelectedTabItem != null)
            {
                // Get current workarea
                var tabItemPos  = this.SelectedTabItem.PointToScreen(new Point(0, 0));
                var tabItemRect = new NativeMethods.Rect
                {
                    Left   = (int)tabItemPos.X,
                    Top    = (int)tabItemPos.Y,
                    Right  = (int)tabItemPos.X + (int)this.SelectedTabItem.ActualWidth,
                    Bottom = (int)tabItemPos.Y + (int)this.SelectedTabItem.ActualHeight
                };

                const uint MONITOR_DEFAULTTONEAREST = 0x00000002;

                var monitor = NativeMethods.MonitorFromRect(ref tabItemRect, MONITOR_DEFAULTTONEAREST);
                if (monitor != IntPtr.Zero)
                {
                    var monitorInfo = new NativeMethods.MonitorInfo();
                    monitorInfo.Size = Marshal.SizeOf(monitorInfo);
                    NativeMethods.GetMonitorInfo(monitor, monitorInfo);

                    var startPoint = this.PointToScreen(new Point(0, 0));
                    if (this.FlowDirection == FlowDirection.RightToLeft)
                    {
                        startPoint.X -= this.ActualWidth;
                    }

                    var inWindowRibbonWidth = monitorInfo.Work.Right - Math.Max(monitorInfo.Work.Left, startPoint.X);

                    var actualWidth = this.ActualWidth;
                    if (startPoint.X < monitorInfo.Work.Left)
                    {
                        actualWidth -= monitorInfo.Work.Left - startPoint.X;
                        startPoint.X = monitorInfo.Work.Left;
                    }

                    // Set width and prevent negative values
                    this.DropDownPopup.Width = Math.Max(0, Math.Min(actualWidth, inWindowRibbonWidth));
                    return(new[]
                    {
                        new CustomPopupPlacement(new Point(startPoint.X - tabItemPos.X, this.SelectedTabItem.ActualHeight - ((FrameworkElement)this.DropDownPopup.Child).Margin.Top), PopupPrimaryAxis.None),
                        new CustomPopupPlacement(new Point(startPoint.X - tabItemPos.X, -((ScrollViewer)this.SelectedContent).ActualHeight - ((FrameworkElement)this.DropDownPopup.Child).Margin.Bottom), PopupPrimaryAxis.None)
                    });
                }
            }

            return(null);
        }
Exemple #12
0
        public void Clear()
        {
            if (this.hdc != null)
            {
                int mapMode   = NativeMethods.SetMapMode(this.hdc, NativeMethods.MM_TEXT);
                int backColor = NativeMethods.SetBkColor(this.hdc, System.Drawing.ColorTranslator.ToWin32(System.Drawing.Color.White));

                NativeMethods.Rect bounds = new NativeMethods.Rect(0, 0, this.width, this.height);
                NativeMethods.ExtTextOut(this.hdc, 0, 0, NativeMethods.ETO_OPAQUE, ref bounds, null, 0, null);

                NativeMethods.SetMapMode(this.hdc, mapMode);
                NativeMethods.SetBkColor(this.hdc, backColor);
            }
        }
Exemple #13
0
        /// <summary>
        /// Get the main window location for the process.
        /// </summary>
        /// <param name="process"> The process that contains the window. </param>
        /// <returns> The location of the window. </returns>
        public static Point GetWindowLocation(this Process process)
        {
            var p        = NativeMethods.GetWindowPlacement(process.MainWindowHandle);
            var location = p.rcNormalPosition.Location;

            if (p.ShowState == 2 || p.ShowState == 3)
            {
                var windowsRect = new NativeMethods.Rect();
                NativeMethods.GetWindowRect(process.MainWindowHandle, out windowsRect);
                location = new Point(windowsRect.Left + 8, windowsRect.Top + 8);
            }

            return(location);
        }
        /// <summary>
        /// Draws to bitmap.
        /// </summary>
        /// <param name="this">This RichTextBox.</param>
        /// <param name="target">The bitmap.</param>
        // ReSharper disable once SuggestBaseTypeForParameter
        private static void _DrawToBitmap(RichTextBox @this, Bitmap target)
        {
            using (var graphics = Graphics.FromImage(target)) {
                var hdc = IntPtr.Zero;
                try {
                    hdc = graphics.GetHdc();

                    var intPtr = hdc;
                    var hDc    = intPtr;

                    var rect = new NativeMethods.Rect {
                        Top    = 0,
                        Left   = 0,
                        Bottom = (int)(target.Height + target.Height * (target.HorizontalResolution / 100) * _INCH),
                        Right  = (int)(target.Width + target.Width * (target.VerticalResolution / 100) * _INCH)
                    };

                    var fmtRange = new NativeMethods.Formatrange {
                        chrg =
                        {
                            cpMin = 0,
                            cpMax = -1
                        },
                        hdc       = hDc,
                        hdcTarget = hDc,
                        rc        = rect,
                        rcPage    = rect
                    };

                    var allocCoTaskMem = IntPtr.Zero;
                    try {
                        allocCoTaskMem = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange));

                        Marshal.StructureToPtr(fmtRange, allocCoTaskMem, false);
                        NativeMethods.FormatRange(@this.Handle, allocCoTaskMem);
                        NativeMethods.FormatRange(@this.Handle, IntPtr.Zero);
                    } finally {
                        if (allocCoTaskMem != IntPtr.Zero)
                        {
                            Marshal.FreeCoTaskMem(allocCoTaskMem);
                        }
                    }
                } finally {
                    if (hdc != IntPtr.Zero)
                    {
                        graphics.ReleaseHdc();
                    }
                }
            }
        }
Exemple #15
0
        public override void AfterAppBarPos(bool isSameCoords, NativeMethods.Rect rect)
        {
            base.AfterAppBarPos(isSameCoords, rect);

            if (useFullWidthAppearance)
            {
                bdrTaskbar.Width = getDesiredWidth();
            }

            // set maxwidth always
            bdrTaskbar.MaxWidth = getDesiredWidth();

            // set button size since available space may have changed
            setTaskButtonSize();
        }
Exemple #16
0
        public ImGuiRender(Device dev, NativeMethods.Rect windowRect, CaptureInterface _interface, Process currentProcess)
        {
            device        = dev;
            _windowHandle = currentProcess.MainWindowHandle;
            hp            = hookProc;
            var cp    = Process.GetCurrentProcess();
            var mName = Path.GetFileNameWithoutExtension(cp.MainModule.ModuleName);

            hHook = SetWindowsHookEx(HookType.WH_GETMESSAGE, hp, GetModuleHandle(mName), cp.Threads[0].Id);
            ImGui.CreateContext();
            var io = ImGui.GetIO();

            io.DisplaySize = new Vector2(windowRect.Right - windowRect.Left, windowRect.Bottom - windowRect.Top);
            ImGui.GetStyle().WindowBorderSize = 0;
            PrepareTextureImGui();
            SetupKeyMapping(io);
        }
Exemple #17
0
        /// <summary>
        /// Implements custom placement for ribbon popup
        /// </summary>
        /// <param name="popupsize"></param>
        /// <param name="targetsize"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        CustomPopupPlacement[] CustomPopupPlacementMethod(Size popupsize, Size targetsize, Point offset)
        {
            if ((popup != null) && (SelectedTabItem != null))
            {
                // Get current workarea
                Point tabItemPos = SelectedTabItem.PointToScreen(new Point(0, 0));
                NativeMethods.Rect tabItemRect = new NativeMethods.Rect();
                tabItemRect.Left   = (int)tabItemPos.X;
                tabItemRect.Top    = (int)tabItemPos.Y;
                tabItemRect.Right  = (int)tabItemPos.X + (int)SelectedTabItem.ActualWidth;
                tabItemRect.Bottom = (int)tabItemPos.Y + (int)SelectedTabItem.ActualHeight;

                uint          MONITOR_DEFAULTTONEAREST = 0x00000002;
                System.IntPtr monitor = NativeMethods.MonitorFromRect(ref tabItemRect, MONITOR_DEFAULTTONEAREST);
                if (monitor != System.IntPtr.Zero)
                {
                    NativeMethods.MonitorInfo monitorInfo = new NativeMethods.MonitorInfo();
                    monitorInfo.Size = Marshal.SizeOf(monitorInfo);
                    NativeMethods.GetMonitorInfo(monitor, monitorInfo);

                    Point startPoint = PointToScreen(new Point(0, 0));
                    if (FlowDirection == FlowDirection.RightToLeft)
                    {
                        startPoint.X -= ActualWidth;
                    }
                    double inWindowRibbonWidth = monitorInfo.Work.Right - Math.Max(monitorInfo.Work.Left, startPoint.X);

                    double actualWidth = ActualWidth;
                    if (startPoint.X < monitorInfo.Work.Left)
                    {
                        actualWidth -= monitorInfo.Work.Left - startPoint.X;
                        startPoint.X = monitorInfo.Work.Left;
                    }
                    // Set width
                    popup.Width = Math.Min(actualWidth, inWindowRibbonWidth);
                    return(new CustomPopupPlacement[]
                    {
                        new CustomPopupPlacement(new Point(startPoint.X - tabItemPos.X, SelectedTabItem.ActualHeight - (popup.Child as FrameworkElement).Margin.Top), PopupPrimaryAxis.None),
                        new CustomPopupPlacement(new Point(startPoint.X - tabItemPos.X, -(SelectedContent as RibbonGroupsContainer).ActualHeight - (popup.Child as FrameworkElement).Margin.Bottom), PopupPrimaryAxis.None),
                    });
                }
            }
            return(null);
        }
        /// <summary>
        /// Returns monitor in witch control is placed
        /// </summary>
        /// <param name="control">Control</param>
        /// <returns>Workarea in witch control is placed</returns>
        public static Rect GetControlMonitor(FrameworkElement control)
        {
            Point tabItemPos = control.PointToScreen(new Point(0, 0));

            NativeMethods.Rect tabItemRect = new NativeMethods.Rect();
            tabItemRect.Left   = (int)tabItemPos.X;
            tabItemRect.Top    = (int)tabItemPos.Y;
            tabItemRect.Right  = (int)tabItemPos.X + (int)control.ActualWidth;
            tabItemRect.Bottom = (int)tabItemPos.Y + (int)control.ActualHeight;
            uint MONITOR_DEFAULTTONEAREST = 0x00000002;

            System.IntPtr monitor = NativeMethods.MonitorFromRect(ref tabItemRect, MONITOR_DEFAULTTONEAREST);
            if (monitor != System.IntPtr.Zero)
            {
                NativeMethods.MonitorInfo monitorInfo = new NativeMethods.MonitorInfo();
                monitorInfo.Size = Marshal.SizeOf(monitorInfo);
                NativeMethods.GetMonitorInfo(monitor, monitorInfo);
                return(new Rect(monitorInfo.Monitor.Left, monitorInfo.Monitor.Top, monitorInfo.Monitor.Right - monitorInfo.Monitor.Left, monitorInfo.Monitor.Bottom - monitorInfo.Monitor.Top));
            }
            return(new Rect());
        }
        public ImGuiRender(Device dev, NativeMethods.Rect windowRect, CaptureInterface _interface, IntPtr windowHandle)
        {
            device        = dev;
            _windowHandle = windowHandle;
            IntPtr InputHookAddr = LocalHook.GetProcAddress("user32.dll", "GetRawInputData");

            inputHook = LocalHook.Create(InputHookAddr, new inputHookDelegate(inputHookSub), this);
            inputHook.ThreadACL.SetExclusiveACL(new Int32[0]);
            OriginalInputHook =
                (inputHookDelegate)Marshal.GetDelegateForFunctionPointer(InputHookAddr, typeof(inputHookDelegate));
            var defWindowProcWAddr = LocalHook.GetProcAddress("user32.dll", "DefWindowProcW");

            DefWindowProcWHook = LocalHook.Create(defWindowProcWAddr, new TWindowProcW(WindowProcWImplementation), this);
            DefWindowProcWHook.ThreadACL.SetExclusiveACL(new int[0]);
            OriginalWndProcHook = (TWindowProcW)Marshal.GetDelegateForFunctionPointer(defWindowProcWAddr, typeof(TWindowProcW));
            var io = ImGui.GetIO();

            UpdateCanvasSize(windowRect.Right - windowRect.Left, windowRect.Bottom - windowRect.Top);
            PrepareTextureImGui();
            SetupKeyMapping(io);
        }
        public void SetPosition()
        {
            if (MenuBar != null)
            {
                dpiScale = VisualTreeHelper.GetDpi(this).DpiScaleX;

                double desiredTop    = MenuBar.Top + MenuBar.ActualHeight;
                double desiredLeft   = MenuBar.Left;
                double desiredHeight = 14;
                double desiredWidth  = MenuBar.ActualWidth;

                if (dpiScale != MenuBar.dpiScale)
                {
                    // we want to always match the menu bar DPI for correct positioning
                    long newDpi = (int)(MenuBar.dpiScale * 96) & 0xFFFF | (int)(MenuBar.dpiScale * 96) << 16;

                    NativeMethods.Rect newRect = new NativeMethods.Rect
                    {
                        Top    = (int)(desiredTop * MenuBar.dpiScale),
                        Left   = (int)(desiredLeft * MenuBar.dpiScale),
                        Bottom = (int)((desiredTop + desiredHeight) * MenuBar.dpiScale),
                        Right  = (int)((desiredLeft + desiredWidth) * MenuBar.dpiScale)
                    };
                    IntPtr newRectPtr = Marshal.AllocHGlobal(Marshal.SizeOf(newRect));
                    Marshal.StructureToPtr(newRect, newRectPtr, false);
                    NativeMethods.SendMessage(Handle, (int)NativeMethods.WM.DPICHANGED, (IntPtr)newDpi, newRectPtr);
                    Marshal.FreeHGlobal(newRectPtr);
                }
                else
                {
                    // reset properties so we actually reposition
                    Top = 0;

                    Top    = desiredTop;
                    Left   = desiredLeft;
                    Height = desiredHeight;
                    Width  = desiredWidth;
                }
            }
        }
Exemple #21
0
        internal virtual void AfterAppBarPos(bool isSameCoords, NativeMethods.Rect rect)
        {
            // apparently the TaskBars like to pop up when AppBars change
            if (Settings.Instance.EnableTaskbar && !Startup.IsShuttingDown)
            {
                AppBarHelper.HideWindowsTaskbar();
            }

            if (!isSameCoords)
            {
                var timer = new DispatcherTimer {
                    Interval = TimeSpan.FromSeconds(0.1)
                };
                timer.Start();
                timer.Tick += (sender1, args) =>
                {
                    // set position again, since WPF may have overridden the original change from AppBarHelper
                    SetAppBarPosition(rect);

                    timer.Stop();
                };
            }
        }
        public Bitmap GetScreenshotModernApp()
        {
            var rect = new NativeMethods.Rect();
            NativeMethods.GetWindowRect(mainWindowHandle, ref rect);

            int width = rect.right - rect.left;
            int height = rect.bottom - rect.top;

            try
            {
                Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                Graphics graphics = Graphics.FromImage(bmp);
                graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new System.Drawing.Size(width, height), CopyPixelOperation.SourceCopy);

                bmp.Save("c:\\users\\breiche\\pictures\\minesweeperWindow.png", ImageFormat.Png);
                return bmp;
            }
            catch (Exception e)
            {
                throw new ModernAppUIAutomationException("Failed to get a screenshot from " + modernAppName, e.InnerException);
            }
        }
Exemple #23
0
        /// <summary>
        ///     Implementation of capturing from the render target of the Direct3D9 Device (or DeviceEx)
        /// </summary>
        /// <param name="device"></param>
        private void DoCaptureRenderTarget(Device device, string hook)
        {
            if (CaptureThisFrame)

            #region CompasRenderLoop

            {
                try
                {
                    if (imGuiRender == null && device != null && device.NativePointer != IntPtr.Zero)
                    {
                        Trace.Write("Creating ImGui");
                        var handle = CurrentProcess.MainWindowHandle;
                        var rect   = new NativeMethods.Rect();
                        NativeMethods.GetWindowRect(handle, ref rect);
                        _sprite = ToDispose(new Sprite(device));
                        IntialiseElementResources(device);
                        imGuiRender = ToDispose(new ImGuiRender(device, rect, Interface, handle));
                    }
                    else if (imGuiRender != null)
                    {
                        if (Services.CompassSettings.ShowFPS)
                        {
                            PerfomanseTester.Reset();
                            PerfomanseTester.Start();
                        }
                        _sprite.Begin(SpriteFlags.AlphaBlend);
                        imGuiRender.GetNewFrame();

                        var CompassViewModel = PacketProcessor.Instance?.CompassViewModel;
                        CompassViewModel?.Render(_sprite);

                        //if (UIState.SettingsOpened)
                        //    ImGuiNative.igShowDemoWindow(ref UIState.OverlayOpened);
                        if (Services.CompassSettings.ShowFPS)
                        {
                            var draw_list = ImGui.GetOverlayDrawList();
                            draw_list.AddText(new Vector2(10, 100), $"RenderingTime(ms) = {Elapsed.Milliseconds}", Color.Red.ToDx9ARGB());
                            draw_list.AddImageRounded((IntPtr)_imageCache["incombat.png"], new Vector2(64, 64), new Vector2(100, 100), new Vector2(100, 100), Vector2.One,
                                                      Color.Red.ToDx9ARGB(), 2, 4);
                            //bool r=true;
                            //    ImGuiNative.igShowDemoWindow(ref r);
                        }

                        imGuiRender.Draw();
                        _sprite.End();
                        if (Services.CompassSettings.ShowFPS && PerfomanseTester.IsRunning)
                        {
                            PerfomanseTester.Stop();
                            Elapsed = PerfomanseTester.Elapsed;
                        }
                    }
                }
                catch (Exception e)
                {
                    DebugMessage(e.ToString());
                }
            }

            #endregion
        }
Exemple #24
0
        /// <summary>
        ///     Implementation of capturing from the render target of the Direct3D9 Device (or DeviceEx)
        /// </summary>
        /// <param name="device"></param>
        private void DoCaptureRenderTarget(Device device, string hook)
        {
            FPS.Frame();
            if (CaptureThisFrame)

            #region CompasRenderLoop

            {
                try
                {
                    if (imGuiRender == null && device != null && device.NativePointer != IntPtr.Zero)
                    {
                        Trace.Write("Creating ImGui");
                        var handle = CurrentProcess.MainWindowHandle;
                        var rect   = new NativeMethods.Rect();
                        NativeMethods.GetWindowRect(handle, ref rect);
                        _sprite = ToDispose(new Sprite(device));
                        IntialiseElementResources(device);
                        imGuiRender = ToDispose(new ImGuiRender(device, rect, Interface, CurrentProcess));
                    }
                    else if (imGuiRender != null)
                    {
                        if (Services.CompassSettings.ShowRenderTime)
                        {
                            PerfomanseTester.Reset();
                            PerfomanseTester.Start();
                        }
                        else if (PerfomanseTester.IsRunning)
                        {
                            PerfomanseTester.Stop();
                        }

                        _sprite.Begin(SpriteFlags.AlphaBlend);

                        imGuiRender.GetNewFrame();
                        var CompassViewModel = PacketProcessor.Instance?.CompassViewModel;
                        CompassViewModel?.Render(_sprite);
                        //ImGui.ShowDemoWindow();
                        if (Services.CompassSettings.ShowRenderTime)
                        {
                            var draw_list = ImGui.GetOverlayDrawList();
                            draw_list.AddText(new Vector2(10, 100), $"RenderingTime(ms) = {Elapsed.Milliseconds}", Color.Red.ToDx9ARGB());
                            draw_list.AddText(new Vector2(10, 50), DateTime.Now.ToString("HH: mm:ss.fff"), Color.White.ToDx9ARGB());
                        }
                        if (Services.CompassSettings.ShowFPS)
                        {
                            ImGui.SetNextWindowBgAlpha(0);

                            if (ImGui.Begin("FPS counter", ref Services.CompassSettings._showFps, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.AlwaysAutoResize))
                            {
                                ImGui.SetWindowFontScale(1.3F);
                                ImGui.Text($"{FPS.GetFPS():n0} fps");
                            }
                            ImGui.End();
                        }
                        _sprite.End();
                        imGuiRender.Draw();

                        if (Services.CompassSettings.ShowRenderTime && PerfomanseTester.IsRunning)
                        {
                            PerfomanseTester.Stop();
                            Elapsed = PerfomanseTester.Elapsed;
                        }
                    }
                }
                catch (Exception e)
                {
                    DebugMessage(e.ToString());
                    _sprite.End();
                }
            }

            #endregion
        }
Exemple #25
0
        public void DoWork()
        {
            int currentProcessId = Process.GetCurrentProcess().Id;

            while (!_shouldStop)
            {
                wndList.Clear();

                // get the visible applications
                var collection = new List <Windows.WindowsAppMgr.WndAttributes>();
                NativeMethods.EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
                {
                    uint processId = 0;
                    NativeMethods.GetWindowThreadProcessId(hWnd, out processId);
                    if (processId == currentProcessId)
                    {
                        return(true);
                    }

                    if (IsAltTabWindow(hWnd) == false)
                    {
                        return(true);
                    }

                    StringBuilder strbTitle = new StringBuilder(255);
                    int           nLength   = NativeMethods.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
                    string        strTitle  = string.Empty;
                    try
                    {
                        strTitle = strbTitle.ToString();
                    }
                    catch (Exception)
                    {
                    }

                    try
                    {
                        Process process     = Process.GetProcessById((int)processId);
                        string  processName = process.ProcessName;
                        if (processName.Contains("rgbxsvr")) //|| processName.Contains("vncviewer"))
                        {
                            // for video capture window
                            NativeMethods.Rect wndRect = new NativeMethods.Rect();
                            NativeMethods.GetWindowRect(hWnd, ref wndRect);

                            int style = NativeMethods.GetWindowLong(hWnd, Constant.GWL_STYLE);
                            style |= (int)Constant.WS_THICKFRAME;       // always able to resize the window
                            style |= (int)Constant.WS_CAPTION;          // always able to close the window
                            collection.Add(new Windows.WindowsAppMgr.WndAttributes {
                                id = hWnd.ToInt32(), processId = processId, name = strTitle, posX = wndRect.Left, posY = wndRect.Top, width = wndRect.Right - wndRect.Left, height = wndRect.Bottom - wndRect.Top, style = style
                            });

                            return(true);
                        }

                        if (string.IsNullOrEmpty(strTitle) == false)
                        {
                            NativeMethods.Rect wndRect = new NativeMethods.Rect();
                            NativeMethods.GetWindowRect(hWnd, ref wndRect);

                            int style = NativeMethods.GetWindowLong(hWnd, Constant.GWL_STYLE);
                            collection.Add(new Windows.WindowsAppMgr.WndAttributes {
                                id = hWnd.ToInt32(), processId = processId, name = strTitle, posX = wndRect.Left, posY = wndRect.Top, width = wndRect.Right - wndRect.Left, height = wndRect.Bottom - wndRect.Top, style = style
                            });
                        }
                    }
                    catch (Exception)
                    {
                    }


                    return(true);
                };

                if (NativeMethods.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero))
                {
                    foreach (var item in collection)
                    {
                        wndList.Add(item);
                    }
                }

                if (EvtWndAttributes != null)
                {
                    EvtWndAttributes(wndList);
                }

                Thread.Sleep(100);
            }
        }