Been a while since I did any program so alil rusty. I was researching on code to maximize and minimize other applications. So I found something basic and here is what I have, slightly modified from the original. It wanted me to generate some FindWindow method which I did. Now everything looks good and I tried to run it, getting a message. Not sure where to go from here. The original thread where I found it didn't mention this.
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);
static void Main(string[] args)
{
// 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);
}
}
private static IntPtr FindWindow(string p, string p_2)
{
throw new NotImplementedException();
}
First, with your method FindWindow()
, when a method has a throw you need to catch it in the method where it is invoked in this case the Main()
.
Now NotImplementedExceptionis a class, here I post you the inheritance hierarchy
As say the error, you just need to implement the method and delete de line: `throw new NotImplementedException();
Finally I post an implementation option, just need the title of the in the window application.
public static IntPtr FindWindow(string titleName)
{
Process[] pros = Process.GetProcesses(".");
foreach (Process p in pros)
if (p.MainWindowTitle.ToUpper().Contains(titleName.ToUpper()))
return p.MainWindowHandle;
return new IntPtr();
}
By the way, here is another question about Maximize/Minimize other applications
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With