Question

How do i retrieve the tooltip text at a specific spot on the screen?

Asked by: soriega

Hi
I am trying to retrieve the text from an application and need to get the text out of the tooltipballoon. I have tried to use FindwindowsEX, Gettext(), childenumerations etc. However, i can't find the hwnd at the point where i wan't to get the tooltip balloon from.
SO: is it possible to simply place the mouse at a specific point on the screen, wait for the balloon to appear and then read what it says without knowing the hwnd of the underlying windowscontrol?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-06-25 at 15:45:11ID23516506
Tags

vb.net

Topics

Microsoft Visual Basic.Net

,

Visual Basic Programming

Participating Experts
4
Points
400
Comments
13

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. ToolTip
    Hi I wanna cal a ToolTip from my OnMouseMove.. When the mouse is over a pos(x,y) in a HWnd, then I want a ToolTip to pop up.. I don't want to attach the ToolTip Control to a ID.. Just want a function that cals a tooltip. How is that done ?
  2. Tooltip formatting
    Anybody know how to custom draw tooltips? I need to display a tooltip that is formatted: italics, bold, underline etc.
  3. display chinese balloon tooltip in a windows defaulted as E…
    Dear Sir, Is it possible to display the balloon tooltip in Chinese even if the OS (windows 2000/xp) is defaulted English as the display language in the regional setting? Thank you very much.
  4. ToolTip & Balloon
    HI. CreateWindow(TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_BALLOON, 0, 0, 0, 0, NULL, NULL, g_hins...
  5. create balloon tooltips
    Hi I know how to make a tooltip like balloon. and when a mouse go over the component it will be activated. I want to activate it myself; for example activate it for an unlimited times, and then disappear it. my other problem is this; in the following code the tooltip can ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: BahpoopiePosted on 2008-06-25 at 15:55:10ID: 21870545

 

by: GHCS_MarkPosted on 2008-06-25 at 15:58:52ID: 21870562

I am presuming you are trying to do this for any application on the system.  You would therefore need to find the location of the mouse on the screen and perform some form of hittest to find the hwnd that the mouse was over.  You could then find the class of that window and see if it was a balloontip as I'm sure they will have a specific style but as I have never attempted this, I couldn't be any less vague.....

 

by: soriegaPosted on 2008-06-25 at 16:04:11ID: 21870597

OK i looked at the TTM_GETTEXT, it seems however like it still requires to know the hwnd (handle) of the control you wan't to retreive from. I can't find the hwnd, so what i need is basically to retreive the tooltiptext that shows up at a specific point X , Y on the screen (and that's not necessarily in a hwnd i can find the name of)

 

by: GHCS_MarkPosted on 2008-06-25 at 16:15:50ID: 21870652

You probably want to make use of http://msdn.microsoft.com/en-us/library/ms633558.aspx as well then.

 

by: soriegaPosted on 2008-06-25 at 16:51:33ID: 21870818

Thanks for WindowFromPoint. I can't get it to find any window though. In fact, wherever i place the mouse on the screen, it allways returns the same handle. Please look below.

     Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
 
 
 
 
    Private Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As POINTAPI) As Integer
   Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
Handles Button4.Click
        Dim result As Long, lptext As String
        Dim structCursorPosition As POINTAPI
        Call GetCursorPos(structCursorPosition)
        Debug.Print("X: " & structCursorPosition.x & " Y: " & structCursorPosition.y)
 
        'here is where the window is returned...
        result = WindowFromPoint(structCursorPosition.x, structCursorPosition.y)
 
 
 
      
 
    End Sub

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:

Select allOpen in new window

 

by: GHCS_MarkPosted on 2008-06-25 at 17:08:47ID: 21870894

According to the documentation that I linked, WindowFromPoint expects a POINT structure, not just x/y points as parameters, and therefore this could be why its failing to find the correct window.

 

by: peetmPosted on 2008-06-26 at 02:16:27ID: 21872990

I think I'd use a combination of EnumWindows/EnumChildWindows/GetClassName - to find TOOLTIPS_CLASSA class windows.  I'd then check with GetWindowRect and WindowFromPoint whether *this* window was the one I wanted.  Then it's a case of using TTM_GETTEXT.

 

by: zzzzzoocPosted on 2008-06-27 at 15:16:34ID: 21888098

For those suggesting to simply use TTM_GETTEXT, can you provide examples?

Sending TTM_GETTEXT to a window belonging to a different process will result in that process attempting to fill the TOOLINFO structure located within the virtual memory of your own process -- which it does not have access to.

To accomplish this, you'll need to allocate virtual memory that both processes have access to, and read/write your variables/structures there for when you use SendMessage().

I could not get this to work in XP and I don't know why it failed either. :-) Although I did try this in VB6 and not .NET but I'm not entirely sure of the best method of approaching this with .NET. Maybe native Win32 API or Marshal class?

 

by: GHCS_MarkPosted on 2008-06-29 at 10:21:51ID: 21894726

As you said, you would need to allocate memory from the Global Heap and then copy it to a local before destroying the allocation.

http://msdn.microsoft.com/en-us/library/aa302340.aspx#win32map_memorymanagementfunctions

Take a look here for an example using a listview of how to access items from another process:

http://www.vbforums.com/showthread.php?t=527756

 

by: soriegaPosted on 2008-06-30 at 08:34:53ID: 21900109

Thanks far all help. I still need some example code on how to retreive the text using SENDMESSAGE and TTM_GETTEXT (as zzzzzooc pointed out..)

Does anyone have some code for this?

Thanks

 

by: zzzzzoocPosted on 2008-07-07 at 13:36:24ID: 21948441

Played around with it some more and I found out why it wasn't working (in VB6). I guessed wrong when I thought lParam probably wouldn't be required in the TOOLINFO structure. :-(

Now the below is only a start and not fully reliable. Some tooltips aren't being retrieved via either TTM_ENUMTOOLS/TTM_GETTEXT for some reason. MSDN mentioned using GETDISPINFO (WM_NOTIFY) but I haven't poked around with that so that could help. It's also only supported on Windows 2000 and above because Read/WriteProcessMemory() isn't supported on 9x. I don't have access to those systems so that makes it difficult to test anything for those platforms. :-)

It's in VB6 but conversion shouldn't be that difficult.



Form1:
------------------------------------------------------------
Option Explicit

Private Type POINTAPI
   x As Long
   y As Long
End Type

Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private m_currwnd As Long
Private Sub Form_Load()
   Timer1.Interval = 3000
   Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
   Dim pt As POINTAPI
   Dim wnd As Long
   Call GetCursorPos(pt)
   wnd = WindowFromPoint(pt.x, pt.y)
   If (wnd <> m_currwnd) Then
       m_currwnd = wnd
       Call List1.Clear
       Call FindToolTips(m_currwnd)
   End If
End Sub



Module1:
------------------------------------------------------------
Option Explicit

Private Type RECT
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

Private Type TOOLINFO
   cbSize      As Long
   uFlags      As Long
   hWnd        As Long
   uId         As Long
   RECT        As RECT
   hInst       As Long
   lpszText    As Long
   lParam      As Long
   'lpReserved  As Long
End Type

Private Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function EnumThreadWindows Lib "user32.dll" (ByVal dwThreadId As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long
Private Declare Function GetCurrentProcessId Lib "kernel32.dll" () As Long
Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hWnd As Long, ByRef lpdwProcessId As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Declare Function VirtualFreeEx Lib "kernel32" (ByVal hProcess As Long, lpAddress As Any, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long

Private Const PAGE_READWRITE = &H4&

Private Const MEM_RESERVE = &H2000
Private Const MEM_COMMIT = &H1000
Private Const MEM_RELEASE = &H8000

Private Const PROCESS_VM_OPERATION As Long = (&H8)
Private Const PROCESS_VM_READ As Long = (&H10)
Private Const PROCESS_VM_WRITE As Long = (&H20)

Private Const WM_USER As Long = &H400
Private Const TTM_GETTOOLCOUNT As Long = (WM_USER + 13)
Private Const TTM_ENUMTOOLSA = (WM_USER + 14)
Private Const TTM_ENUMTOOLSW = (WM_USER + 58)
Private Const TTM_GETTEXTA As Long = (WM_USER + 11)
Private Const TTM_GETTEXTW = (WM_USER + 56)
Public Sub FindToolTips(ByVal owner_hWnd As Long)
   Dim thread As Long
   thread = GetWindowThreadProcessId(owner_hWnd, ByVal 0&)
   If (thread <> 0) Then
       Call EnumThreadWindows(thread, AddressOf EnumThreadWndProc, 0)
   End If
End Sub
Public Function EnumThreadWndProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
   Const LPSTR_TEXTCALLBACK As Long = -1
   Const TOOLTIP_MAXLEN As Long = 160
   
   Dim numtools As Long
   Dim m_pid As Long
   Dim m_proc As Long
   Dim m_ptr_ti As Long
   Dim m_ptr_txt As Long
   Dim m_len_ti As Long
   Dim ti As TOOLINFO
   Dim i As Integer
   Dim pos As Integer
   Dim buff() As Byte
   Dim buff_str As String
   'get number of tools.. if none, probably not tooltip control
   numtools = SendMessage(hWnd, TTM_GETTOOLCOUNT, 0, ByVal 0&)
   If (numtools > 0) Then
       'open target process, allocate memory
       Call GetWindowThreadProcessId(hWnd, m_pid)
       m_proc = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, m_pid)
       m_len_ti = LenB(ti)
       m_ptr_ti = VirtualAllocEx(m_proc, 0, m_len_ti, MEM_COMMIT Or MEM_RESERVE, PAGE_READWRITE)
       m_ptr_txt = VirtualAllocEx(m_proc, 0, TOOLTIP_MAXLEN, MEM_COMMIT Or MEM_RESERVE, PAGE_READWRITE)
       'loop through tools
       For i = 0 To (numtools - 1)
           ti.cbSize = m_len_ti
           ti.lpszText = m_ptr_txt
           'initialize some stuff :P
           ReDim buff(TOOLTIP_MAXLEN - 1) As Byte
           Call WriteProcessMemory(m_proc, ByVal m_ptr_ti, ti, m_len_ti, 0)
           Call WriteProcessMemory(m_proc, ByVal m_ptr_txt, buff(0), TOOLTIP_MAXLEN, 0)
           'get tool info
           If (SendMessage(hWnd, TTM_ENUMTOOLSW, i, ByVal m_ptr_ti)) Then
               Call ReadProcessMemory(m_proc, ByVal m_ptr_ti, ti, m_len_ti, 0)
               'if ptr changed to -1 (callback), use gettext (msdn says use GETDISPINFO?)
               If (ti.lpszText = LPSTR_TEXTCALLBACK) Then
                   ti.lpszText = m_ptr_txt
                   Call WriteProcessMemory(m_proc, ByVal m_ptr_ti, ti, m_len_ti, 0)
                   Call SendMessage(hWnd, TTM_GETTEXTW, ByVal TOOLTIP_MAXLEN, ByVal m_ptr_ti)
               End If
               Call ReadProcessMemory(m_proc, ByVal m_ptr_txt, ByVal VarPtr(buff(0)), TOOLTIP_MAXLEN, 0)
               'format our text
               buff_str = buff
               pos = InStr(1, buff_str, vbNullChar)
               If (pos > 0) Then
                   buff_str = Left$(buff_str, pos - 1)
               End If
               
               'your tooltip...
               If (buff_str <> vbNullString) Then
                   Form1.List1.AddItem buff_str
               End If
               
           End If
       Next
       'cleanup
       Call VirtualFreeEx(m_proc, ByVal m_ptr_ti, m_len_ti, MEM_RELEASE)
       Call VirtualFreeEx(m_proc, ByVal m_ptr_txt, TOOLTIP_MAXLEN, MEM_RELEASE)
       Call CloseHandle(m_proc)
   End If
   'continue enum
   EnumThreadWndProc = 1
End Function


20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...