G
Guest
I have a requirement where I need to embed a VB 6 forms application into .Net
forms application. Basically the new .Net application would act as a wrapper
application and would control the embedded VB 6 application.
I tried to start the VB 6 in a separate process from dot net app and
acquired the handle of the handle to the main window of the process.
Next I used to use Win32 API function SetParent to set the parent of the VB
6 application window to the dot net application window.
But when I run the dot net app, it creates the VB 6 app and window is
launched. But the SetParent does not work as the VB 6 app window stays
separately outside the dot net app window.
I have pasted the code below for better clarity:
//Creating VB 6 app process
Process p = null;
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = this.exeName;
startInfo.WindowStyle = ProcessWindowStyle.Normal;
p = Process.Start(this.exeName);
//Waiting till the VB 6 process finishes its execution
p.WaitForInputIdle();
appWin = p.MainWindowHandle;
//Change the window attributes of the VB 6 app so that it can become a
//child window to another window...
long result = GetWindowLongA(appWin, GWL_STYLE);
long newResult = result | WS_CHILD | WS_OVERLAPPEDWINDOW;
SetWindowLongA(appWin, GWL_STYLE, newResult);
//Use SetParent for changing the parent...
IntPtr a = SetParent(appWin, this.Handle);
//Move the child window within the parent window
MoveWindow(appWin, 0, 0, this.Width, this.Height, true);
This method works roughly for embedding app window in another dot net
application. But do not work for the embedding a VB 6 app window.
What am I missing here?
forms application. Basically the new .Net application would act as a wrapper
application and would control the embedded VB 6 application.
I tried to start the VB 6 in a separate process from dot net app and
acquired the handle of the handle to the main window of the process.
Next I used to use Win32 API function SetParent to set the parent of the VB
6 application window to the dot net application window.
But when I run the dot net app, it creates the VB 6 app and window is
launched. But the SetParent does not work as the VB 6 app window stays
separately outside the dot net app window.
I have pasted the code below for better clarity:
//Creating VB 6 app process
Process p = null;
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = this.exeName;
startInfo.WindowStyle = ProcessWindowStyle.Normal;
p = Process.Start(this.exeName);
//Waiting till the VB 6 process finishes its execution
p.WaitForInputIdle();
appWin = p.MainWindowHandle;
//Change the window attributes of the VB 6 app so that it can become a
//child window to another window...
long result = GetWindowLongA(appWin, GWL_STYLE);
long newResult = result | WS_CHILD | WS_OVERLAPPEDWINDOW;
SetWindowLongA(appWin, GWL_STYLE, newResult);
//Use SetParent for changing the parent...
IntPtr a = SetParent(appWin, this.Handle);
//Move the child window within the parent window
MoveWindow(appWin, 0, 0, this.Width, this.Height, true);
This method works roughly for embedding app window in another dot net
application. But do not work for the embedding a VB 6 app window.
What am I missing here?