FindWindow() приватный Метод

private FindWindow ( string lpClassName, string lpWindowName ) : IntPtr
lpClassName string
lpWindowName string
Результат IntPtr
Пример #1
0
        public bool[] CheckGameRunning()
        {
            var isGameRunning    = false;
            var isGameNoVR       = false;
            var isSteamVRRunning = false;

            var hwnd = WinApi.FindWindow("UnityWndClass", "VRChat");

            if (hwnd != IntPtr.Zero)
            {
                var cmdline = string.Empty;

                try
                {
                    WinApi.GetWindowThreadProcessId(hwnd, out uint pid);
                    using (var searcher = new ManagementObjectSearcher($"SELECT CommandLine FROM Win32_Process WHERE ProcessId = {pid}"))
                        using (var objects = searcher.Get())
                        {
                            cmdline = objects.Cast <ManagementBaseObject>().SingleOrDefault()?["CommandLine"]?.ToString();
                        }
                    isGameNoVR = cmdline.Contains("--no-vr");
                }
                catch
                {
                }
            }

            if (Process.GetProcessesByName("vrchat").Length > 0)
            {
                isGameRunning = true;
            }

            if (Process.GetProcessesByName("vrserver").Length > 0)
            {
                isSteamVRRunning = true;
            }

            return(new bool[]
            {
                isGameRunning,
                isGameNoVR,
                isSteamVRRunning
            });
        }
Пример #2
0
 public bool IsGameRunning()
 {
     return(WinApi.FindWindow("UnityWndClass", "VRChat") != IntPtr.Zero);
 }