2

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.

enter image description here

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();
}
diiN__________
  • 7,393
  • 6
  • 42
  • 69
KuyaBraye
  • 55
  • 1
  • 3
  • 8

1 Answers1

2

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

  1. System.Object
  2. System.Exception
  3. System.SystemException
  4. System.NotImplementedException

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

Community
  • 1
  • 1
Randall Sandoval
  • 237
  • 1
  • 6
  • 21