经过一番研究,我能够找到解决方案。
解决方案
在调用 SetParent 之前,我们应该使用 Windows API 的 SetWindowLongPtr 更新窗口样式。最终代码如下
long style = WinAPI.GetWindowLongPtr(new HandleRef(this,console.MainWindowHandle), WinAPIConstants.GWL_STYLE).ToInt64();
style= style & ~(WinAPIConstants.WS_CAPTION |
WinAPIConstants.WS_BORDER |
WinAPIConstants.WS_DLGFRAME);
IntPtr styleValue = new IntPtr(style);
Rectangle displayRectangle = newTab.DisplayRectangle;
// Removing the title bar and border.
WinAPI.SetWindowLongPtr(new HandleRef( this,console.MainWindowHandle),
WinAPIConstants.GWL_STYLE, styleValue);
style = WinAPI.GetWindowLongPtr(new HandleRef(this, console.MainWindowHandle), WinAPIConstants.GWL_STYLE).ToInt64();
style &= ~WinAPIConstants.WS_POPUP;
style |= WinAPIConstants.WS_CHILD;
styleValue = new IntPtr(style);
// Setting window to be child of current application and the popup behaviour of window is removed.
WinAPI.SetWindowLongPtr(new HandleRef(this, console.MainWindowHandle), WinAPIConstants.GWL_STYLE, styleValue);
// Attach the console to the tab.
WinAPI.SetParent(console.MainWindowHandle, newTab.Handle);
谢谢
Vipin Kumar Mallaya。