I have to detect when a combobox from an application I have not source code, has changed. The idea is to hook an event to this control, and when the event fires, get the selected value of the control. I have googled but I just have found how to hook with a window (How to hook on a window), when the header text change. I can get the handle of the control (FindWindowEx) but, I have no idea how to hook an event to the control, please guys if any can help me with this.
Asked
Active
Viewed 2,077 times
1
-
not sure if this link will help but here is a starting point you can look at http://easyhook.codeplex.com/ l – MethodMan Aug 14 '12 at 21:57
-
Also, this Google Search: [Hooking API Calls in other Applications](https://www.google.com/search?q=how%20to%20hook%20an%20event%20of%20external%20application) – MethodMan Aug 14 '12 at 21:58
-
@DJKRAZE I fixed that for you. – Robert Harvey Aug 14 '12 at 22:00
-
thanks Harvey.. how do I convert an answer to a comment for future reference.?? – MethodMan Aug 14 '12 at 22:09
-
@DJKRAZE: By copy/pasting to a comment and deleting your answer. :) – Robert Harvey Aug 14 '12 at 22:19
-
Get yourself a decent UI automation library or the pinvoke will eat you whole. Like http://white.codeplex.com/ – Hans Passant Aug 15 '12 at 03:26
1 Answers
1
You can look into the SendMessage API. DDE was an old method of IPC but it still works with .net.
As a cheap easy method, just create a form with a guid + '|' + the handle of a text box as the Text property. When your app runs just load the form but don't show it (hide it from the task tray as well).
Your other app can FindWindowEx on the first apps form using the predetermined guid in the header and also get the handle to the textbox on the form (seperate it from the guid with a pipe char or something).
Now just SendMessage(WM_SETTEXT) to the textbox hwnd (give it the value the user selected in the combobox). If you put an event handler on the text_changed event it will fire in your first app.

Belmiris
- 2,741
- 3
- 25
- 29
-
Thanks everybody. But seems there is a little miss understood with my issue. The combobox is at the application I have not source code. What I try to do is create a delegate event hook to the combobox so when it has been changed trigger the event handler at my application and in this method capture the combobox selected value. Seems this requires Global System Hooks, and this could be hard to implement, if I am not wrong. ;-) – user1599230 Aug 15 '12 at 14:36
-
[GlobalSystemHooks](http://www.codeproject.com/Articles/18638/Using-Window-Messages-to-Implement-Global-System-H) Seems the unique way to do this is with Global System Hooks, and implement this requires a C# wrapper for a C++ dll, so there is not a simple answer to my question... So thanks every body for you advices. – user1599230 Aug 15 '12 at 21:54