I programmed a WinForm in .net by C# to opens VB6 exe in TabControl,
now all of Windows exe file like Notpad.exe or ... opens success in TabControl but VB6 does not open correctly in WinForm, it does not obey Parent/Child legal.
Now please help me, it is very important and neseccery for me.
In Addation:
1-in The Program used Procces class to start program and also used SetParent() for define Parent/Child legal.
2- I Used Telerik PageView to open windows in separated tabs.
code:
public string TabName;
public const int GWL_STYLE = -16;
public const uint WS_VISIBLE = 0x10000000;
private void radButtonElement3_Click(object sender, EventArgs e)
{
TabName = radButtonElement3.Text;
Telerik.WinControls.UI.RadPageViewPage Tab = new Telerik.WinControls.UI.RadPageViewPage(TabName);
radPageView1.Pages.Add(Tab);
radPageView1.SelectedPage = Tab;
IntPtr appWin;
appWin = IntPtr.Zero;
string exeName = Application.StartupPath + "\\" + "VB6.exe";
Process p = null;
try
{
p = System.Diagnostics.Process.Start(exeName);
p.WaitForInputIdle();
appWin = p.MainWindowHandle;
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message, "Error");
}
IntPtr _newHandler = radPageView1.Pages[(radPageView1.Pages.Count) - 1].Handle;
SetParent(p.MainWindowHandle, _newHandler);
SetWindowLong(_newHandler, GWL_STYLE, WS_VISIBLE);
MoveWindow(_newHandler, 0, 0, radPageView1.Pages[0].Size.Width, radPageView1.Pages[0].Size.Height, true);
}
[DllImport("user32.dll", EntryPoint = "GetWindowThreadProcessId", SetLastError = true,
CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
private static extern long GetWindowThreadProcessId(long hWnd, long lpdwProcessId);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll")]
public static extern int GetClassLong(IntPtr hWnd, int index);
[DllImport("user32.dll", SetLastError = true)]
private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", EntryPoint = "GetWindowLongA", SetLastError = true)]
private static extern long GetWindowLong(IntPtr hwnd, int nIndex);
[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 long SetWindowPos(IntPtr hwnd, long hWndInsertAfter, long x, long y, long cx, long cy, long wFlags);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
[DllImport("user32.dll", EntryPoint = "PostMessageA", SetLastError = true)]
private static extern bool PostMessage(IntPtr hwnd, uint Msg, long wParam, long lParam);