Beispiel #1
0
        public virtual Task Clean()
        {
            return(Task.Run(() =>
            {
                Initlize();

                if (process != null)
                {
                    try
                    {
                        process.Kill();
                    }
                    catch (Exception)
                    {
                    }
                    process = null;
                }

                if (!string.IsNullOrEmpty(_defaultBG))
                {
                    ImgWallpaper.SetBG(_defaultBG);
                    _defaultBG = null;
                }
            }));
        }
Beispiel #2
0
        public virtual async Task Show(string appPath, string args)
        {
            if (string.IsNullOrEmpty(appPath))
            {
                return;
            }

            bool isOk = await Task.Run(() => Initlize());

            if (!isOk)
            {
                return;
            }

            KillOldProcess();

            _defaultBG = await ImgWallpaper.GetCurrentBG();


            string exeName = Path.GetFileName(appPath);
            bool   isInt   = int.TryParse(exeName, out int Pid);

            if (isInt)
            {
                process = Process.GetProcessById(Pid);
            }
            else
            {
                string name = Path.GetFileNameWithoutExtension(exeName);
                foreach (Process exe in Process.GetProcessesByName(name))
                {
                    try
                    {
                        if (exe.MainModule.FileName == exeName)
                        {
                            process = exe;
                            break;
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                if (process == null)
                {
                    ProcessStartInfo startInfo = new ProcessStartInfo(appPath)
                    {
                        WindowStyle = ProcessWindowStyle.Maximized
                    };
                    double width  = Screen.AllScreens[0].Bounds.Width;
                    double height = Screen.AllScreens[0].Bounds.Height;
                    startInfo.Arguments = $"{args} -popupwindow -screen-height {height} -screen-width {width}";
                    //startInfo.Arguments = $" -popupwindow -screen-width {y1}";
                    process = Process.Start(startInfo);
                }
            }
            cacheMainHandle = await TryGetMainWindowHandle(process);

            cacheParent = USER32Wrapper.GetParent(cacheMainHandle);
            USER32Wrapper.SetParent(cacheMainHandle, workerw);
        }