-
Mar 12th, 2000, 11:38 PM
#1
How can I get the text currently highlighted in a grid. The grid is on a non vb form in another application.
I tried the GetWindowText api and sending a WM_GETTEXT message, but these do not work.
-
Mar 13th, 2000, 03:40 AM
#2
Hyperactive Member
I'm assuming you have the handle to the control. If not, I can tell you how to enumerate the windows to get that. Then you can use:
In your declarations:
Code:
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long
Const WM_GETTEXTLENGTH = &HE
Const WM_GETTEXT = &HD
In your form:
Code:
Dim wintext As String ' receives the copied text from the target window
Dim slength As Long ' length of the window text
Dim retval As Long ' return value of message'
'lControlhwnd is the Handle to Control - Pass This
' First, determine how much space is necessary for the buffer. (1 is added for the terminating null character.)
slength = SendMessage(lControlhwnd, WM_GETTEXTLENGTH, ByVal CLng(0), ByVal CLng(0)) + 1
'Make enough room in the buffer to receive the text.
wintext = Space(slength)
' Copy the target window's text into the buffer.
retval = SendMessage(lControlhwnd, WM_GETTEXT, ByVal slength, ByVal wintext)
' Remove the terminating null and extra space from the buffer.
wintext = Left(wintext, retval)
MsgBox "The Control's Text Is: " & wintext, vbOkOnly + vbInformation
-
Mar 13th, 2000, 03:51 AM
#3
The code above will not work, becuse in order for you to get the text, you would have to know the hWnd of the individual cell.
-
Mar 13th, 2000, 03:54 AM
#4
Hyperactive Member
This does work for most controls such as textboxes, listboxes, or comboboxes. However,
using Spy++, you can tell that only the grid itself has a handle but not each individual
cell (works the same way for tabs).
Edited by WadeD on 03-13-2000 at 04:13 PM
-
Mar 13th, 2000, 04:13 AM
#5
The thing is, there are no chidren physically in the grid.
If you use Spy++ to retrieve messages for the Grid (I used MSFlexGrid in that test), it looks like it's painting the part of the grid based on the coordinates. So, it is not using WM_SETTEXT (with SendMessage), but rather painting the text (in this case an image) to the Grid.
I'm sure it can be done, it's just a matter of time finding that out.
-
Mar 13th, 2000, 04:24 AM
#6
Well, I knew the WM_GETTEXT message didn't work. And I knew also the grid didn't have any child windows. So if the grid uses graphical methods to paint the text, I'm affraid it can't be done with subclassing either. And to use some kind of OCR techniques is a bit overdone for me. If there are any other ideas, I would like to hear them.
Thanks so far.
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
|