Search code examples
c#winapiprotocolsalphasetwindowlong

Removing WS_BORDER and WS_CAPTION from windows styles doesn't work


I created a small app in C# that removes border and caption from window, then it sets size to the user's resolution and centers it. It's a utility for me to use when I want to play games in windowed mode without being annoyed by the borders. Everything works fine with most games, but I tried to use it on a recently released game Alpha Protocol and it doesn't work. I could almost say that the game reverts my changes, but I'm not sure how to tell if that's true or not. I'm using imported API functions MoveWindow, SetWindowLong and SetWindowPos.

Snippet:

Win32.MoveWindow(hWnd, 0, 0, Convert.ToInt32(sizeXText.Text), Convert.ToInt32(sizeYText.Text), true);
Win32.SetWindowLong(hWnd, GWL_STYLE, Win32.GetWindowLong(hWnd, GWL_STYLE) & ~WS_CAPTION & ~WS_BORDER);
Win32.SetWindowPos(hWnd, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_DRAWFRAME);

Solution

  • Every time SetWindowPos is called it sends a message: WM_WINDOWPOSCHANGING to the window with a writable copy of the SetWindowPos parameters. This gives the window the chance to validate and change the parameters. Many window's automatically react to repositioning and sizing to "smartly" manage their non-client decorations - which I guess is what is happening here. The OnWindowPosChanging code is re-setting the non client decorations just before the DRAWFRAME is handled.