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

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

问题描述

我想获取 win32 旧控件的工具提示文本(不是本质上支持 .

更新 2:那些相信这可以通过……完成的人,我想说,说起来容易做起来难.我欢迎那些已经尝试过的人对此发表评论,如果您能提供一些证据来证明其适用性和有效性,我们也欢迎一些表面上可行的解决方案.

更新 3:如果我们尝试最小化 TTM_SETDELAYTIME 以便 sleep(N) 中的 N可以最小化,这在一些实验后不起作用.一旦工具提示窗口句柄存在,我们只能调整它.例如

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

更新 4:使用 TTM_GETTEXTA 消息似乎是一个解决方案,但是,它类似于更新 3,我们需要 tooltipCtrl<的句柄/code>,它仅在工具提示创建后可用,因为要创建此工具提示,我们别无选择,只能将鼠标光标悬停在工具上方,这似乎存在性能问题(Thread.Sleep) 如上所述.

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

更新 5:如何获取工具提示文本"使用 InterOp (PInvoke) 或使用传统方法的自动化 UI(鼠标悬停在工具窗口上,找到 Hwnd 句柄,然后获取其文本...) 不是这篇文章的关注点.预期结果:我们能否提取控件(例如按钮)的工具提示字符串而无需将鼠标悬停在控件上?如果是,如何?

更新 6:使用 WM_MOUSEHOVER 激活工具提示窗口似乎不起作用,我已经使用 SendMessage(...) 测试了它并填充了适当的 wparam 和 lparam,但在静脉中.

解决方案

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

玩 WM_HOVER、WM_MOUSEHOVER、WM_MOUSEENTER

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

您的屏幕截图看起来像一个自定义控件,因此要弄清楚是什么触发了工具提示,这将是一个黑客问题.

您可能可以同时发送多个 WM_MOUSEENTER 或 WM_MOUSEHOVER.这真的取决于底层代码.

如果这导致延迟太长(并且建议的解决方案均无效),请考虑将工具提示测试拉入不那么频繁或仅在特定请求下执行的辅助测试池.

还有...我相信你已经尝试过了...但如果没有,请查看 UI Spy 并查看它是否在实际生成之前报告了有关工具提示的任何信息.

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

What I have done:

  • 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;
  • 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.

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)

  • Programmatically get the button's tooltip string without requiring the tooltip to appear
  • Without having to place mouse over each button one-by-one.

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.

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.

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

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);

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?

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.

Play with WM_HOVER, WM_MOUSEHOVER, WM_MOUSEENTER

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

etc.

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

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.

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天全站免登陆