1

I have a unique challenge. I've been tasked with manipulating a third party application's controls from my own application and I'm restricted to .Net 3.5. I'm able to write text to a rich text box from the clipboard and click a button so far (thank you Spy++):

        // paste text into Rich Text Box
        IntPtr hwndChild = FindWindowEx((IntPtr)handle, IntPtr.Zero, "WindowsForms10.RichEdit20W.app.0.378734a", null);
        SendMessage(hwndChild, Msgs.WM_PASTE, 0, IntPtr.Zero);

        // click OK button
        hwndChild = FindWindowEx((IntPtr)handle, IntPtr.Zero, "WindowsForms10.BUTTON.app.0.378734a", null);
        SendMessage(hwndChild, Msgs.BM_CLICK, 0, IntPtr.Zero);

Now I'm trying to access a combobox in the other app to compare it's datasource contents with a value read from elsewhere, and if that value matches one in the combobox, then select that value in the other app's combox. My application is in C#.

I'm able to get the handle of the combobox in the other app using the user32.dll method FindWindowEx() like this:

hwndChild = FindWindowEx((IntPtr)handle, IntPtr.Zero, "WindowsForms10.STATIC.app.0.378734a", null);

I used Spy++ to find the combobox's class name, but don't know what to do next. I tried this:

        NativeMessage lpMsg = new NativeMessage();
        PeekMessage(out lpMsg, hwndChild, 0, 0, 0x0000); // set wRemoveMsg to 0x0000

but lpMsg is empty after the call. That was a wild-ass guess anyway. Any ideas?

Phil N DeBlanc
  • 398
  • 1
  • 13
  • https://stackoverflow.com/questions/11961215/how-to-hook-an-event-to-a-windows-control-in-other-application. The accepted answer does not solve the issue. It seems, that you need a c++ app, that creates a hook and then executes a callback from managed code – oldovets Aug 24 '18 at 22:24
  • This cpuld help you: https://www.pinvoke.net/default.aspx/Constants.CB_GETLBTEXTLEN – ZorgoZ Aug 25 '18 at 05:22
  • Thanks @oldovets and @ZorgoZ! – Phil N DeBlanc Aug 27 '18 at 14:51

1 Answers1

0

I swear that I tried this, but the answer was simply to use this after loading the clipboard with the text:

SendMessage(hwndChild, Msgs.WM_PASTE, 0, IntPtr.Zero);

I doesn't resolve the "I'm trying to access a combobox in the other app to compare it's datasource contents with a value read from elsewhere, and if that value matches one in the combobox, then select that value in the other app's combox" issue, but at least I can paste into it.

Phil N DeBlanc
  • 398
  • 1
  • 13