Live Chat Icon For mobile
Live Chat Icon

How do I maximize my main window

Platform: WinForms| Category: Win32

To maximize the main window, you can get the handle of the main window in the new process, and then send a SC_MAXIMIZE system command message to it. You can get the handle through the Process.MainWindowHandle property. To send a message you should use the DllImportAttribute attribute to import the API function. This is a sample code:

public class WinAPI
	public const int WM_SYSCOMMAND = 0x0112;
	public const int SC_MAXIMIZE = 0xF030;

	[DllImportAttribute ('user32.dll')]
	public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

Process p = new Process();
p.StartInfo.FileName = @'D:\Program Files\test.exe';
WinAPI.SendMessage(p.MainWindowHandle, WinAPI.WM_SYSCOMMAND, WinAPI.SC_MAXIMIZE,0);

(from on microsoft.public.dotnet.framework.windowsforms)

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.