日期:2014-05-18  浏览次数:20974 次

如何让HwndSource永远处于最上端(On Topmost)
我们项目的主窗口为MFC 的MDI窗口,而上面的内容都是用DirectX渲染的。 现在想要支持文字编辑的功能。 于是我想到了用WPF的HwndSource上放TextBox的方案,但是最终发现这个TextBox经常被我们自己渲染的场景所覆盖。而用Spy++发现这个弹出的窗口确实有Topmost样式的。
生产HwndSource代码如下:
C# code
//attach textbox to client window
HwndSourceParameters parameters = new HwndSourceParameters(/*MSG0*/"Parameters", rec.Width, rec.Height);
parameters.ParentWindow = parentIntPtr;
parameters.SetPosition(rec.Location.X, rec.Location.Y);
parameters.WindowClassStyle = 0;
parameters.WindowStyle = (int)(WindowStyles.WS_CHILD | WindowStyles.WS_VISIBLE | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_MAXIMIZEBOX);
parameters.ExtendedWindowStyle = (int)(WindowExStyles.WS_EX_TOPMOST | WindowExStyles.WS_EX_TRANSPARENT);

mHwndSource = new HwndSource(parameters);
if (mHwndSource == null)
    return null; ;

mHwndSource.RootVisual = mTextBox;
mTextBox.CaptureMouse();



不知道为啥TextBox能被遮盖,是不是我哪里属性没设好,或者我们的程序用DirectX渲染跟WPF渲染有冲突?两者渲染时有重叠(overlap)?
(CSDN不太会传图,有兴趣的同学可以查看我的blog,上面有详细的症状描述图:http://www.cnblogs.com/anders06/archive/2009/02/27/1399334.html)

或者有没有其他的方案,只要能支持文字编辑,并且编辑时能永远处于最上层。

万分感谢!


------解决方案--------------------
帮你顶
------解决方案--------------------
up
------解决方案--------------------
潜力贴,给楼主顶了。
------解决方案--------------------
潜力贴,顶一个