获取Win32的旧有控制的工具提示文本编程 [英] Get Win32 legacy control's tooltip text programmatically

查看:229
本文介绍了获取Win32的旧有控制的工具提示文本编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得为Win32原有控制(而不是WPF控件,支持固有的 UI自动化)。

I would like to get the tooltip text for win32 legacy control (not WPF controls that inherently support UI Automation).

我做了什么:


  • 鉴于利益的按钮时,我得到了它的 AutomationElement ,其边界RECT

  • 我移动鼠标移到该按钮(code);

  • Thread.sleep代码(1500)来等待提示控制弹出;
    强大的文本 - 枚举桌面上所有的子窗口,并获得子窗口 tooltipAutomationElement ,其类型是工具提示;

  • tooltipAutomationElement ,得到这个提示的name属性,对应的工具提示字符串。

  • Given a button of interest, I've got its AutomationElement, and its bounding rect
  • I moved the mouse over this button (in code);
  • Thread.Sleep(1500) to wait for the tooltip control to popup; strong text - Enumerate Desktop's all child windows, and get the child window tooltipAutomationElement, whose type is "Tooltip";
  • From tooltipAutomationElement, get this tooltip's name property, which corresponds to the tooltip string.

这实际工作,但代价是:我必须睡眠(1500)并手动等待提示出现(5-20​​按钮进行扫描工具提示串),该不匹配的性能要求。

This actually works, but the penalty is: I have to sleep(1500) and manually wait for the tooltip to appear (5-20 buttons are to be scanned for the tooltip strings), which does not match performance requirement.

什么是预期(不知道这是可行的)

What is expected (not sure if it is feasible)


  • 以编程方式获得按钮的工具提示字符串,而无需提示出现

  • 而不必把鼠标放在每个按钮一个接一个。

更新1 :对于 TTN_NEEDTEXT ,MSDN文档看起来不是很清楚,我不知道如何编程此使用C#。一个相关的链接到工具提示控件相关的低水平的结构/信息可以发现的这里

Update 1: For TTN_NEEDTEXT, MSDN doc seems not very clear, and I have no clue how to program this using C#. One of the relevant link for low level structures/messages related to tooltip control can be found here.

更新2 :谁相信那些它可能是由...做的,我会说,这说起来容易做起来难。我欢迎那些谁已经尽力了,这则留言,有的表面上是可行的解决方案,欢迎您的可以提供一些证据的展现其适用性和疗效。

Update 2: Those who believe this could be done by ... , I would say, it is easier said than done. I welcome those who have tried, to comment on this, and some ostensibly feasible solutions are welcome if you can offer some evidence to show its applicability and efficacy.

更新3 :如果我们试图尽量减少 TTM_SETDELAYTIME N 中在睡眠(N)可以被最小化,这并不经过一些试验工作。一旦提示窗口句柄存在,我们只能调整这一点。例如。

Update 3: If we try to minimize the TTM_SETDELAYTIME so that N in the sleep(N) can be minimized, this does not work after some experimentation. We can only adjust this once the tooltip window handle exists. e.g.

SendMessage(_tooltipCtrl.Handle, TTM_SETDELAYTIME, _TTDT_INITIAL, 10); //10 ms

更新4 :使用 TTM_GETTEXTA 消息似乎是一个解决方案,但是,它类似于更新3,我们需要的手柄在 tooltipCtrl ,这是唯一可用之后创建的提示,有这个提示创建以来,我们没有选择,只能悬停鼠标光标的工具,它似乎有以上性能问题( Thread.sleep代码)正如上文所述。

Update 4: using TTM_GETTEXTA message seems to be a solution, however, it is similar to Update 3, where we need the handle of the tooltipCtrl, which is only available AFTER the tooltip is created, since to have this tooltip created, we have no choice but to hover mouse cursor above the tool, which seems to have performance issues (Thread.Sleep) as outlined above.

SendMessage(_tooltipCtrl.Handle, TTM_GETTEXTA, 0, ti);

更新5 :如何获得提示文本使用互操作(PInvoke的),或者使用自动化UI传统的方法(鼠标悬停工具窗口中,找到HWND处理,然后获取它的文本。 ..)是不是这个职位的关注。什么是预期的:我们能否无需徘徊在控制中提取控制(比如按钮)的工具提示字符串?如果是的话,怎么样?

Update 5: "How to get the tooltip text" using InterOp (PInvoke) or Automation UI using traditional approach (mouse hovering on the tool window, find the Hwnd handle, then get its text...) is not the concern of this post. What is expected: Can we extract the tooltip string of a control (say a button) with no need of hovering upon the control? If yes, how?

更新6 :使用WM_MOUSEHOVER激活提示窗口似乎不工作,我一直在使用的SendMessage(...)适当wParam和lParam填补,但在静脉测试了出来。

Update 6: using WM_MOUSEHOVER to activate the tooltip window seems not working, I have tested that out using SendMessage(...) with proper wparam and lparam filled, but in vein.

谢谢!

推荐答案

只是一个想法,而是尝试使用消息,而不是利用实际的鼠标。

Just a thought, but try using messages rather than leveraging the actual mouse.

与WM_HOVER播放,WM_MOUSEHOVER,WM_MOUSEENTER

Play with WM_HOVER, WM_MOUSEHOVER, WM_MOUSEENTER

 SendMessage(_buttonCtrl.Handle, WM_MOUSEHOVER, ..., ...)

等。

您的截图看起来像一个自定义的控制,因此这将成为黑客找出触发提示的问题。

Your screenshot looks like a custom control so it's going to be a matter of hacking to figure out what triggers the tooltip.

潜在的,您可以发送几个WM_MOUSEENTER的或WM_MOUSEHOVER的同时。这真的取决于基础code。

Potentially, you can send several WM_MOUSEENTER's or WM_MOUSEHOVER's simultaneously. It really depends on the underlying code.

如果这是导致过长的延迟,(而且没有建议的解决方案的工作)的去想拉提示检测到被较少或仅在特定要求执行的二次测试泳池。

If this is causing too long of a delay, (and none of the suggested solutions work) think about pulling tooltip testing into a secondary test pool that is executed less frequently or only on specific request.

也...我敢肯定,你已经尝试过......但如果​​没有,检查出的 UI间谍,看看它是否报告有关的实际产生之前,该提示的任何信息。

Also... and I'm sure you've tried it already... but if not, check out UI Spy and see if it reports any information about the tooltip before it's actually generated.

这篇关于获取Win32的旧有控制的工具提示文本编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆