views:

193

answers:

2

Hello, 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);
+1  A: 

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

SLaks
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: http://i47.tinypic.com/iypl5g.jpg
Jonathan Strange
A: 

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.

Chris Becke
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...
Jonathan Strange
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)?
Jonathan Strange
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.
Chris Becke
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.
Jonathan Strange
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.
Chris Becke
Thanks for your answers. I'll get back to this later when I feel more confident with Win32 API and C# in general just for the sake of solving it, since my app was supposed to be simple and the effort exceeds profit in this case.
Jonathan Strange