Reputation: 373
I'm quite new to C# and is faced with an issue. I wish to manipulate a window (resize, move) that I dynamically created through:
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 handle by app.MainWindowHandle
but I can't obtain the form by Control.FromHandle(app.MainWindowHandle)
. Hence, I can't set the new location nor size of this notepad.
Any idea on how do I manipulate the window then? Thanks in advance!
Upvotes: 4
Views: 1437
Reputation: 14700
Notepad is a Win32 application, not a .NET Form. That's why you can't get a Control
from it - it's not a control!
What you CAN do with the window handle is pass it along to Win32 functions that can manipulate Win32 windows. There's a whole host of them such as SetWindowPos
to set window location (and see this SO question on using it from C#).
See more reference on Window functions on MSDN, and use PInvoke.net as reference for calling these Win32 methods from C#.
Upvotes: 4