Search code examples
c#outlookpinvoke

PInvoke: Any possibility to identify a Textbox-Control


I have an Outlook-Addin, which contains a Ribbon with a Textbox. I'd like to access and set this Text in the Code behind, but according to this Thread Access Ribbon Elements Programatically in XML Ribbon this is not possible. So I tried to bypass the Outlook-Logic and work with PInvokes.

I've written a small wrapper, which returns me the Class-Name, the Text and the Handle of each Control of a given Process, for example Outlook.

But I still didn't find a possibility, to kindahow indentify Textbox X as Handle y.

I also tried to get more Informations via

    [DllImport("user32.dll", SetLastError = true)]
    internal static extern Boolean GetClassInfoEx(IntPtr hInstance, String lpClassName, ref Model.WndClassEx lpWndClass);

But I also can't see a possibility to identify my Control with this Data.

The last possibility I see here is to create a 'GetText'-Delegate on the Ribbon, set some specific Text and search the Control via this Text, but this seems super-hackish to me.

Are there better ways to make this work?


Solution

  • These controls are not windowed. That is, the text box control does not have a window handle, because it is not a window.

    So what you are attempting to do, is impossible by this method. Whilst you can enumerate the windows of the process, but this will not yield a window representing the text box, because the text box, like other ribbon sub-controls, is not windowed.