Solved

Get text(word) when mouseover everywhere on screen?

Posted on 2003-11-23
4
328 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

744 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

15 Experts available now in Live!

Get 1:1 Help Now