469,945 Members | 2,383 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,945 developers. It's quick & easy.

SetParent Windows API function notworking with VB 6 forms

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?
Nov 22 '05 #1
1 3929
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.


SetParent is only meant to be used with windows in the same process.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Raghavendran Muraleetharan | last post: by
1 post views Thread by Scott Davies | last post: by
3 posts views Thread by miben | last post: by
4 posts views Thread by tshad | last post: by
reply views Thread by clarionprogrammer | last post: by
7 posts views Thread by Matt | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.