Solved

Get text(word) when mouseover everywhere on screen?

Posted on 2003-11-23
4
329 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
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 300 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

896 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now