-1

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?

Community
  • 1
  • 1
Matthias Müller
  • 3,336
  • 3
  • 33
  • 65

1 Answers1

1

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Well I get the Handle, and If I manually enter some Text in the Textbox and read out the Text of each Subcontrol, I also get the Handle. But I'd like to do that without some "Find by Text"-shennanigans. – Matthias Müller Nov 02 '15 at 21:48
  • Text boxes on Office ribbons are not windowed – David Heffernan Nov 02 '15 at 21:53
  • I think we're speaking about something else. Did I use a wrong word or might you elaborate what you mean, about not windows? I don't need the Window-Informations per se, just the Text and a comprehensible Identifier. – Matthias Müller Nov 03 '15 at 07:48
  • You are trying to check the window class name. Only windows have window classes. I'm telling you that the code in your question, and your entire approach cannot work because you are dealing with non-windowed controls. I'm sure there is a way to interact with your controls, but it's unclear what it will be since you omitted so much detail. – David Heffernan Nov 03 '15 at 07:57
  • OK Thanks, seems like I've a wrong understanding of the materia. I will need to research further about this topic. – Matthias Müller Nov 03 '15 at 11:40
  • Btw: can You edityour answer? Didn't wan to downvote but to upvote. – Matthias Müller Nov 03 '15 at 11:46
  • OK I've done that. I didn't really mind the downvote because it's hardly the most earth shatteringly brilliant answer! – David Heffernan Nov 03 '15 at 12:04