C# 让一个单独的应用程序重新确认它的大小已调整
我有一个单独的游戏,我正在运行,我把它调整到我的C项目表单的一部分大小。工作方式正是我希望它除了游戏不承认它已被调整大小。因此,所有的控制输入都有点不正确,UI比例也不正确。奇怪的是,如果我手动调整或移动游戏窗口,一切都会自行修复 尝试SendMessage和Invalidate,最小化和最大化窗口,但运气不佳。这是我目前拥有的C# 让一个单独的应用程序重新确认它的大小已调整,c#,winapi,unmanaged,C#,Winapi,Unmanaged,我有一个单独的游戏,我正在运行,我把它调整到我的C项目表单的一部分大小。工作方式正是我希望它除了游戏不承认它已被调整大小。因此,所有的控制输入都有点不正确,UI比例也不正确。奇怪的是,如果我手动调整或移动游戏窗口,一切都会自行修复 尝试SendMessage和Invalidate,最小化和最大化窗口,但运气不佳。这是我目前拥有的 Process firstGame = Process.GetProcessesByName("gameprocessname").ElementAt(0); if
Process firstGame = Process.GetProcessesByName("gameprocessname").ElementAt(0);
if (firstGame != null)
{
try
{
IntPtr firstGameHandle = firstGame.MainWindowHandle; //get handle of game win
IntPtr mainFormHandle = this.Handle; // store handle of my app
SetWindowLong(firstGameHandle, GWL_STYLE, WS_BORDER); // get rid of borders
// move the window where we want
SetWindowPos(
firstGameHandle, (IntPtr)0, gb.Location.X, gb.Location.Y, gb.Width, gb.Height,
SHOWWINDOW);
// make my application parent of the game
SetParent(firstGameHandle, mainFormHandle);
// child handle was lost on SetParent(); get Game handle again
IntPtr childHandle = FindWindowEx(
this.Handle, IntPtr.Zero, "gamewndclass", "titlecaption");
SetWindowText(childHandle, gameTitle); //Rename gamewindow
SetForegroundWindow(childHandle); //set game window as active
boxhandle = childHandle; //store the game windows handle
// last thing I tried to get window to redraw and reset
RedrawWindow(
this.Handle, IntPtr.Zero, IntPtr.Zero,
RedrawWindowFlags.Frame |
RedrawWindowFlags.UpdateNow |
RedrawWindowFlags.Invalidate);
}
catch (Exception er)
{
MessageBox.Show("Error: " + er.ToString());
}
这涉及到使用挂钩。我想这是一个开始,至少为我指明了一个新的方向。谢谢,这是相似的。不是真的想知道什么时候爆炸,而是想知道如何触发。由于某些原因,窗口会按精细的边框调整大小,但内容或游戏窗口的缩放无法适应新窗口的大小。手动缩放窗口或按标题栏移动窗口似乎可以重置内容。我只是想让我的程序在游戏窗口上触发与用户手动调整窗口大小相同的调用。如果这看起来很复杂,很抱歉