0

I'm working on a small program that automates using another program. I have no problem using FindWindow(Ex) and getting/setting text to all of the other controls on the software, but am hitting a road block with the Edit control they are using. Using Spy++, I can find the control without issues, and can get/set the text to it, but it's not actually visible. Is it a custom control? Can I access the different controls inside of a custom control? I've attached some screen shots to show what is happening.

Using Spy++ to find the class of the control: enter image description here

But it doesn't see the caption "sometext"

Now I'll set the text to "testing" enter image description here

It reads the text, but it's not what is actually displayed. The control still displays "sometext" but Spy++ and my own GetText method sees "testing"

Finally, I tried closing it to see if it was covering a control or something and this is what I saw enter image description here

It does the typical minimize/close but there is a "textbox" type of thing still visible. Is it a custom control they constructed that has a control inside of it? Am I able to get/set the text there that says "sometext"? Also, I browsed and searched the Spy++ window for "sometext" (after refreshing it, of course), and it was no where to be found.

I'm currently doing it by setting focus to it, which activates the cursor in the field, and using sendkeys to clear the field and populate new text. It works fine, but I really don't want to use sendkeys in case the focus somehow gets lost during the keypresses.

Also, trying to keep it .NET 2.0 compatible if possible. Thanks!

sdouble
  • 1,055
  • 3
  • 11
  • 28
  • So the Caption is not what is displayed? Sounds like an owner-drawn control. If that is so, chances are that there is no published text property but only pixels. In that case I suspect the control itself might listen to the keypresses.. If all that is so, I doubt that you can do better that working with sendkeys yourself.. – TaW May 22 '14 at 20:58
  • The Edit control does not support owner-draw. Without seeing the window hierarchy it is just a wild guess what window Spy++ found. – Hans Passant May 22 '14 at 21:03
  • Talking about wild guesses, [here is one](http://stackoverflow.com/questions/7348745/how-to-custom-draw-a-margin-in-a-textbox) ;-) – TaW May 22 '14 at 22:19
  • @TaW That's what I was afraid of. I don't really need to _get_ the text, but setting it is a necessity. I was hoping to watch the field for text to monitor while the software is processing (when it's finished, the text disappears from that field), but there are other things I can watch. Maybe I'll set focus before every keystroke to be as close to certain that the focus is on the right field as I can be. The way the "Edit" control is minimized and the big white textbox is still visible in the third picture makes me think there is a control inside of the Edit control that I can't access. – sdouble May 23 '14 at 13:19
  • Well, as Hans said, I was making just wild guesses. But it still could be impossible to set the text in a direct way; instead of sending the characters one by one, I would try to load them into the clipboard and then paste them all in one sendkey _ctrl-V_ command. For good measure you might even clear the clipboard afterwards and retrieve them with a _crtl-A ctrl-C_ (and optionally _end_) to check they got there ok.. – TaW May 23 '14 at 13:54
  • I actually do a paste into the field. For clearing, I send the end key and 60 backspaces (59 character limit on the field). I initially tried ctrl-a but it's a hotkey on their software. I've been considering a chain of end, shift + home, delete instead of the backspaces, but am afraid they could somehow lose the highlight. – sdouble May 23 '14 at 14:17

0 Answers0