views:

30

answers:

2

Hi I'm trying to show hidden form in process1 from another one was called by :

Process.Start(@"F:\MyOtherFormPath\MyOtherForm.exe",this.Handle.ToInt32());

As you can see i passed the handle number of the hidden form ,which i'm calling the "MyOtherForm" from, and i used this number to get a handle and show the hidden form from my "MyOtherForm" like this :

Form newFrm = Form.FromHandle(new IntPtr(long.Parse(handleNumberOfMyHiddenForm)));
newFrm.show();

But it didn't work, any way to do this .

P.S: it didn't throw any exception .

thanx in advanced ..

A: 

The handle that you pass is not valid in the other process.

In order to accomplish what you would like to do you will have to use some way of inter-process communication. In .NET this can be handled e.g. using WCF or .NET Remoting.

Another way to control other application would be using P/Invoke or user interface automation (System.Windows.Automation namespace).

0xA3
thanx @divo but can you plz give a simple example to show me how to use it .?? :)
Al0NE
+1  A: 

What you are trying to do is not possible, it is a miracle that you didn't get an exception. A window handle is valid between processes, as long as they run in the same session. But Control.FromHandle() can only find controls that were created in the process from which it is called. In your case it should return null.

Making the form in the other process visible is actually possible, you'll have to P/Invoke ShowWindow() using SW_SHOWNORMAL. Visit pinvoke.net for the declaration. Use Handle.ToInt64() so it will work properly on 64-bit operating systems.

Hans Passant