开发者

How can I show Form in process1 from Form in process2?

I'm trying to show hidden form in process1 from another one was called 开发者_C百科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 ..


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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜