|
-
May 25th, 2000, 01:31 AM
#1
Thread Starter
Hyperactive Member
how can i get the text of any object my mouse is over, like buttons, combo boxes, text boxes, and list items.
-
May 25th, 2000, 03:39 AM
#2
transcendental analytic
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 26th, 2000, 04:18 PM
#3
Thread Starter
Hyperactive Member
-
May 26th, 2000, 06:39 PM
#4
transcendental analytic
That's a bit hard to do, you need to use a lot of api, because each control have different ways in showing it's text, basically getwindowtext. To know which window is att toplevel at that point of screen you need to enumerate all windows, and then enumerate all childwindows and then compare the rects of them (getwindowrect) for the last window that is at top in the enumeration, with the cursorposition (getcursorpos) and you have the right wnd. for getting the text, i'm not sure if you can do that with all controls, but you could try.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 27th, 2000, 04:33 PM
#5
Thread Starter
Hyperactive Member
i just want to know how can we get the text from all the controls, i can do the rest myself.
-
May 27th, 2000, 07:06 PM
#6
transcendental analytic
That's as i said hard but there's another way. You can get the DC of the desktopwindow and then copy the area your mouse is over with bitblt. and you will have a small box containing the text (and the background to it), i know thats probably not what you want, am i right?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 28th, 2000, 02:05 AM
#7
Thread Starter
Hyperactive Member
but thats not what i want, any other ideas?
-
May 28th, 2000, 02:27 AM
#8
Guru
Kedaman, that would work, but what about this?
More of my module-loving code:
Code:
Option Explicit
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Type POINTAPI
x As Long
y As Long
End Type
Function GetTextFromCursorPosition() As String
Dim sBuffer As String, lBufferSize As Long, hWndThingie As Long, ptCursorPos As POINTAPI, lPos As Long
Call GetCursorPos(ptCursorPos)
hWndThingie = WindowFromPoint(ptCursorPos.x, ptCursorPos.y)
' Now, hWndThingie is the hWnd of the window where the mouse cursor is.
lBufferSize = GetWindowTextLength(hWndThingie) + 1
sBuffer = String(lBufferSize, vbNullChar)
Call GetWindowText(hWndThingie, sBuffer, lBufferSize)
' Now, to trim the null(s)!
lPos = InStr(sBuffer, vbNullChar)
If lPos > 0 Then sBuffer = Left(sBuffer, lPos - 1)
' Return the text.
GetTextFromCursorPosition = sBuffer
End Function
Then... Whenever... Use this:
Call MsgBox("Why are you pointing at a TextBox/Window/Whatever whose caption/text/whatever is " & GetTextFromCursorPosition & "?")
-
May 28th, 2000, 02:36 AM
#9
transcendental analytic
Wow! Yonatan, you really deserves to be Guru! Windowfrompoint, i didn't know that. Thanks!
Also, i'm a module lover 
[Edited by kedaman on 05-28-2000 at 10:37 PM]
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 28th, 2000, 09:09 PM
#10
Thread Starter
Hyperactive Member
i tried that too, but it only gets the text from text boxes. any other ideas.
-
May 28th, 2000, 10:02 PM
#11
transcendental analytic
Well listboxes and other controls that don't work with getwindowtext just have the text stored internally, You could try to get the DC instead and somehow extract the text from there by comparing it to different fonts in different size, but i think that's somewhat too hardcore
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 28th, 2000, 11:53 PM
#12
Guru
This should be a little check program... Not an OCR one. (Maybe)
Extracting the text from graphics is OCR (Optical Character Recognition). It's a little too advanced for something like getting the text from ListBoxes. I haven't tested my code, but I think everything you wanted (except ListBoxes) works with the code I gave you.
Here is some code that will identify whether it's a ListBox or not. If it is, it will get the text of the currently selected item there. If it isn't, it will run the GetWindowText code I gave you earlier.
Try this code in a module (I haven't tested it, but it should work):
Code:
Option Explicit
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Const LB_GETCURSEL = &H188
Public Const LB_GETTEXT = &H189
Public Const LB_GETTEXTLEN = &H18A
Public Const LB_ERR = (-1)
Type POINTAPI
x As Long
y As Long
End Type
Sub TrimNulls(ByRef sString As String)
Dim lPos As Long
lPos = InStr(sString, vbNullChar) ' Scan the string for nulls.
If lPos > 0 Then sString = Left(sString, lPos - 1) ' Found one? Trim! Only leave whatever is before it.
End Sub
Function GetTextFromListBox(ByVal hWndListBox As Long) As String
Dim sBuffer As String, lBufferSize As Long, lCurSel As Long
lCurSel = SendMessage(hWndListBox, LB_GETCURSEL, 0, ByVal 0) ' Get the current selection index.
If lCurSel = LB_ERR Then Exit Function ' No selection? Return an empty string.
lBufferSize = SendMessage(hWndListBox, LB_GETTEXTLEN, lCurSel, ByVal 0) + 1 ' Get length + null place.
sBuffer = String(lBufferSize, vbNullChar) ' Reserve the correct amount of places.
Call SendMessage(hWndListBox, LB_GETTEXT, lCurSel, ByVal sBuffer) ' Get the text followed by a bunch of nulls.
Call TrimNulls(sBuffer) ' Trim all the nulls!
GetTextFromListBox = sBuffer
End Function
Function GetTextFromCursorPosition() As String
Dim sBuffer As String, lBufferSize As Long, hWndThingie As Long, ptCursorPos As POINTAPI
' First we get the hWnd of the thingie where the cursor is.
Call GetCursorPos(ptCursorPos)
hWndThingie = WindowFromPoint(ptCursorPos.x, ptCursorPos.y)
' Now, hWndThingie is the hWnd of the window where the mouse cursor is.
' We need to check if it's a ListBox or not.
sBuffer = String(255, vbNullChar) ' Reserve 255 places.
Call GetClassName(hWndThingie, sBuffer, 255) ' Get the ClassName followed by a bunch of nulls.
Call TrimNulls(sBuffer) ' Trim all the nulls!
' If you know any ListBox ClassNames other than "ListBox" and "ThunderListBox", add them!
If (sBuffer = "ListBox") Or (sBuffer = "ThunderListBox") Then
GetTextFromCursorPosition = GetTextFromListBox(hWndThingie)
Exit Function
End If
' If it's not a ListBox...
lBufferSize = GetWindowTextLength(hWndThingie) + 1 ' Get length + null place.
sBuffer = String(lBufferSize, vbNullChar) ' Reserve the correct amount of places.
Call GetWindowText(hWndThingie, sBuffer, lBufferSize) ' Get the text followed by a bunch of nulls.
Call TrimNulls(sString) ' Trim all the nulls!
GetTextFromCursorPosition = sBuffer
End Function
Same syntax as before, except now it works with ListBoxes.
If you want to get all the text of all the items in a ComboBox or a ListBox, then post a reply and tell me about it.
-
May 29th, 2000, 01:01 AM
#13
Lively Member
May be of interest...
Just thought this link might interest you. It links to
some code for getting info on windows when you mouseover them. Check it out 
http://www.planet-source-code.com/vb...txtCodeId=5647
Laterz
REM
-
May 29th, 2000, 03:05 PM
#14
Thread Starter
Hyperactive Member
i sure would love to have a code to get the caption from list boxes and combo boxes. thanks for all the help.
-
May 29th, 2000, 05:26 PM
#15
Hyperactive Member
Kedaman posts = 1373: Fanatic member
Yonatan posts = 1142: Guru
Je ne comprends pas.
?????
DAn
-
May 29th, 2000, 05:38 PM
#16
transcendental analytic
Hehe, go complain about that to John. what does "Je ne comprends pas." mean?
I'll test your code later Yonatan.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 29th, 2000, 05:41 PM
#17
Hyperactive Member
Its French for 'I don't understand'
(no I'm not French, or Canadian)
Dan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|