[Solved] Get info from a third party window.

Just starting out? Need help? Post your questions and find answers here.
ZX80
Enthusiast
Enthusiast
Posts: 192
Joined: Mon Dec 12, 2016 1:37 pm

[Solved] Get info from a third party window.

Post by ZX80 »

Hello all.

How can I read the text from the StatusBar? In this case, I'm interested in the standard regedit application. I am currently reading "LastKey" string parameter, but this does not always reflect the current state. It will be changed after a restart. But if you explore the tree, the "LastKey" will not change instantly. I want to know the full path at any moment in time.

Has anyone already done something like this?
Last edited by ZX80 on Sat Sep 04, 2021 6:39 am, edited 1 time in total.
User avatar
chi
Addict
Addict
Posts: 861
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Get info from a third party window.

Post by chi »

Hi, do you mean like this?

Code: Select all

hWnd = FindWindow_(0, "Registry Editor")
hWnd = FindWindowEx_(hWnd, 0, "msctls_statusbar32", 0)

txtlen = SendMessage_(hWnd, #WM_GETTEXTLENGTH, 0, 0) + 1
txt$ = Space(txtlen)

SendMessage_(hWnd, #WM_GETTEXT, txtlen, @txt$)
Debug txt$
Et cetera is my worst enemy
BarryG
Addict
Addict
Posts: 1706
Joined: Thu Apr 18, 2019 8:17 am

Re: Get info from a third party window.

Post by BarryG »

chi wrote: Thu Sep 02, 2021 8:06 pm

Code: Select all

hWnd = FindWindow_(0, "Registry Editor")
What about for non-English PCs? Is there a way to get the hWnd by class or something?
User avatar
chi
Addict
Addict
Posts: 861
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Get info from a third party window.

Post by chi »

BarryG wrote: Fri Sep 03, 2021 1:58 am What about for non-English PCs? Is there a way to get the hWnd by class or something?
You could try...

Code: Select all

hWnd = FindWindow_("RegEdit_RegEdit", 0)
Only tested on Win7 (english)
Et cetera is my worst enemy
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4094
Joined: Sun Apr 12, 2009 6:27 am

Re: Get info from a third party window.

Post by RASHAD »

Code: Select all

Repeat
  hWnd = FindWindow_("RegEdit_RegEdit", 0)
  Delay(1)
  x+1
Until hwnd Or x >= 100
If hWnd
  hWnd = FindWindowEx_(hWnd, 0, "Edit", 0)  
  txt$ = Space(#MAX_PATH)
  SendMessage_(hWnd, #WM_GETTEXT, #MAX_PATH, @txt$)
  Debug txt$
Else
  Debug "RegEdit not found"
EndIf
Egypt my love
BarryG
Addict
Addict
Posts: 1706
Joined: Thu Apr 18, 2019 8:17 am

Re: Get info from a third party window.

Post by BarryG »

Thank you, both!
ZX80
Enthusiast
Enthusiast
Posts: 192
Joined: Mon Dec 12, 2016 1:37 pm

Re: Get info from a third party window.

Post by ZX80 »

Good time everyone and sorry for late reply.

chi, yes, this exactly what I was looking for. Thanks a lot!
Before looking at your second post, I also thought to use classname. This works well and more versatile. Thanks again.

RASHAD, thanks for your answer. Unfortunately, your version does not work for me. Nevertheless, the problem has been solved. Thank you, both!


P.S. I don't need this at the moment, I just thought... complicate the task...

How about statusbar with multiple fields? And I, for example, need to get the text from the second field. For example, in the first, an icon or progressbar will be installed/showed, and in the second, the value of the percentage of process. That is, is further division into parts possible? In other words, each field has its own descriptor. Or does it not work like that? I wonder how to solve this case. Then the topic/question will be more fully disclosed.

Thank you in advance.
User avatar
chi
Addict
Addict
Posts: 861
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Get info from a third party window.

Post by chi »

ZX80 wrote: Fri Sep 03, 2021 7:25 am How about statusbar with multiple fields?
8)

Code: Select all

Global hWndPB

Procedure WinEnum(hWnd, lParam)
  If hWnd
    tmp${10}
    GetWindowText_(hWnd, @tmp$, 10)
    If tmp$ = "PureBasic"
      hWndPB = hWnd
      ProcedureReturn 0
    EndIf
  EndIf
  ProcedureReturn 1
EndProcedure

If EnumWindows_(@WinEnum(), 0)=0 And hWndPB
  hWnd = FindWindowEx_(hWndPB, 0, "msctls_statusbar32", 0)
  If hWnd
    txtlen = SendMessage_(hWnd, #SB_GETTEXTLENGTH, 1, 0) & $FFFF * 2
    If txtlen
      txt$ = Space(txtlen)
      GetWindowThreadProcessId_(hWnd, @pid)
      proc = OpenProcess_(#PROCESS_VM_OPERATION|#PROCESS_VM_READ|#PROCESS_QUERY_INFORMATION, #False, pid)
      *txt = VirtualAllocEx_(proc, #Null, txtlen, #MEM_COMMIT, #PAGE_READWRITE)
      SendMessage_(hWnd, #SB_GETTEXT, 1, *txt)
      ReadProcessMemory_(proc, *txt, @txt$, txtlen, 0)
      VirtualFreeEx_(proc, *txt, txtlen, #MEM_RELEASE)
      CloseHandle_(proc)
      MessageRequester("", txt$)
    EndIf
  EndIf
EndIf
Et cetera is my worst enemy
ZX80
Enthusiast
Enthusiast
Posts: 192
Joined: Mon Dec 12, 2016 1:37 pm

Re: Get info from a third party window.

Post by ZX80 »

chi, thanks a lot for your awesome code :!:

It reminded me of the approach to a third-party SysListView32. There, too, it was necessary to first open a third-party process to gain access to the SysListView32. Is very similar.

Well... The topic is disclosed. Thank you very much.
Post Reply