| 1 | using Core.Librarys; |
| 2 | using Core.Models.AppObserver; |
| 3 | using Core.Servicers.Interfaces; |
| 4 | using System; |
| 5 | using System.Collections.Generic; |
| 6 | using System.Linq; |
| 7 | using System.Text; |
| 8 | using System.Threading.Tasks; |
| 9 | |
| 10 | namespace Core.Servicers.Instances |
| 11 | { |
| 12 | public class WindowManager : IWindowManager |
| 13 | { |
| 14 | |
| 15 | public WindowInfo GetWindowInfo(IntPtr handle_) |
| 16 | { |
| 17 | try |
| 18 | { |
| 19 | string title = GetWindowTitle(handle_); |
| 20 | var rect = Win32API.GetWindowRect(handle_); |
| 21 | string className = Win32API.GetWindowClassName(handle_); |
| 22 | int width = rect.Width; |
| 23 | int height = rect.Height; |
| 24 | int x = rect.Left; |
| 25 | int y = rect.Top; |
| 26 | |
| 27 | return new WindowInfo(className, title, handle_, width, height, x, y); |
| 28 | } |
| 29 | catch (Exception e) |
| 30 | { |
| 31 | return WindowInfo.Empty; |
| 32 | } |
| 33 | |
| 34 | } |
| 35 | |
| 36 | ///<summary> |
| 37 | /// |
| 38 | ///</summary> |
| 39 | ///<param name="handle_"></param> |
| 40 | ///<returns></returns> |
| 41 | private string GetWindowTitle(IntPtr handle_) |
| 42 | { |
| 43 | try |
| 44 | { |
| 45 | int titleCapacity = Win32API.GetWindowTextLength(handle_) * 2; |
| 46 | StringBuilder stringBuilder = new StringBuilder(titleCapacity); |
| 47 | Win32API.GetWindowText(handle_, stringBuilder, stringBuilder.Capacity); |
| 48 | string title = stringBuilder.ToString(); |
| 49 | return stringBuilder.ToString(); |
| 50 | } |
| 51 | catch (Exception e) |
| 52 | { |
| 53 | return string.Empty; |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | } |