How do I write to another window through a C# form [modified]
-
Hello everyone, I'm making a program, but I'm (obviously) stuck with a problem. I want to write a message to the current topscreen through a C# application. For instance: when you open Microsoft Word and you type 'hello' it will double the word like this 'hheelllloo'. The application allready knows when a key is pushed, now the only thing that will have to be done is write a message to the current top window (like word or notepad or whatever window is open and where you are typing in). I guess that this is possible with something like PostMessage and GetTopWindow. But it won't work. Can anybody tell me what I'm doing wrong? Or can someone tell me what will work? Thank you allready. This is what I have:
\[DllImport("user32.dll")\] public static extern int GetTopWindow(int hwnd); \[DllImport("user32.dll")\] public static extern int PostMessage(int hWnd, uint Msg, int wParam, uint lParam); //..code const int VK\_KEY = 0x41; const int WM\_CHAR = 0x0102; int WindowToFind = GetTopWindow(0); Console.WriteLine(WindowToFind); int result = PostMessage(WindowToFind, WM\_CHAR, VK\_KEY, 0); Console.WriteLine(result);
The output for result is always 1. The output for WindowToFind is different, sometimes it gives the same value at different windows. Sometimes a different value. One of the outcome of WindowToFind is 131138 edit: Allright... finaly I found out the anwser to my problem (after hours of searching :P). I just had to use the SendKeys class.
SendKeys.SendWait("");
modified on Wednesday, March 5, 2008 5:42 AM
-
Hello everyone, I'm making a program, but I'm (obviously) stuck with a problem. I want to write a message to the current topscreen through a C# application. For instance: when you open Microsoft Word and you type 'hello' it will double the word like this 'hheelllloo'. The application allready knows when a key is pushed, now the only thing that will have to be done is write a message to the current top window (like word or notepad or whatever window is open and where you are typing in). I guess that this is possible with something like PostMessage and GetTopWindow. But it won't work. Can anybody tell me what I'm doing wrong? Or can someone tell me what will work? Thank you allready. This is what I have:
\[DllImport("user32.dll")\] public static extern int GetTopWindow(int hwnd); \[DllImport("user32.dll")\] public static extern int PostMessage(int hWnd, uint Msg, int wParam, uint lParam); //..code const int VK\_KEY = 0x41; const int WM\_CHAR = 0x0102; int WindowToFind = GetTopWindow(0); Console.WriteLine(WindowToFind); int result = PostMessage(WindowToFind, WM\_CHAR, VK\_KEY, 0); Console.WriteLine(result);
The output for result is always 1. The output for WindowToFind is different, sometimes it gives the same value at different windows. Sometimes a different value. One of the outcome of WindowToFind is 131138 edit: Allright... finaly I found out the anwser to my problem (after hours of searching :P). I just had to use the SendKeys class.
SendKeys.SendWait("");
modified on Wednesday, March 5, 2008 5:42 AM
maybe
GetDlgItem
andGetWindowText
orSetWindowText
can help ? just an idea.V.
Stop smoking so you can: Enjoy longer the money you save. Moviereview Archive