Search code examples
.netwindows-process

Maximize another process' Window in .NET


I have a handle on another process' main window in .net (proc.MainWindowHandle). How do I maximize the window inside of .net?


Solution

  • You can pinvoke to ShowWindow with SW_SHOWMAXIMIZED to maximize the window.

    Pinvoke.net has an entry for ShowWindow here.

    For example,

    // Pinvoke declaration for ShowWindow
    private const int SW_SHOWMAXIMIZED = 3;
    
    [DllImport("user32.dll")]
    static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
    
    // Sample usage
    ShowWindow(proc.MainWindowHandle, SW_SHOWMAXIMIZED);