Well, all that is working completely fine now. It even grabs the right window I'm looking for if there are multiple windows.
But, there is something going on with the other API stuff that I can't quite put my finger on. This is the current code I've got :
Code:
int GWL_STYLE = -16;
long WS_BORDER = -0x800000;
long WS_DLGFRAME = -0x400000;
long WS_THICKFRAME = -0x40000;
long WS_SIZEBOX = -0x00040000;
long WS_SYSMENU = -0x00080000;
long WS_POPUP = -0x80000000;
uint SWP_NOMOVE = 0x0002;
uint SWP_NOZORDER = 0x0004;
uint SWP_FRAMECHANGED = 0x0020; /* The frame changed: send WM_NCCALCSIZE */
long WS_CAPTION = WS_BORDER | WS_DLGFRAME;
IntPtr hWndPtr = FindWindow(null, y.MainWindowTitle);
Rectangle ScreenSize = myScreens[x.Monitor - 1].Bounds;
long code = GetWindowLong(hWndPtr, GWL_STYLE);
code= (code & WS_CAPTION & WS_BORDER & WS_THICKFRAME & WS_SIZEBOX & WS_SYSMENU) | WS_POPUP;
// this line does the proper moving!
MoveWindow(hWndPtr, ScreenSize.Left, ScreenSize.Top, ScreenSize.Right, ScreenSize.Bottom, 1);
SetWindowLong(hWndPtr, GWL_STYLE, (int)code);
SetWindowPos(hWndPtr, new IntPtr(-1), ScreenSize.Left, ScreenSize.Top, ScreenSize.Right, ScreenSize.Bottom, SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED);
It all works as it should. It grabs the correct window, gets the correct info for the destination screen (multi-monitor stuff), gets the window's style information and modifies it. MoveWindow moves the window to the selected monitor, setwindowlong removes the border stuff, and setwindowpos makes it fill that monitor. So you have a pseudo full screen.
The strange thing is it doesn't work correctly the first time it moves the window. The contained controls in the window do not resize to fit the new dimensions (obvious by a test window mdi-child control not going all the way to the right and the bottom, by the same size as the now hidden borders). Except when you shift the window to another monitor selection, then it's perfect. But even looping this code twice to try and force it again doesn't work (well, it does, but by god is it ugly...).
So um... Why won't it work first time round, and how do I make it work?