在C#Forms应用程序中嵌入游戏(自定义EXE) [英] Embedding a Game(custom EXE) inside a C# Forms Application
问题描述
Hello CodeProject,
我想在我的Forms应用程序中嵌入一个游戏(如:GTA等),我知道如何使用以下Code :: <简单的Windows窗体应用程序来实现它br />
Hello CodeProject,
I want to embed a game(like : GTA etc.) inside my Forms Application, I know how you do it with simple Windows Forms Applications using the following Code ::
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
//<JUMPING TO BUTTON_1 CLICK>
/////////////////////////////////.........................................................\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
private void button1_Click(object sender, EventArgs e)
{
try
{
Process p = Process.Start(textBox1.Text,textBox1.Text);
p.WaitForInputIdle(); // Allow the process to open it's window
SetParent(p.MainWindowHandle, panel1.Handle); //Set the Windows Parent as Panel1
}
catch (Exception ex)
{
MessageBox.Show("ERROR DUDE!!!!!\n" + ex.Message);
}
}
//Import a DLL called User32.dll for catching the Form
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
它有效适用于常规应用程序,如记事本,QEMU等。
但适用于游戏,浏览器等复杂应用程序。我遇到以下问题
1)对于大多数游戏,他们无法正确加载资源,例如当我从我的应用程序启动igi2.exe时需要IGI,
我收到一条错误消息说
It works for Normal Applications like Notepad,QEMU etc.
But for complex applications like Games,Browsers,etc. I get the following problems
1) For mostly Games, They are Not able to load resources properly, for instance take IGI,
when I start igi2.exe from my application I get a error message saying
"COULD NOT LOAD FILE : LOCAL:weapons.res"
同样适用于需要从HDD加载资源的游戏。
2)当我启动chrome,iexplore,explorer.exe或任何此类复杂的应用程序时,我的表单无法捕获它。另外我的错误处理程序显示以下消息(有时):
Same goes for Games that require resources to be loaded from HDD.
2)When I start chrome,iexplore,explorer.exe or any such complex application my Form is unable to catch it. Also My error handler show the following message(sometimes) :
"ERROR DUDE!!!!!!!!!!!!!!!!!
Process has exited"
任何解决方案/建议吗?
任何帮助将不胜感激
~Sids123
Any Solution/Suggestion to this?
Any help would be appreciated
~Sids123
推荐答案
我想你可以试试像......
嵌入 - 外部 - 可执行 - 内部 - 尖锐程序 [ ^ ]
或者,
可以将可执行文件作为资源嵌入到项目中,如...
http://www.cs.nyu.edu/~vs667/articles/embed_executable_tutorial/ [ ^ ]
I think you can try with something like..
Embedding-an-external-executable-inside-a-c-sharp-program[^]
Or,
can embed an executable as resource inside a project like..
http://www.cs.nyu.edu/~vs667/articles/embed_executable_tutorial/[^]
这篇关于在C#Forms应用程序中嵌入游戏(自定义EXE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!