I am wondering how can I restore application window to specific location on the screen.
I did managed to write some code, but somehow I do have a feeling that there must be and easier and more efficient way to do it programaticaly... as my current version is restoring window first and then moving it to required location. I would like to restore it without being forced to move it afterwards.
my code:
public void Send()
{
if (Process.GetProcessesByName("report").Any())
{
Process proc = Process.GetProcessesByName("report").First();
if (proc != null)
{
IntPtr pointer = proc.MainWindowHandle;
SetForegroundWindow(pointer);
SendMessage(pointer, WM_SYSCOMMAND, SC_RESTORE, 0);
Program.MoveWindow(pointer, 0, 0, 100, 100, true);
}
}
// do something
}
of course this is followed with :
[DllImport("user32.dll")]
static extern int SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
internal static extern bool SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam, Int32 lParam);
static Int32 WM_SYSCOMMAND = 0x0112;
static Int32 SC_RESTORE = 0xF120;
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
I would be very grateful for further solutions and explanation.