Solved

Get text(word) when mouseover everywhere on screen?

Posted on 2003-11-23
4
333 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 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month3 days, 15 hours left to enroll

630 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