How to grab data from non-owned window.
-
- Enthusiast
- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
How to grab data from non-owned window.
Been a while since I've been here, but glad to be back. Hoping to get my programming brain workng again.
Here is my question.
I have a non-owned program running. There is no known way to export the information I need from it, but it appears on a window in the same position at all times. I know the name of the window and hopefully can get the handle.
Is there some way I can grab the information from that window?
It is three to four lines of text. I cannot select and copy to the clipboard manually, so I'm need to find a way to read the display area and then copy it and paste into my program somehow.
Thanks for any ideas you can share.
Terry
Here is my question.
I have a non-owned program running. There is no known way to export the information I need from it, but it appears on a window in the same position at all times. I know the name of the window and hopefully can get the handle.
Is there some way I can grab the information from that window?
It is three to four lines of text. I cannot select and copy to the clipboard manually, so I'm need to find a way to read the display area and then copy it and paste into my program somehow.
Thanks for any ideas you can share.
Terry
Last edited by TerryHough on Thu Jan 30, 2014 6:08 pm, edited 1 time in total.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: How to grab data from non-owned window.
It would help if you could discover the class of control containing the text. Greatis Windowse or such should help here.
BERESHEIT
-
- Enthusiast
- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
Re: How to grab data from non-owned window.
Greatis Windowse does allow me to find each of these fields and reports the handle and control id of each of the lines. It even shows me the text in that control.
Now, I need to find a way to extract that over to a PureBasic program somehow. Probably some Windows API can help me?
Now, I need to find a way to extract that over to a PureBasic program somehow. Probably some Windows API can help me?
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
-
- Enthusiast
- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
Re: How to grab data from non-owned window.
Greatis Windowse reports
Class XEdit
on all of these fields.
Class XEdit
on all of these fields.
-
- Enthusiast
- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
Re: How to grab data from non-owned window.
Here is a screen capture of how the data looks on the non-owned screen that I need to grab the text from.

I'm not finding a way to do this so far.

I'm not finding a way to do this so far.
Re: How to grab data from non-owned window.
If you have the handle to the XEdit control/window, try this.
I do have some old code laying around if you need it. It may take me a while to find it.
Code: Select all
SendMessage_(hwnd, #WM_GETTEXT, bufferSize, *buffer)
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
-
- Enthusiast
- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
Re: How to grab data from non-owned window.
Hi Sparkie. Good to see you are still around.
I may need your code. Right now I am trying to find the handle for these XEdit fields.
Not having much luck at the moment. Need to find something that will report it to me.
netmaestro suggested Greatis Windowse. That looked like it was going to do it, but the handle shown for each item is the same (or I'm looking at the wrong thing).
I may need your code. Right now I am trying to find the handle for these XEdit fields.
Not having much luck at the moment. Need to find something that will report it to me.
netmaestro suggested Greatis Windowse. That looked like it was going to do it, but the handle shown for each item is the same (or I'm looking at the wrong thing).
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: How to grab data from non-owned window.
You're probably looking at the parent handle. You need to identify the control somehow. If you know its classname or x and y or its control id this is all good. Try this approach:
Obtain the parent handle somehow. Use FindWindow_() or such. It will have a different handle each time it runs.
Use EnumChildWindows_() and pass the parent handle, it will call a procedure for each child window it has. Give it a proc in the form:
Then once you have the hwnd, use the line of code Sparkie gave you and you should be good to go.
Obtain the parent handle somehow. Use FindWindow_() or such. It will have a different handle each time it runs.
Use EnumChildWindows_() and pass the parent handle, it will call a procedure for each child window it has. Give it a proc in the form:
Code: Select all
Procedure EnumProc(hwnd, lParam)
; examine the child hwnd you get here to see if it's the one you're looking for
; e.g.
; cn$ = Space(100)
; GetClassname_(hwnd, @cn$, 98)
; is UCase(cn$) = "XEDIT"? etc. and/or test the coords, you have several options
; Once you decide this is your hwnd,
; PokeI(lParam, hwnd)
: ProcedureReturn 0 to stop enumeration
; if not
; ProcedureReturn 1 to continue enumerating child windows
Endprocedure
parenthwnd = FindWindow_(...
EnumChildWindows_(parenthwnd, @EnumProc(), @childhwnd.i)
; now childhwnd has your handle
BERESHEIT
Re: How to grab data from non-owned window.
Here's some old code I dug up. See if it gets you started.
Code: Select all
; ************************************************
; Code: EnumWindows / EnumChildWindows
; Author: Sparkie
; Date: January 30, 2006 (revised a bit on January 29, 2014)
; OS: Windows only
; ************************************************
Enumeration
#TextParent
#ComboBoxParent
#ListChildren
EndEnumeration
#WinMain = 0
Procedure.l enumChildren(hwnd.l, lParam.l)
If hwnd
parentText$ = Space(256)
classText$ = Space(256)
childText$ = Space(256)
childID = GetDlgCtrlID_(hwnd)
GetWindowText_(hwnd, @parentText$, 256)
SendMessage_(hwnd, #WM_GETTEXT, 256, @childText$)
GetClassName_(hwnd, @classText$, 256)
AddGadgetItem(#ListChildren, -1, Str(hwnd) + Chr(10) + Str(childID) + Chr(10) + childText$ + Chr(10) + classText$)
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
Procedure.l enumWins(hwnd.l, lParam.l)
parentText$ = Space(256)
classText$ = Space(256)
If hwnd
; --> Only looking for visible windows with this one
If IsWindowVisible_(hwnd)
childID = GetDlgCtrlID_(hwnd)
GetWindowText_(hwnd, @parentText$, 256)
GetClassName_(hwnd, @classText$, 256)
AddGadgetItem(#ComboBoxParent, 0, Str(hwnd) + " " + parentText$)
EndIf
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
If OpenWindow(#WinMain, 0, 0, 1200, 700, "EnumWindows/ChildWindows", #PB_Window_SystemMenu)
TextGadget(#TextParent, 5, 5, 50, 25, "Parent >>")
ComboBoxGadget(#ComboBoxParent, 60, 5, 500, 25)
ListIconGadget(#ListChildren, 5, 40, 1190, 650, "Child Handle", 100, #PB_ListIcon_FullRowSelect)
AddGadgetColumn(#ListChildren, 1, "ID", 50)
AddGadgetColumn(#ListChildren, 2, "Text", 840)
AddGadgetColumn(#ListChildren, 3, "Class", 200)
; Id all current windows
EnumWindows_(@enumWins(), 0)
SetGadgetState(#ComboBoxParent, 0)
hParent = Val(StringField(GetGadgetText(#ComboBoxParent), 1, " "))
; Id all child windows. This only goes 1 level deep so reuse as needed
EnumChildWindows_(hParent, @enumChildren(), 0)
Repeat
event = WaitWindowEvent()
If EventType() = #PB_EventType_Change And EventGadget() = #ComboBoxParent
ClearGadgetItems(#ListChildren)
hParent = Val(StringField(GetGadgetText(#ComboBoxParent), 1, " "))
EnumChildWindows_(hParent, @enumChildren(), 0)
EndIf
Until event = #PB_Event_CloseWindow
EndIf
End
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
-
- Enthusiast
- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
Re: How to grab data from non-owned window.
Thanks Sparkie! That code was a big help.
It helped me determine that these fields ARE NOT XEdit class at all.
They appear to be Static class, and if you click on the field it overlays it with an XEdit class control. That control then ALWAYS has the same handle and that was certainly confusing.
I'm still lost and haven't been able to extract the data from the Static control. I need to be more adept with the Windows API.
It helped me determine that these fields ARE NOT XEdit class at all.
They appear to be Static class, and if you click on the field it overlays it with an XEdit class control. That control then ALWAYS has the same handle and that was certainly confusing.
I'm still lost and haven't been able to extract the data from the Static control. I need to be more adept with the Windows API.
Re: How to grab data from non-owned window.
Terry, what does Windowse look like when you select the window?
Does it show the text as in this pic?

Does it show the text as in this pic?

What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
-
- Enthusiast
- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
Re: How to grab data from non-owned window.
I'm trying. But, all I get is the children from the screen that launched the one I'm trying to read.
Acts like there are none on this window at all, but there numerous fields on a scroll area.
Acts like there are none on this window at all, but there numerous fields on a scroll area.
Re: How to grab data from non-owned window.
Any chance you can post a more detailed pic (such as mine above) of what you are seeing on your side?
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
-
- Enthusiast
- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
Re: How to grab data from non-owned window.
Check your PM. Let me know if you need more.