NetAutoGUI.Windows/WindowsApplicationController.cs

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using Vanara.PInvoke;
using WildcardMatch;

namespace NetAutoGUI.Windows
{
	[SupportedOSPlatform("windows")]
	internal class WindowsApplicationController : IApplicationController
	{
        private static string GetWindowText(long hwnd)
        {
            StringBuilder sb = new StringBuilder(1024);
            User32.GetWindowText(new HWND(new IntPtr(hwnd)), sb, sb.Capacity);
            return sb.ToString();
        }

        private static Rectangle GetWindowRect(long hwnd)
        {
            User32.GetWindowRect(new HWND(new IntPtr(hwnd)), out RECT rect);
            return new Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
        }

        private static Window GetWindowDetail(HWND hwnd)
        {
            IntPtr intPtr = (IntPtr)hwnd;
            Window window = new Window(intPtr.ToInt64(), GetWindowRect, GetWindowText);
            return window;
        }

        public bool IsApplicationRunning(string processName)
		{
            //The ProcessName property does not include the .exe extension
            string nameWithoutExtension = Path.GetFileNameWithoutExtension(processName);
            return Process.GetProcesses().Any(p => nameWithoutExtension.Equals(p.ProcessName,StringComparison.OrdinalIgnoreCase));
		}

		public Process LaunchApplication(string appPath, string? arguments = null)
		{
			var startInfo = new ProcessStartInfo
			{
				FileName = appPath,
				Arguments = arguments,
				UseShellExecute = true,//这样就可以用"chrome.exe"这个相对路径启动,而不用全路径
			};
			return Process.Start(startInfo);
		}

		public Window? FindWindowByTitle(string title)
		{
			return FindWindow(t => title == t.Title);
		}

		public Window? FindWindow(Func<Window, bool> predict)
后面还有 94 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。