Programming/C#
sendmessage in C#
blueasa
2010. 12. 27. 01:42
[DllImport("user32.dll", SetLastError = true)] | |
static extern IntPtr FindWindow(string lpClassName, string lpWindowName); | |
[DllImport("user32.dll", SetLastError = true)] | |
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); | |
[DllImport("user32.dll")] | |
private static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, Int32 wParam, Int32 lParam); | |
static void Main(string[] args) | |
{ | |
// Use this to send key strokes | |
const int WM_KEYDOWN = 0x100; | |
IntPtr windowHandle = FindWindow("NOTEPAD", null); | |
IntPtr editHandle = FindWindowEx(windowHandle, IntPtr.Zero, "EDIT", null); | |
PostMessage(editHandle, WM_KEYDOWN, 'A', 0); | |
Console.ReadKey(); | |
} |
[DllImport("user32.dll")] | |
public static extern int SendMessage(int hWnd, int msg, int wParam, [MarshalAs(UnmanagedType.LPStr)] string lParam); | |
[DllImport("user32.dll", SetLastError = true)] | |
static extern IntPtr FindWindow(string lpClassName, string lpWindowName); | |
[DllImport("user32.dll", SetLastError = true)] | |
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); | |
static void Main(string[] args) | |
{ | |
const int WM_SETTEXT = 0x0C; | |
IntPtr windowHandle = FindWindow("NOTEPAD", null); | |
IntPtr editHandle = FindWindowEx(windowHandle, IntPtr.Zero, "EDIT", null); | |
string textToSendToFile = "Input here your text"; | |
SendMessage((int)editHandle, WM_SETTEXT, 0, textToSendToFile); | |
Console.ReadKey(); | |
} |
반응형