调用win32时隐藏WPF窗口
本文关键字:WPF 窗口 隐藏 win32 调用 | 更新日期: 2023-09-27 18:02:02
我有一个win32应用程序(用Delphi编写),它调用了一些WPF窗口。这些WPF窗口调用win32 Delphi项目中的其他窗口(以重用一些代码)。当我这样做时,它会隐藏(发送到后台)WPF窗口。
这些win32窗口是在COM dll中。
有办法避免这种行为吗?
我需要这样的东西:
+--------------------------------------------------
| win32
|
|
|
| +-------------------------------------+
| | wpf |
| | |
| | |
| | |
| | +--------------------+ |
| | | win32 | |
| +--| |-------------+
| | |
| +--------------------+
|
|
但是我得到:
+--------------------------------------------------
| win32
|
|
|
|
|
|
|
|
| +--------------------+
| | win32 |
| | |
| | |
| +--------------------+
|
|
在delphi主项目中,我使用了"CreateOleObject"来访问wpf代码。在WPF中,使用"ShowDialog()"命令打开窗口。同样,在WPF中,我调用delphi,使用互操作引用到我的win32 dll。
好的,使用的代码如下:
Delphi主要应用:
var dll : OleVariant;
begin
dll := CreateOleObject("MyDllinCSharp.ClassName");
dll.DoSomething(...);
此时,WPF Windows出现在前面:
wpf代码:var form = new MyForm();
form.ShowDialog();
在xaml中,没有什么重要的,只有一个基本窗口:
<Window x:Class="MyForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Reverter" Height="432" Width="500" WindowStartupLocation="CenterScreen">
现在在c#中,我将调用delphi DLL,在我引用c#项目中的COM DLL后:
var dll = Delphi.CreateInstance("delphidll", "Interfacename") as IMyProcess;
dll.DoSomethingInDelphi(....);
我得到了这个工作,在WPF元素中托管Win32窗口,就像下面的演练:
http://msdn.microsoft.com/en-us/library/ms752055.aspx现在我有了这样的内容:
+--------------------------------------------------
| win32
|
|
|
| +-------------------------------------+
| | wpf |
| | |
| | |
| | -wpf------------------ |
| | |+--------------------+| |
| | || win32 || |
| +-|| ||------------+
| || ||
| |+--------------------+|
| ----------------------
|