Program that opens Notepad in the background [closed]

1

I need to make a program that, when the user presses a button, the program opens the notepad and inserts a message previously programmed by me in the code. How could I have the part of the program insert the text of the message in Notepad?

    
asked by anonymous 16.10.2015 / 17:27

1 answer

3

The following code opens Notepad and inserts a text inside:

[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);

static void AbrirBlocoDeNotasComTexto(string texto)
{
    ProcessStartInfo startInfo = new ProcessStartInfo("notepad");
    startInfo.UseShellExecute = false;

    Process notepad = Process.Start(startInfo);
    notepad.WaitForInputIdle();

    IntPtr child = FindWindowEx(notepad.MainWindowHandle, new IntPtr(0), null, null);
    SendMessage(child, 0x000c, 0, texto);
}

I pulled it out .

    
16.10.2015 / 17:32