I develop on Windows 10.
I want to move and resize an external application. I tried to make it work first with notepad and calculator. But, whatever I do the notepad/cal do not move or resize. I tried using SetWindowPos
, UpdateWindow
and MoveWindow
but nothing worked. I debugged the code, and the inner part of the foreach
does get executed.
I tried to run it as admin as suggested here, but it didn't help.
static void foo()
{
foreach (var p in Process.GetProcesses().Where(p => p.ProcessName.ToLower().Contains("calculatorapp")))
{
SetWindowPos(p.Handle, HWND.TopMost, 10, 10, 100, 300, (uint)(SWP.SHOWWINDOW));
int err = Marshal.GetLastWin32Error();
UpdateWindow(p.Handle);
//SetWindowPos(p.Handle, 0, 0, 250, 250, true);
MoveWindow(p.Handle, 0, 0, 250, 250, true);
}
}
Just as Hans Passant said, you need a window handle like this.
I used SPY++ here to get the window handle of notepad. Then used
Setwindowpos
to move the notepad to a new location and get the new size.