The MASM Forum

General => The Campus => Topic started by: x64Core on October 01, 2013, 05:56:34 PM

Title: Problem gettting child window caption
Post by: x64Core on October 01, 2013, 05:56:34 PM
hello guys im not able to get the caption of a child window, check spy does:
(http://img43.imageshack.us/img43/9177/q43j.png)
I wan to get:
masm32.com/board/index.php
my code:


.586
.model flat,stdcall
include masm32rt.inc
.data
class1 db "Chrome_WidgetWin_1",0
subw db "Chrome_OmniboxView",0
.code
Start proc

    invoke FindWindow,addr class1,0
    invoke FindWindowEx,eax,0,addr subw,0
    ; eax = zero
Ret
Start EndP
End Start

EAX equal to zero, im not able to figure out the problem, any help please

Title: Re: Problem gettting child window caption
Post by: TWell on October 01, 2013, 06:29:53 PM
Both windows are in same level.
"Chrome_OmniboxView" isn't child of "Chrome_WidgetWin_1" ?
EDIT:
Test with IronPortable:
"Chrome_OmniboxView" is child of "Chrome_WidgetWin_1"
SendMessage with WM_GETTEXT works.
Title: Re: Problem gettting child window caption
Post by: x64Core on October 01, 2013, 06:42:18 PM
Quote from: TWell on October 01, 2013, 06:29:53 PM
Both windows are in same level.
"Chrome_OmniboxView" isn't child of "Chrome_WidgetWin_1" ?
nope, calling FindWindow plus Chrome_OmniboxView string doesnt work.

Added:
also, I tried by calling EnumWindow or EnumChildWindow and no function was able to get the string...
Title: Re: Problem gettting child window caption
Post by: sinsi on October 01, 2013, 07:53:54 PM
Try FindWindow with lpClassName=null and lpWindowName=masm32.com/board/index.php
Title: Re: Problem gettting child window caption
Post by: dedndave on October 01, 2013, 10:36:22 PM
lpClassName=NULL
lpWindowName=>"masm32.com/board/index.php"
Title: Re: Problem gettting child window caption
Post by: x64Core on October 02, 2013, 03:36:16 AM
The problem is, I cannot get handle from title,  because it will change constantly
Class is ok as it will not change never in the program.

program is google chrome. its very strange, I tried a lot of things  :icon_eek:
Title: Re: Problem gettting child window caption
Post by: TWell on October 02, 2013, 03:51:23 AM
EDIT: The class "Chrome_OmniboxView" was removed in newer versions.
Title: Re: Problem gettting child window caption
Post by: x64Core on October 02, 2013, 04:05:07 AM
TWell , your code shows me nothing, it does not find Chrome_OmniboxView class. is it working for you?
My google version is: Version 28.0.1500.95 m
Title: Re: Problem gettting child window caption
Post by: dedndave on October 02, 2013, 06:14:53 AM
if it is a child window, you want to use FindWindowEx
FindWindow is for top-level windows
to use FindWindowEx, you need the handle of the parent window

so...
    .DATA
szParentClass db '????',0
szChildClass  db '????',0

    .CODE
    INVOKE  FindWindow,offset szParentClass,NULL
    .if eax
        INVOKE  FindWindowEx,eax,NULL,offset szChildClass,NULL
    .endif


now - you may have multiple instances of chrome
i will let you deal with that one, as i don't have it installed   :P
Title: Re: Problem gettting child window caption
Post by: x64Core on October 02, 2013, 06:22:13 AM
Quote from: TWell on October 02, 2013, 03:51:23 AMEDIT: The class "Chrome_OmniboxView" was removed in newer versions.
If so how does spy do to get string, i dont think so  :icon_eek:

@dedndave:
Check my post #1 I did so, but for some reason findWindowEx doesnt work but spy is able to get string.

I dont understand how the # spy is able to get string

I tried with several programs:
(http://img593.imageshack.us/img593/4844/g4to.png)

WinInspector is able to do it as well.

Edit # = Profanity



Title: Re: Problem gettting child window caption
Post by: dedndave on October 02, 2013, 07:12:40 AM
ok - there are a few complications that you may be running into

first - the window may be a UNICODE window - with a UNICODE class name
you should be able to look at the window properties under spy++ to see
i haven't had much experience here, but it's a possibility

secondly, under windows 7, some child windows/controls are isolated by a worker window
these windows seem to be all over the place if you use the aero glass theme
sometimes, these windows have "shell" and/or "dll" in the names
but - i think spy++ will spot those windows

otherwise - check the windows properties carefully for style bits - etc
anything unusual that might make them hard to find
i could be more help if i were using the same OS and chrome
but - i use XP and firefox   :P

if all else fails, you should be able to get the parent handle and enumerate all child windows to find it
Title: Re: Problem gettting child window caption
Post by: dedndave on October 02, 2013, 07:16:58 AM
question - are you able to get the parent handle with FindWindow ???
display it in a MessageBox to verify it is non-zero
Title: Re: Problem gettting child window caption
Post by: x64Core on October 02, 2013, 07:28:57 AM
Quote from: dedndave on October 02, 2013, 07:16:58 AM
question - are you able to get the parent handle with FindWindow ???
display it in a MessageBox to verify it is non-zero
It is assumed that the parent is Chrome_WidgetWin_1 class, FindWindow finds it but FindWindowEx doesnt find the child (Chrome_OmniboxView). I will debug Spy++ to know how it works.

Title: Re: Problem gettting child window caption
Post by: dedndave on October 02, 2013, 07:35:55 AM
i would think spy++ uses EnumChildWindows
Title: Re: Problem gettting child window caption
Post by: x64Core on October 02, 2013, 07:47:35 AM
Quote from: dedndave on October 02, 2013, 07:35:55 AM
i would think spy++ uses EnumChildWindows
Yeah I think so, but it doesn work.
I tried EnumWindows plus EnumChildWindow as I said inabove posts :P
Title: Re: Problem gettting child window caption
Post by: dedndave on October 02, 2013, 08:05:54 AM
(http://img593.imageshack.us/img593/4844/g4to.png)

perhaps, when you ran EnumChildWindows, you were running it on the wrong parent handle
i see 2 "Chrome_WidgetWin_1" windows - one has no children - one does

you can run EnumWindows - filter out only parent Chrome_WidgetWin_1 windows
then, when you find one of those - call EnumChildWindows on it

i will get back to you in an hour or so with a program to try - have to take care of something   :P
Title: Re: Problem gettting child window caption
Post by: dedndave on October 02, 2013, 08:40:47 AM
quick and dirty
let me know if it works   :biggrin:
Title: Re: Problem gettting child window caption
Post by: x64Core on October 02, 2013, 08:59:45 AM
Not working :
(http://img94.imageshack.us/img94/9226/e2hr.png)

Even, I tried enumerating all windows on the system:


.586
.model flat,stdcall
include masm32rt.inc

.data
sparentcls db "PARENT > class: %ls ",0ah,0
sparenttit db "PARENT > title: %ls ",0ah,0

schildcls db "    #CHILD > class: %ls",0ah,0
schildtit db "    #CHILD > title: %ls",0ah,0
.code

getchilds proc hwnd:HWND,lparam:LPARAM
    LOCAL classname[200*1]:WORD
    LOCAL mtitle[200*5]:WORD
   
    invoke GetClassNameW,hwnd,addr classname,sizeof classname
    invoke GetWindowTextW,hwnd,addr mtitle,sizeof mtitle
   
    lea eax,classname
    push eax
    push offset schildcls
    call crt_printf
    add esp,sizeof(DWORD) * 2
   
   
    lea eax,mtitle
    push eax
    push offset schildtit   
    call crt_printf
    add esp,sizeof(DWORD) * 2
   
    mov eax,1
    ret

getchilds endp


getparents proc hwnd:HWND,lparam:LPARAM
   
    LOCAL classname[200*1]:WORD
    LOCAL mtitle[200*5]:WORD
    LOCAL written:DWORD
    LOCAL h:HANDLE
   
    invoke GetClassNameW,hwnd,addr classname,sizeof classname
    invoke GetWindowTextW,hwnd,addr mtitle,sizeof mtitle
   
    lea eax,classname
    push eax
    push offset sparentcls
    call crt_printf
    add esp,sizeof(DWORD) * 2
   
   
    lea eax,mtitle
    push eax
    push offset sparenttit   
    call crt_printf
    add esp,sizeof(DWORD) * 2
   
    ; get childs
    invoke EnumChildWindows,hwnd,offset getchilds,0   
   
    mov eax,1
    ret   

getparents endp

Start proc
   
    invoke EnumWindows,offset getparents,0
    int 3 ; break
   
Ret
Start EndP
End Start


string is empty

Parent string is ok
child string is empty:

(http://img21.imageshack.us/img21/7679/yhsb.png)

Title: Re: Problem gettting child window caption
Post by: x64Core on October 02, 2013, 09:55:17 AM
Resolved guys lol use Sendmessage
Looks like the GetWindowText function has problems getting the string:
http://blogs.msdn.com/b/oldnewthing/archive/2003/08/21/54675.aspx
---
thank yall for your time, thanks dave   :t
Title: Re: Problem gettting child window caption
Post by: hutch-- on October 02, 2013, 10:18:14 AM
Write an enumeration callback as Dave suggested then be willing to scan parts of the data for each application instance to find data that indicates that it is Chrome.
Title: Re: Problem gettting child window caption
Post by: dedndave on October 02, 2013, 11:12:07 AM
i made a mistake on GetWindowText, actually
i only print the result if EAX is non-zero - just like GetClassName   :redface:

well - GetWindowText isn't the same as GetClassName
i was in a hurry - what can i say - at least it put you on the right track

see if this one is a little better....

in the end - may be better to use WM_GETTEXT   :t

EDIT: i went ahead and switched to WM_GETTEXT
i also cleaned up the output text format a little
Title: Re: Problem gettting child window caption
Post by: x64Core on October 02, 2013, 02:36:56 PM
Quote from: dedndave on October 02, 2013, 11:12:07 AM
i made a mistake on GetWindowText, actually
i only print the result if EAX is non-zero - just like GetClassName   :redface:

well - GetWindowText isn't the same as GetClassName
i was in a hurry - what can i say - at least it put you on the right track

see if this one is a little better....

in the end - may be better to use WM_GETTEXT   :t

EDIT: i went ahead and switched to WM_GETTEXT
i also cleaned up the output text format a little
mmm... I dont think so, GetWindowText is not working in actually, it returns an empty string, idk why but doesnt work.
SendMessage is working quite fine :P check it
Title: Re: Problem gettting child window caption
Post by: TWell on October 02, 2013, 04:08:38 PM
Some tests with Dave's program in Win 7

Version 29.0.1547.76 m

Parent Handle: 000301A2
Parent Handle: 000301A4
  Chrome_WidgetWin_0 , The MASM Forum - Index
  Chrome_RenderWidgetHostHWND
  CompositorHostWindowClass
Parent Handle: 00020182
Parent Handle: 0009015C

Version 30.0.1599.66 m

Parent Handle: 001502EA
Parent Handle: 00070162
  Chrome_WidgetWin_0 , The MASM Forum - Index
  Chrome_RenderWidgetHostHWND
  CompositorHostWindowClass
Parent Handle: 000601A6
Parent Handle: 000B0188

IronPortable
Version 29.0.1600.1 (220100)

Parent Handle: 000506CA
Parent Handle: 00060644
  Chrome_WidgetWin_0 , The MASM Forum - Index
  Chrome_RenderWidgetHostHWND
Parent Handle: 00040664
Parent Handle: 00080674

So no more class "Chrome_OmniboxView"
Title: Re: Problem gettting child window caption
Post by: jj2007 on October 02, 2013, 04:53:21 PM
Quote from: x64Core on October 02, 2013, 09:55:17 AM
Looks like the GetWindowText function has problems getting the string:
http://blogs.msdn.com/b/oldnewthing/archive/2003/08/21/54675.aspx

Looks familiar (http://www.masmforum.com/board/index.php?topic=18489.msg156383#msg156383) ;-)
The main problem here is that GetWindowText is no good for kids of other parents, while SendMessage works fine in general but may hang (see "What if I don't like these rules?" in Raymond Chen's blog quoted above). The only reliable solution (used for Win$() (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1090)) is to use SendMessageTimeout with a timeout of e.g. 100 ms (of which 50 µs are typically needed).

In 32-bit versions of Windows, beware of asking for the text of kids in 16-bit processes: an exception will occur, and AFAIK there is no workaround.
Title: Re: Problem gettting child window caption
Post by: hutch-- on October 02, 2013, 05:07:54 PM
TWell,

Have a look at a MASM32 example in version 11 called "enumwin.exe" in the enumerate directory of examples. Run Chrome, then start "enumwin.exe" then see what the class name, handle and window caption text is.
Title: Re: Problem gettting child window caption
Post by: TWell on October 02, 2013, 05:49:07 PM
It isn't there. ("Chrome_OmniboxView" is removed from newer versions)

Such as:
IronPortable Version 29.0.1600.1 (220100)
Title: Re: Problem gettting child window caption
Post by: hutch-- on October 02, 2013, 08:07:25 PM
I am running Version 27.0.1500.0 (201000) of Iron Portable and it shows up fine. Note though that this is one my older XP SP3 box.

You may find that they (the developers of Iron) don't want it to be easily found by other programs.
Title: Re: Problem gettting child window caption
Post by: x64Core on October 04, 2013, 05:14:09 AM
my chrome is 28.0.1500.95 m and its working
BTW, nice information jj, thank you


added:
I just updated my chrome to: Version 30.0.1599.66 m
not working anymore lol
any alternative, guys?  injection  :P