embed a VB Standard EXE in a .Net Windows app - in-place activatio

G

Guest

I am having an existing VB 6 standard .EXE application. Now I am developing a
wrapper application in .Net and I want to launch the VB 6 exe app embedded
with
in the .Net App window. That is, the standard EXE application should be
activated in-place within the .Net window and should be confined within the
..Net app window.

Any suggestions on how I go about doing this stuff?

This is a repeat post for the new visitors.
 
C

Craig Vermeer

Okay, here goes.

To launch a vb6 exe as a child of a winform, you can make the following
changes to the control in the CodeProject article:

Where it grabs the window handle to the child app:
// Start the process
p = System.Diagnostics.Process.Start(this.exeName);
// Wait for process to be created and enter idle condition
p.WaitForInputIdle();
// Get the main handle
appWin = p.MainWindowHandle;

Replace the last line with this method call:

// Note, p.MainWindowHandle points to the hidden VB main application
// window (classname ThunderRT6Main)
// that own's the VB Main form window. We need to find the VB Main Form
// window (classname ThunderRT6FormDC)
appWin = FindMainVBForm(p.MainWindowHandle);

And, of course, add the method. This finds the window handle to the
real VB6 form instead of the hidden one that is the mainwindowhandle of
the process.

/// <summary>
/// VB Applications have a hidden top window which own's the window that
/// is the main VB form. The OwnerWindow is a pointer to this hidden
/// window.
/// This window is not the parent of the main VB form (classname
/// ThunderRT6FormDC). So we need to loop through all the windows to
/// find the window that has the OwnerWindow as it's owner.
/// </summary>
/// <param name="OwnerWindow">Pointer to OwnerWindow (classname
/// ThunderFormRT6Main</param>
/// <returns></returns>
private IntPtr FindMainVBForm( IntPtr OwnerWindow )
{
IntPtr pCurWindow = GetWindow(OwnerWindow, GW_HWNDFIRST );
while( pCurWindow != IntPtr.Zero )
{
// Check
if( GetWindow( pCurWindow, GW_OWNER ) == OwnerWindow )
{
break;
}
pCurWindow = GetWindow(pCurWindow, GW_HWNDNEXT );
}
return pCurWindow;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top