Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get text(word) when mouseover everywhere on screen?

Posted on 2003-11-23
4
Medium Priority
?
337 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

926 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