我的一个朋友做了这项工作有时候是前!
你应该做的事情是这样的:
首次导入系统DLL:
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", EntryPoint = "SetWindowLongA", SetLastError = true)]
private static extern long SetWindowLong(IntPtr hwnd, int nIndex, long dwNewLong);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
,现在我宣布一个计时器,并按照下列代码:
private const int GWL_STYLE = (-16);
private const int WS_VISIBLE = 0x10000000;
Process p;
/*Closing Is Timer*/
private void Closing_Tick(object sender, EventArgs e)
{
p.Refresh();
string a = p.ProcessName;
SetParent(p.MainWindowHandle, panel1.Handle);
SetWindowLong(p.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
MoveWindow(p.MainWindowHandle, 0, 0, this.Width, this.Height, true);
}
void run(string add)
{
string addres = add;
try
{
p = Process.Start(addres);
Thread.Sleep(500); // Allow the process to open it's window
SetParent(p.MainWindowHandle, panel1.Handle);
SetWindowLong(p.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
MoveWindow(p.MainWindowHandle, 0, 0, this.Width, this.Height, true);
}
catch
{
Closeing.Enabled = false;
MessageBox.Show(addres + "\n" + "Not Found", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
Environment.Exit(0);
}
}
private void button1_Click(object sender, EventArgs e)
{
Closeing.Enabled = true;
run(@textBox1.Text);
}
输入参数运行的方法是程序的路径使用想要在您的应用程序中运行
Hop e此帮助! :)
你的意思是你想要将他们的UI嵌入你的内部?无需他们的合作,这并不简单。 (并且它完全与TS无关;您需要Windows API方法来重新授予Windows) – SLaks
简短回答否,长答案,一切皆有可能...... – Jodrell
@Slaks:这就是为什么ProfK希望“成为本地主机上的TS客户端”,而不是重新设置窗口:因为TS *可以在没有“托管”UI(通常是)的合作下完成。 – Medinoc