Page 1 of 1

How to grab data from non-owned window.

Posted: Tue Jan 28, 2014 2:47 am
by TerryHough
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

Re: How to grab data from non-owned window.

Posted: Tue Jan 28, 2014 4:59 am
by netmaestro
It would help if you could discover the class of control containing the text. Greatis Windowse or such should help here.

Re: How to grab data from non-owned window.

Posted: Tue Jan 28, 2014 4:05 pm
by TerryHough
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?

Re: How to grab data from non-owned window.

Posted: Tue Jan 28, 2014 5:04 pm
by netmaestro
If you say what the class is...

Re: How to grab data from non-owned window.

Posted: Tue Jan 28, 2014 5:17 pm
by TerryHough
Greatis Windowse reports

Class XEdit

on all of these fields.

Re: How to grab data from non-owned window.

Posted: Wed Jan 29, 2014 9:18 pm
by TerryHough
Here is a screen capture of how the data looks on the non-owned screen that I need to grab the text from.

Image

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

Re: How to grab data from non-owned window.

Posted: Wed Jan 29, 2014 11:13 pm
by Sparkie
If you have the handle to the XEdit control/window, try this.

Code: Select all

SendMessage_(hwnd, #WM_GETTEXT, bufferSize, *buffer)
I do have some old code laying around if you need it. It may take me a while to find it.

Re: How to grab data from non-owned window.

Posted: Wed Jan 29, 2014 11:43 pm
by TerryHough
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).

Re: How to grab data from non-owned window.

Posted: Thu Jan 30, 2014 12:05 am
by netmaestro
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:

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
Then once you have the hwnd, use the line of code Sparkie gave you and you should be good to go.

Re: How to grab data from non-owned window.

Posted: Thu Jan 30, 2014 1:00 am
by Sparkie
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 

Re: How to grab data from non-owned window.

Posted: Thu Jan 30, 2014 6:14 pm
by TerryHough
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.

Re: How to grab data from non-owned window.

Posted: Thu Jan 30, 2014 6:33 pm
by Sparkie
Terry, what does Windowse look like when you select the window?

Does it show the text as in this pic?

Image

Re: How to grab data from non-owned window.

Posted: Thu Jan 30, 2014 8:20 pm
by TerryHough
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.

Re: How to grab data from non-owned window.

Posted: Thu Jan 30, 2014 8:46 pm
by Sparkie
Any chance you can post a more detailed pic (such as mine above) of what you are seeing on your side?

Re: How to grab data from non-owned window.

Posted: Thu Jan 30, 2014 10:25 pm
by TerryHough
Check your PM. Let me know if you need more.