API C# - how to get the handle of the textbox where the caret is in another program?
i w开发者_JAVA技巧ant to get the handle of the textbox where the caret is in, in another program. all i can find is how to get the list of the controls in a window with "EnumChildWindows", and then to search for "edit" control.. (and it doesn't work for all the program that have textbox). i have no idea how to find the one that the caret is in and the user is writing in. i really got stuck with it.. :( thanx alot, Shiran.
You'll need to jump through several pinvoke hoops. Start with GetForegroundWindow() to get the handle of the active toplevel window. Then GetThreadWindowProcessId() to obtain the ID of the thread that owns that window. Then finally GetGUIThreadInfo(), it returns a bunch of into about the windows owned by the thread. The GUITHREADINFO.hwndCaret member gives you the handle to the window that owns the caret. It doesn't have to be a text box btw.
Visit pinvoke.net for the declarations you'll need.
精彩评论