Maximize a process window

  • Thread starter Thread starter Sanjay Seshasainam
  • Start date Start date
S

Sanjay Seshasainam

How can I maximize a process window

I am using the Process class in System.Diagnostics. I can
identify the specific process I want using the window
title after that I want to maximize the window. I can get
the handle for the window using MainWindowHandle how do I
maximize the window ?

Thanks,
Sanjay

Process[] myProcess;
myProcess = Process.GetProcessesByName("process_name");

foreach (System.Diagnostics.Process instance in
myProcess)
{
string windowTitle = instance.MainWindowTitle;
if ( windowTitle == "WINDOW_TITLE" )
{
// How can I maximize the window here ??
void *windowHandle =
instance.MainWindowHandle.ToPointer();
}
}
 
Hi,

Call the SendMessage API function through P/Invoke, sending the WM_MAXIMIZE
message to the main process window. As you already have the MainWindowHandle
(you don't need to get a pointer from it, by the way), the rest is pretty
straightforward:

1) Declare the SendMessage prototype with the DllImport attribute (please
refer to MSDN for details on this)
2) Find out the numeric value of the WM_MAXIMIZE constant (look it up in the
winuser.h file. You should have one if you have Visual C++ installed)
3) Call the declared SendMessage method passing necessary parameters.
 
Back
Top