Program that opens Notepad in the background

Asked

Viewed 686 times

1

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

  • 4

    So put what you’ve done and what problem you’re facing.

1 answer

3

The following code opens the 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 took it from here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.