如何让HwndSource永远处于最上端(On Topmost)
我们项目的主窗口为MFC 的MDI窗口,而上面的内容都是用DirectX渲染的。 现在想要支持文字编辑的功能。 于是我想到了用WPF的HwndSource上放TextBox的方案,但是最终发现这个TextBox经常被我们自己渲染的场景所覆盖。而用Spy++发现这个弹出的窗口确实有Topmost样式的。
生产HwndSource代码如下:
//attach textbox to client windowHwndSourceParameters 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();