Как разместить окно, порожденное другим процессом в собственном окне X11 в C #? - PullRequest
0 голосов
/ 01 апреля 2019

Мне нужно разместить окно, порожденное другим процессом внутри окна, которое я создаю, чтобы отправлять такие команды, как нажатия клавиш и т. Д., А также извлекать информацию из процесса в целях отладки (это для отладки игрового движка).с исходным кодом у нас нет доступа).

X11's XReparentWindow метод, кажется, мне нужно использовать для выполнения этой задачи;тем не менее, я получаю сообщение об ошибке X11: BadMatch (недопустимые атрибуты параметров).

        public bool LoadMugen_UNIX(int profileNo)
        {
            Display = new XDisplay(null);
            var dummy = new XWindow(Display, this.Handle);
            var allWindows = new XWindow(Display, new IntPtr(Display.Root));
            var sw = new Stopwatch();
            IntPtr processPtr = IntPtr.Zero;

            // Wait for MUGEN to be recognized
            sw.Start();
            while (sw.ElapsedMilliseconds < 5000 && processPtr == IntPtr.Zero)
            {
                try
                {
                    processPtr = FindWindows(Display.Handle, "M.U.G.E.N").FirstOrDefault(ptr => ptr != IntPtr.Zero);
                }
                catch
                {

                }
            }
            sw.Stop();
            processWindow = new XWindow(Display, processPtr);
            var pWindow = processWindow;
            var container = new XWindow(Display, this.backgroundBox.Handle);

            if (processWindow != null)
            {
                if (this.p == null || this.p.HasExited)
                {
                    this._mugen_type = MugenWindow.MugenType_t.MUGEN_TYPE_NONE;
                    if (this.p != null)
                        this.p.Dispose();
                    this.p = (Process)null;
                    if (LogManager.MainObj() != null)
                        LogManager.MainObj().appendLog("Failed to load the exe file.");
                    return false;
                }

                if (processWindow.Handle == IntPtr.Zero)
                {
                    if (LogManager.MainObj() != null)
                        LogManager.MainObj().appendLog("Failed to load the exe file.");
                    this.CloseMugen();
                    return false;
                }

                X11NativeMethods.XReparentWindow(Display.Handle, processWindow.Handle, container.Handle, 0,0);

                MugenProfile profile = ProfileManager.MainObj().GetProfile(profileNo);
                if (profile != null)
                {
                    DebugForm.MainObj().SetSpeedModeCheckBox(profile.IsSpeedMode(), true);
                    DebugForm.MainObj().SetSkipModeCheckBox(profile.IsSkipMode());
                    DebugForm.MainObj().SetDebugModeCheckBox(profile.IsDebugMode(), true);
                    DebugForm.MainObj().PreInitTriggerCheck(this._mugen_type);
                    this._workingProfileId = profile.GetProfileNo();
                }
                this._isMugenFrozen = false;
                this._isGameQuitted = false;
                this._isMugenCrashed = false;
                this._addr_db = MugenAddrDatabase.GetAddrDatabase(this._mugen_type);
                if (!this.mugenWatcher.IsBusy)
                    this.mugenWatcher.RunWorkerAsync();
                return true;
            }


            return false;
        }

X11 XReparentWindow определяется в отдельном файле как DllImport, например:

[DllImport("libX11.so")]
public static extern int XReparentWindow(IntPtr display, IntPtr w, IntPtr parent, int x, int y);

Я получаю следующую ошибку:

X11 Error encountered: 
  Error: BadMatch (invalid parameter attributes)
  Request:     7 (0)
  Resource ID: 0x8600062
  Serial:      2238
  Hwnd:        Hwnd, Mapped:True ClientWindow:0x8600062, WholeWindow:0x8600061, Zombie=False, Parent:[Hwnd, Mapped:True ClientWindow:0x8600060, WholeWindow:0x860005F, Zombie=False, Parent:[<null>]]
  Control:     System.Windows.Forms.PictureBox, SizeMode: StretchImage  at System.Environment.get_StackTrace () [0x00000] in /build/mono/src/mono/mcs/class/corlib/System/Environment.cs:316 
  Control:     System.Windows.Forms.PictureBox, SizeMode: StretchImage  at System.Environment.get_StackTrace () [0x00000] in /build/mono/src/mono/mcs/class/corlib/System/Environment.cs:316 
  at System.Windows.Forms.XplatUIX11.HandleError (System.IntPtr display, System.Windows.Forms.XErrorEvent& error_event) [0x00067] in /build/mono/src/mono/mcs/class/System.Windows.Forms/System.Windows.Forms/XplatUIX11.cs:2120 
  at XSharp.XWindow.XFetchName (System.IntPtr , System.IntPtr , System.IntPtr& ) [0x00000] in <af09c9b5837947a8b2263cd8aa794ae6>:0 
  at XSharp.XWindow.get_Name () [0x00007] in /run/media/jesuszilla/Roll/dev/xsharp/xsharp/xsharp.cs:1687 
  at SwissArmyKnifeForMugen.MugenWindow.LoadMugen_UNIX (System.Int32 profileNo) [0x001df] in /run/media/jesuszilla/Roll/dev/SAKnifeWM/SwissArmyKnifeForMugen/MugenWindow_Native.cs:75 

Что является причиной BadMatch и как мне пройти его, чтобы выполнить эту задачу?

...