sendmessage in C#
Programming/C# / 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(); | |
| } |
반응형
'Programming > C#' 카테고리의 다른 글
| C# TAB, 방향키, Control, Alt, Shift Key 입력 처리 (2) | 2011.01.20 |
|---|---|
| [펌] 외부 응용프로그램 실행하기 (Process.Start 메서드) - CMD (0) | 2011.01.13 |
| C# SendMessage Keypress (1) | 2010.12.26 |
| 윈폼에서 토글 버튼(Make Toggle Button for WinForm) 만들기 (2) | 2010.12.14 |
| Microsoft Win32 to Microsoft .NET Framework API Map (0) | 2010.12.10 |
