求高手:WPF窗体中加载ActiveX控件总是显示在最前的问题!!!!!
mrisw 2011-05-26 02:24:29 没有WPF板块?发SilverLight里也行吧?
求助:(求实例代码,100分只给实例代码。)
WPF窗体中通过WinFormHost加载的ActiveX控件(VC6开发)总是显示在WPF控件的前面,ZIndex对这个不起作用。
原因是WPF Window通过DirectX,OpenGL绘制,WinFormHost以及WinFrom通过GDI绘制,且是在另一个hWnd,且总是先绘制WPF的Control,再绘制WinFormHost的控件。
有没有办法把WPF控件放在WinFormHost控件之前呢?
(可否通过SetWindowPos这类的API来强行把WPF控件设置到TOP?怎样获得WPF控件的hWnd呢?)
例子程序如下:
<Window x:Class="AxOrderTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="600" Width="1000" Loaded="Window_Loaded">
<Grid Name="LayoutRoot">
<TextBlock Name="m_Info" TextWrapping="Wrap" Height="193" HorizontalAlignment="Left" Margin="794,190,0,0" Text="" VerticalAlignment="Top" Width="184" FontSize="14" />
<Button Content="this is a WPF control" Height="67" HorizontalAlignment="Left" Margin="681,87,0,0" Name="button1" VerticalAlignment="Top" Width="297" Click="button1_Click" />
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms.Integration;
using AxTest;
namespace AxOrderTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
WindowsFormsHost wfh = new WindowsFormsHost();
AcroPDFReader thePDFReader = new AcroPDFReader();
wfh.Child = thePDFReader;
wfh.VerticalAlignment = VerticalAlignment.Top;
wfh.HorizontalAlignment = HorizontalAlignment.Left;
wfh.Width = 780;
wfh.Height = 550;
wfh.Opacity = 0.7;
thePDFReader.OpenPDFFile("C:\\CRF.pdf");
LayoutRoot.Children.Add(wfh);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
m_Info.Text = "问题是:\n";
m_Info.Text += "怎样把 button1 放到 thePDFReader 的前面?";
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AxTest
{
public partial class AcroPDFReader : UserControl
{
public AcroPDFReader()
{
InitializeComponent();
}
public void OpenPDFFile(string strFileName)
{
m_axAcroPDF.LoadFile(strFileName);
}
}
}