使用 SetParent 的 DirectX 游戏冻结问题
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'
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论