- UID
- 390967
- 帖子
- 1592
- 主題
- 821
- 精華
- 0
- 積分
- 854
- 楓幣
- 10961
- 威望
- 395
- 存款
- 10100
- 贊助金額
- 1800
- 推廣
- 0
- GP
- 2677
- 閱讀權限
- 150
- 在線時間
- 189 小時
- 註冊時間
- 2023-5-18
- 最後登入
- 2024-11-21
|
- public static WindowInfo GetWindowDetail(IntPtr hWnd)
- {
- // 視窗類別名
- var lpString = new StringBuilder(512);
- User32.GetClassName(hWnd, lpString, lpString.Capacity);
- var className = lpString.ToString();
- // 視窗標題
- var lptrString = new StringBuilder(512);
- User32.GetWindowText(hWnd, lptrString, lptrString.Capacity);
- var title = lptrString.ToString().Trim();
- // 視窗可視性
- var isVisible = User32.IsWindowVisible(hWnd);
- // 視窗位置與大小
- User32.LPRECT rect = default;
- User32.GetWindowRect(hWnd, ref rect);
- var bounds = new Rect(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top);
- // 視窗所在進程資訊
- var processInfo = ProcessInfosByHwnd.GetInfo(hWnd);
- return new WindowInfo(hWnd, className, title, isVisible, bounds, processInfo);
- }
複製代碼 User32函數- public static class User32
- {
- [DllImport("user32.dll", SetLastError = true)]
- public static extern IntPtr GetWindow(IntPtr hwnd, uint windowType);
- public delegate bool WndEnumProc(IntPtr hWnd, int lParam);
- [DllImport("user32")]
- public static extern bool Enumwindows(WndEnumProc lpEnumFunc, int lParam);
- [DllImport("user32")]
- public static extern IntPtr GetParent(IntPtr hWnd);
- [DllImport("user32")]
- public static extern bool IsWindowVisible(IntPtr hWnd);
- [DllImport("user32")]
- public static extern int GetWindowText(IntPtr hWnd, StringBuilder lptrString, int nMaxCount);
- [DllImport("user32")]
- public static extern int GetClassName(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
- [DllImport("user32")]
- public static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
- [DllImport("user32")]
- public static extern bool GetWindowRect(IntPtr hWnd, ref LPRECT rect);
- [StructLayout(LayoutKind.Sequential)]
- public readonly struct LPRECT
- {
- public readonly int Left;
- public readonly int Top;
- public readonly int Right;
- public readonly int Bottom;
- }
- }
複製代碼 |
|