cabgef
cabgef

Reputation: 1398

How do I turn off WS_CAPTION style of a window (using user32.dll)?

I am embedding a 3rd party app into a panel on a C# Windows form (using SetParent from user32.dll). I need to then turn off the title bar window style WS_CAPTION so that it looks like a part of the hosting application.

How do I change a window's style to accomplish this?

For sake of example, say _hWnd is the handle of the application to embed.

Upvotes: 2

Views: 4515

Answers (4)

Pierre Arnaud
Pierre Arnaud

Reputation: 10537

Use GetWindowLong to retrieve the window style, mask the WS_CAPTION bits and then set the updated style using SetWindowLong:

var style = GetWindowLong(_hWnd, GWL_STYLE);
SetWindowLong(_hWnd, GWL_STYLE, style & ~WS_CAPTION);

and with following helper code:

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);

Upvotes: 0

KV Prajapati
KV Prajapati

Reputation: 94653

Take look at WindowInterceptor

Upvotes: 2

Filip Navara
Filip Navara

Reputation: 4828

SetWindowLong(_hWnd, GWL_STYLE, GetWindowLong(_hWnd, GWL_STYLE) & ~WS_CAPTION);

Upvotes: 2

John Lockwood
John Lockwood

Reputation: 3875

If memory serves, you might be able to do a GetWindowLong on the style, |= ~ WS_CAPTION on that value, and then SetWindowLong. See those APIs in MSDN.

Also see: http://www.codeguru.com/forum/showthread.php?t=352963

Upvotes: 3

Related Questions