Last active
June 23, 2020 21:37
-
-
Save IvanStoychev/ac5b877080502cfe363b04fd9cbcf987 to your computer and use it in GitHub Desktop.
C# code samples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a collection of useful pieces of C# code that are ready to be used as they are. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The following two DllImports are required for the "ExportToNotepad" method to work. | |
[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); | |
/// <summary> | |
/// Opens notepad.exe and send the given text to it. | |
/// </summary> | |
/// <param name="text">The text to send to notepad.exe.</param> | |
void ExportToNotepad(string text) | |
{ | |
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, text); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment