开发者

Launch WPF executable and set parent?

开发者 https://www.devze.com 2023-04-11 02:12 出处:网络
I have a WPF executable and 开发者_StackOverflow中文版I want another program to launch it and set this launching program as the parent windows of my WPF executable (The main purpose is that when the l

I have a WPF executable and 开发者_StackOverflow中文版I want another program to launch it and set this launching program as the parent windows of my WPF executable (The main purpose is that when the launching program is closed the WPF executable is also shut down). I thought I could make it like this: I pass the Hwnd as one command line parameter (as integer-string), and I can call the SetParent or whatever function inside my WPF executable code to specify the parent. However, I can't make it work. Can anybody tell me how to do that, or any other way to do that? Thanks!


You can't. Window handles are per-process.

Besides, you wouldn't want to. It's problematic enough to have a parent window in another thread -- that causes the message queues of the two threads to become attached, i.e., they effetively share the same message queue from then on. So now if either thread locks up, or does some lengthy processing, both threads are frozen. (And there's no way to later detach the message queues, as far as I'm aware.) Imagine trying to extend this cross-process.

If you must start some new code and use an existing window as a parent, you can't go cross-process. You would have to load the WPF code into your process and call a method in it, passing your parent window as a parameter. The simplest way to load that code into your process would be to change your WPF application to a class library (.dll), and either add a reference to that .dll, or load it dynamically using Reflection.


As @Joe White said you cannot achieve this straightaway ... I think I can "guess" what you are getting at ....

You probably have a WinForm MDI parent (its exe already) and you want to launch another WPF window (another exe) as its child. Am I correct?

Hmmmm then you would have to create a new WinForm child window with WinFormWPFHostApp in it and then refer the WPF assemblies to this project and try to host the Content of the MainWindow from that other WPF application.

refer this article...

0

精彩评论

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

关注公众号