Manipulate windows created by a process

I am new to C # and ran into a problem. I want to manipulate the window (resize, move) with which I dynamically created:

Process app = new Process(); app.StartInfo.FileName = "notepad.exe"; //just an example, app.Start(); //it will be more than just notepad 

I understand that I can get the descriptor app.MainWindowHandle , but I can't get the form Control.FromHandle(app.MainWindowHandle) . Therefore, I cannot set a new location or size for this notebook.

Any idea on how I can manipulate the window? Thanks in advance!

+4
source share
1 answer

Notepad is a Win32 application, not a .NET form. That is why you cannot get Control from it - it is not control!

What you can do with a window handle is to pass it along with Win32 functions that can work with Win32 windows. There are many of them, such as SetWindowPos , to set the location of the window (and see this SO question about using it with C #).

Read more about Window Functions on MSDN and use PInvoke.net as a reference to call these Win32 methods from C #.

+4
source

Source: https://habr.com/ru/post/1446936/


All Articles