1

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

2 Answers 2

1

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.

6
  • I found: const UInt32 SWP_NOSENDCHANGING = 0x0400; /* Don't send WM_WINDOWPOSCHANGING */ Adding it to SetWindowPos didn't change anything, though. I take it that SWP_DRAWFRAME is the crucial part of the function that needs to be executed in order to update the frame? I might try sending only that thru SendMessage without SetWindowPos...
    – JStrange
    May 31, 2010 at 12:47
  • Hm, seems like MoveWindow is also sending WM_WINDOWPOSCHANGING, so if it really is the case that the game is intercepting the message, is my only chance to remove the border manually (via some painting functions)?
    – JStrange
    May 31, 2010 at 12:53
  • Almost any function that is capable of moving or resizing or changing the visibility or z-order of a window ultimately is a wrapper around SetWindowPos. SetWindowPos sends WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED - which are handled by the default window procedure that resends them as WM_GETMINMAXINFO, WM_MOVE and WM_SIZE messages. I expect that the game is handling at least one of these messages to reset its frame styles. If the changing message is being inhibited correctly, then its in one of the changed notifications. May 31, 2010 at 13:31
  • Could you point me to some material I should read up on before trying to tackle this problem? I'm fairly new to C# and Win32 APi.
    – JStrange
    May 31, 2010 at 15:54
  • I don't think you can succeed here. It seems that the game in question is aggressively restoring the window's non client state to what it thinks the state should be. To convince this program to honor your styles you'd need a library like detours to physically hook its attempts to set its non client styles and modify them how YOU want. May 31, 2010 at 18:07
0

You should use Spy++ to investigate the game's window structure.

1
  • I use Winspector Spy and maybe I'm just dumb, but I don't see anything of interest. If I use the WS's feature of editing the window styles it ends exactly the same way as with my app... nothing happens. Here's a pic from WS: i47.tinypic.com/iypl5g.jpg
    – JStrange
    May 30, 2010 at 23:45

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.