Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get text(word) when mouseover everywhere on screen?

Posted on 2003-11-23
4
Medium Priority
?
335 Views
Last Modified: 2010-05-01
        I wanna get text(word) when mouseover everywhere on screen? I knew that if the text is picture we can not get but if it is a text how can?


Thank in advance
0
Comment
Question by:smallboyzkh2002
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 600 total points
ID: 9813437
Not a strong solution but:

See if this help: (save the following code with notepad to a text file called frmGetTextFromHwnd .frm and add it to a standard exe project)


VERSION 5.00
Begin VB.Form frmGetTextFromHwnd
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5940
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   5940
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox Text1
      Appearance      =   0  'Flat
      BackColor       =   &H00000000&
      ForeColor       =   &H0000FFFF&
      Height          =   2535
      Left            =   60
      MultiLine       =   -1  'True
      ScrollBars      =   3  'Both
      TabIndex        =   0
      Top             =   60
      Width           =   5835
   End
   Begin VB.Timer Timer1
      Interval        =   125
      Left            =   3780
      Top             =   2640
   End
End
Attribute VB_Name = "frmGetTextFromHwnd"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Const WM_GETTEXT = &HD

Private Type POINTAPI
        x As Long
        y As Long
End Type

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 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 Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long




Private Function GetTextFromHwnd()
Dim ret As Long
Dim pt As POINTAPI
Dim MyStr As String

ret = GetCursorPos(pt)
ret = WindowFromPoint(pt.x, pt.y)
MyStr = String$(255, Chr$(0))

If ret Then
    GetWindowText ret, MyStr, 255
    If Left$(MyStr, 1) = Chr$(0) Then
        SendMessage ret, WM_GETTEXT, ByVal 255&, ByVal MyStr
    End If
    If Left$(MyStr, 1) <> Chr$(0) Then
        With Text1
            .Text = "Hwnd: " & ret & " - " & Chr$(34) & Left$(MyStr, InStr(1, MyStr, Chr$(0), vbTextCompare) - 1) & Chr$(34) & vbNewLine & .Text
        End With
    End If
    MyStr = String$(255, Chr$(0))

End If

End Function




Private Sub Timer1_Timer()
GetTextFromHwnd
DoEvents
End Sub


0
 
LVL 1

Author Comment

by:smallboyzkh2002
ID: 9816402
Thank  Richie_Simonetti
        I test your code already but it can get only the text in NotePad Program only the other it can get only title of program. Anyway thank for helping.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9817283
That's an old code that i found on my HD, i cannot test it since i haven't vb installed anymore but if i remeber well, it could get text from buttons, icons and any window that has a hwnd. It doesn't works with labels, i didn't have time to found a way to read them too.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question