我的一個朋友做了這項工作有時候是前!
你應該做的事情是這樣的:
首次導入系統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