我将第 3 方应用程序嵌入到 C# Windows 窗体上的面板中(使用SetParent
来自 user32.dll)。然后我需要关闭标题栏窗口样式WS_CAPTION
,使其看起来像托管应用程序的一部分。
如何更改窗口的样式以实现此目的?
例如,说_hWnd
是要嵌入的应用程序的句柄。
如果没有记错,您可以对样式执行 GetWindowLong,对该值执行 |= ~ WS_CAPTION,然后执行 SetWindowLong。请参阅 MSDN 中的那些 API。
SetWindowLong (_hWnd, GWL_STYLE, GetWindowLong (_hWnd, GWL_STYLE) & ~WS_CAPTION);
使用GetWindowLong检索窗口样式,屏蔽WS_CAPTION
位,然后使用SetWindowLong设置更新的样式:
var style = GetWindowLong(_hWnd, GWL_STYLE);
SetWindowLong(_hWnd, GWL_STYLE, style & ~WS_CAPTION);
并使用以下帮助代码:
const int GWL_STYLE = -16;
const int WS_CAPTION = 0x00C00000;
[DllImport ("user32")]
private static extern int GetWindowLong(System.IntPtr hwnd, int nIndex);
[DllImport ("user32")]
private static extern int SetWindowLong(System.IntPtr hwnd, int index, int newLong);