使用 SetParent 的 DirectX 游戏冻结问题

发布于 2025-01-10 13:08:30 字数 2788 浏览 3 评论 0原文

DirectX 游戏冻结问题在显示“以管理员身份运行”窗口后开始。

我尝试了 SetWindowPos()SetWindowLong()ShowWindow()SetForegroundWindow()SetActiveWindow () 功能,但不能解决冻结问题。

所有功能都可以在不使用 SetParent() 的情况下运行。如何使用像 VisualBasic.interaction.AppActivate() 函数这样的 SetParent 来激活窗口句柄?

NOT:这不是“不响应”

在此处输入图像描述

本机:

using System.Runtime.InteropServices;
 using System.Diagnostics.Process;

  //SetWindowPos Function.
 [DllImport("user32.dll")]
    public static extern bool SetWindowPos(IntPtr handle, IntPtr HandleInsertAfter, int Xkoordanit, int Ykoordanit, int cxboyut, int cyboyut, uint uFlags);
 public const int SWP_SHOWWINDOW = 0x0040;
 public const int SWP_NOSIZE = 0x0001;
 public const int SWP_NOMOVE = 0x0002;
 // SetWindowLong Function.
 [DllImport("user32.dll")]
 public static extern uint SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
 public const int GWL_STYLE = (-16);
 public abstract class WindowStyles
 {
     public const uint WS_OVERLAPPED = 0x00000000;
     public const uint WS_CAPTION = 0x00C00000;
     public const uint WS_SYSMENU = 0x00080000;
     public const uint WS_THICKFRAME = 0x00040000;
     public const uint WS_MINIMIZEBOX = 0x00020000;
     public const uint WS_MAXIMIZEBOX = 0x00010000;
 }
 // ShowWindow Function
 [DllImport("user32.dll")]
    public static extern bool ShowWindow(IntPtr handle, int nCmdShow);
 // SetForegroundWindow Function.
 [DllImport("user32.dll")]
 public static extern bool SetForegroundWindow(IntPtr hWnd);
 // SetActiveWindow
 [DllImport("user32.dll", SetLastError = true)]
 public static extern IntPtr SetActiveWindow(IntPtr hWnd);
 // SetParent function.
 [DllImport("user32.dll", SetLastError = true)]
 public static extern IntPtr SetParent(IntPtr MainWindowHandle, IntPtr Panel);

我尝试了像焦点窗口这样的代码:

// form2
Form2 form2 = new Form2(); 
// dock window to form2.panel
IntPtr Handle = gameProcess.MainWindowHandle;
IntPtr Docked = SetParent(Handle, form2.panel1.handle);
// i tried all functions.
SetWindowPos(Handle, IntPtr.Zero, 0, 0, 1024, 768, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
SetWindowPos(Handle, IntPtr.Zero, 0,0, 1024,768, SWP_SHOWWINDOW);
SetWindowLong(Handle, GWL_STYLE, (WindowStyles.WS_OVERLAPPED | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU | WindowStyles.WS_THICKFRAME | WindowStyles.WS_MINIMIZEBOX | WindowStyles.WS_MAXIMIZEBOX));
ShowWindow(Handle, 9); // ShowWindow = 9
SetForegroundWindow(handle);
Microsoft.VisualBasic.interaction.AppActivate(gameProcess.Id); // Need Microsoft.VisualBasic library DLL
SetActiveWindow(Handle);

The DirectX Game Freeze issue started after show the 'Run As Administrator' window.

I tried SetWindowPos(), SetWindowLong(), ShowWindow(), SetForegroundWindow(), SetActiveWindow() functions but don't fix the freeze problem.

All functions is working without using SetParent(). How to Active window handle using SetParent like VisualBasic.interaction.AppActivate() function?

NOT: this is not 'not responding'

enter image description here

Native:

using System.Runtime.InteropServices;
 using System.Diagnostics.Process;

  //SetWindowPos Function.
 [DllImport("user32.dll")]
    public static extern bool SetWindowPos(IntPtr handle, IntPtr HandleInsertAfter, int Xkoordanit, int Ykoordanit, int cxboyut, int cyboyut, uint uFlags);
 public const int SWP_SHOWWINDOW = 0x0040;
 public const int SWP_NOSIZE = 0x0001;
 public const int SWP_NOMOVE = 0x0002;
 // SetWindowLong Function.
 [DllImport("user32.dll")]
 public static extern uint SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
 public const int GWL_STYLE = (-16);
 public abstract class WindowStyles
 {
     public const uint WS_OVERLAPPED = 0x00000000;
     public const uint WS_CAPTION = 0x00C00000;
     public const uint WS_SYSMENU = 0x00080000;
     public const uint WS_THICKFRAME = 0x00040000;
     public const uint WS_MINIMIZEBOX = 0x00020000;
     public const uint WS_MAXIMIZEBOX = 0x00010000;
 }
 // ShowWindow Function
 [DllImport("user32.dll")]
    public static extern bool ShowWindow(IntPtr handle, int nCmdShow);
 // SetForegroundWindow Function.
 [DllImport("user32.dll")]
 public static extern bool SetForegroundWindow(IntPtr hWnd);
 // SetActiveWindow
 [DllImport("user32.dll", SetLastError = true)]
 public static extern IntPtr SetActiveWindow(IntPtr hWnd);
 // SetParent function.
 [DllImport("user32.dll", SetLastError = true)]
 public static extern IntPtr SetParent(IntPtr MainWindowHandle, IntPtr Panel);

i tried code like focus window:

// form2
Form2 form2 = new Form2(); 
// dock window to form2.panel
IntPtr Handle = gameProcess.MainWindowHandle;
IntPtr Docked = SetParent(Handle, form2.panel1.handle);
// i tried all functions.
SetWindowPos(Handle, IntPtr.Zero, 0, 0, 1024, 768, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
SetWindowPos(Handle, IntPtr.Zero, 0,0, 1024,768, SWP_SHOWWINDOW);
SetWindowLong(Handle, GWL_STYLE, (WindowStyles.WS_OVERLAPPED | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU | WindowStyles.WS_THICKFRAME | WindowStyles.WS_MINIMIZEBOX | WindowStyles.WS_MAXIMIZEBOX));
ShowWindow(Handle, 9); // ShowWindow = 9
SetForegroundWindow(handle);
Microsoft.VisualBasic.interaction.AppActivate(gameProcess.Id); // Need Microsoft.VisualBasic library DLL
SetActiveWindow(Handle);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文