Another Programming Question

  • Thread starter Thread starter Yoshi
  • Start date Start date
Y

Yoshi

Hi everyone!

I am developing an application that runs a seperate executiblie file, calls
the SetParent API so the application is contained in my application.

The problem that I am having is I have to wait a certain period of time for
the application to completely run/load into memory before I can call the
SetParent api or it does nothing.

What's the best way to determine when an application is at a point to call
the SetParent API?

Thanks,

Y
 
SetParent is used to change the parent window of a child window, does it
mean you are trying to change the parent of a child window of a launched
(child) application to a window in your launching (parent) application? If
this is what you want, forget about it, parent/child relationship for window
handles is bound to the same application.

Willy.
 
Willy,

I have developed an application that launches a .exe program like "Excel."
My application gets the handle of this application and Sets Excel's parent
to my application of which it appears as if it's running my application.

The issue I am having is there's a point in which I need to call the
SetParent api for Excel to appear in my application. I have narrowed it down
to when the application has finished running. I am looking for a method to
wait for the application to finish loading so I can Set it's parent to my
application and see it running.

Thanks,

Y
 
Yoshi said:
Willy,

I have developed an application that launches a .exe program like "Excel."
My application gets the handle of this application and Sets Excel's parent
to my application of which it appears as if it's running my application.

The issue I am having is there's a point in which I need to call the
SetParent api for Excel to appear in my application. I have narrowed it
down to when the application has finished running. I am looking for a
method to wait for the application to finish loading so I can Set it's
parent to my application and see it running.
Please re-read my previous posting, this is not the purpose of SetParent.
Could you be more specific when talking about handles? When you say "My
application gets the handle ", I assume you are talking about the process
handle, not a window handle right?
Now what are you doing with this handle in relation to the SetParent API ?
A piece of code could say more than a thousand words I guess :-)

Willy.
 
Hey Willy...

Here is a quick example:

[DllImport("user32.dll")]

static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

System.Diagnostics.ProcessStartInfo si = new
System.Diagnostics.ProcessStartInfo();
si.FileName = "winword.exe";


si.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;


System.Diagnostics.Process p = System.Diagnostics.Process.Start(si);


p.EnableRaisingEvents = true;

p.Exited += new EventHandler(OnHasExited);

SetParent(p.MainWindowHandle, this.Handle);
 
Yoshi said:
Hey Willy...

Here is a quick example:

[DllImport("user32.dll")]

static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

System.Diagnostics.ProcessStartInfo si = new
System.Diagnostics.ProcessStartInfo();
si.FileName = "winword.exe";


si.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;


System.Diagnostics.Process p = System.Diagnostics.Process.Start(si);


p.EnableRaisingEvents = true;

p.Exited += new EventHandler(OnHasExited);

SetParent(p.MainWindowHandle, this.Handle);


You could use Process.WaitForInputIdle to make sure the process has started
and it's message loop is spinning.
BUT, as I said before what you are doing here :
SetParent(p.MainWindowHandle, this.Handle);
is wrong. SetParent takes two handles belonging to the same application, in
your case they belong to different applications. Did you ever checked the
return value? I guess you are not.
What exactly are you trying to achieve?

Willy.
 
I am developing an application that contains certain modules. There is an
external application that the user runs. I would like to run the application
but make it look like it's part of my application. It's basically contained
in my application.

The SetParent works but requires a "desired" pause so the external
application can load to a certain point for the SetParent to work properly.

Make sense now?

Thanks,

Y




Willy Denoyette said:
Yoshi said:
Hey Willy...

Here is a quick example:

[DllImport("user32.dll")]

static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

System.Diagnostics.ProcessStartInfo si = new
System.Diagnostics.ProcessStartInfo();
si.FileName = "winword.exe";


si.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;


System.Diagnostics.Process p = System.Diagnostics.Process.Start(si);


p.EnableRaisingEvents = true;

p.Exited += new EventHandler(OnHasExited);

SetParent(p.MainWindowHandle, this.Handle);


You could use Process.WaitForInputIdle to make sure the process has
started and it's message loop is spinning.
BUT, as I said before what you are doing here :
SetParent(p.MainWindowHandle, this.Handle);
is wrong. SetParent takes two handles belonging to the same application,
in your case they belong to different applications. Did you ever checked
the return value? I guess you are not.
What exactly are you trying to achieve?

Willy.
 
Yoshi said:
I am developing an application that contains certain modules. There is an
external application that the user runs. I would like to run the
application but make it look like it's part of my application. It's
basically contained in my application.

The SetParent works but requires a "desired" pause so the external
application can load to a certain point for the SetParent to work
properly.

Make sense now?

Here's what you can do, but again it's not supposed you do this, read the
remarks paragraph in the SetParent documentation on MSDN and you will see
both handles must belong to the same application. It's not because something
"seems" to work that it's correct to assume it will do all the time under
all circumstances.

if (p.WaitForInputIdle(10000)) // wait max. 10 sec's
SetParent(p.MainWindowHandle, this.Handle);

else

.... // something took to many time here



Willy.
 
Back
Top