none
AfxOleControl42 Set Text

    Question

  • I'm currently building an application that will interact with another application via sending text to textbox controls, clicking buttons, etc (general Windows Automation stuff).  I am building this app with C# 4.0 framework.

    I'm struggling setting the text of a control that has a type of AfxOleControl42.

    I verified I grab the proper control (handle id) via Spy++, because when I log messages in Spy++, when I send text to the particular textbox control (of type AfxOleControl42), it tells me that I'm keydowning and keyupping in the expected handle id.

    However, when I try to interact with this textbox control programmatically, I am unable to

    I've tried the following methods:

    1. SendMessage(int, WM_SETTEXT, 0, STRING_TO_SEND)
    2. SendMessage(int, WM_KEYDOWN (and then WM_KEYUP), 0, STRING_TO_SEND)
    3. PostMessage()
    4. Clipboard paste
    5. Used AutomationElement object...((ValuePattern)valuePattern).SetValue(value);
    6. System.Windows.Forms.SendKeys.Send() and .SendDelay()

    When using AutomationElements, and I try to set focus, I get an exception "Target element cannot receive focus".

    Has anyone had issues with this type of control before?  I have no idea why the developer didn't just use a TextBox control, instead of AfxOleControl42, but it seems more like a Panel than a TextBox...

    **Edit:  This is on a Windows 7 machine***


    • Edited by timclaason Monday, October 14, 2013 3:39 PM
    Monday, October 14, 2013 3:28 PM

All replies

  • I ended up using a library called "Windows Input Simulator."  It allows me to send input via SendKeys more successfully.

    It isn't the perfect solution, and I'm still stumped as to why my attempts at interacting with these controls are so disappointing.  Hopefully someone will eventually be able to speak to this...

    Wednesday, October 16, 2013 6:10 PM