Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, April 8, 2009 7:32 AM
How do I maximize/minimize applications programmatically in C#?
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
All replies (1)
Wednesday, April 8, 2009 7:33 AM âś…Answered
Basically, we can use the Windows API ShowWindowAsync function to normalize/maximize/minimize another application. Please refer to the code snippet below for an example:
Code Snippet:
private const int SW_SHOWNORMAL = 1;
private const int SW_SHOWMINIMIZED = 2;
private const int SW_SHOWMAXIMIZED = 3;
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
private void button1_Click(object sender, EventArgs e)
{
// retrieve Notepad main window handle
IntPtr hWnd = FindWindow("Notepad", "Untitled - Notepad");
if (!hWnd.Equals(IntPtr.Zero))
{
// SW_SHOWMAXIMIZED to maximize the window
// SW_SHOWMINIMIZED to minimize the window
// SW_SHOWNORMAL to make the window be normal size
ShowWindowAsync(hWnd, SW_SHOWMAXIMIZED);
}
}
Related thread:
http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/f8dc9aec-c53f-41cf-a376-aa3d88dda1d9
** **
For more FAQ about Visual C# General, please see Visual C# General FAQ
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.