Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Check text area content of a child window
#1
Hi,

I am trying to check if a chat window (from an application) is empty or not.. I tried to record a macro to find out the text area child control name so that I could check whether or not it has any text in it.

===
int w1=act(win("WaterStrider - Conversation" "QWidget"))
lef+ 336 105 child("qt_scrollarea_viewport" "QWidget" w1) 1
==

Does this mean "qt_scrollarea_viewport" is the name of the text area in that chat window? if yes, how can I check its contents?

Basically what I am trying to do is to run a macro when i recieve an incoming chat but I do not want the macro to be triggered when I am initiating a chat with a user. I thought about this and realized that the only difference would be incoming chats would have a message in it. So if I can check whether the message area (text area) of the chat window is empty, then I can be sure that I am initiating that chat else its an incoming chat (i.e. if the text area is not empty)

Thanks again for your help.
#2
Some controls use different text for their name/text property and for displayed content.

Try floating toolbar dialog "Find image". Capture empty chat area. If the macro will find the empty-area image... else ...

Also try other dialogs from the "Windows, controls" menu of the floating toolbar. Accessible object (possibly the displayed text is its Value property) or Window text.
#3
Thank you. I am trying the following based off your advice:

===
RECT r
int w=win("WaterStrider - Conversation" "QWidget")
scan "image:h74A4C021" child("qt_scrollarea_viewport" "QWidget" w) r 1|2|16
if(scan("image:h74A4C021" w r))
out "x=%i y=%i width=%i height=%i" r.left r.top r.right-r.left r.bottom-r.top
else out "not found"
===

But I am getting an error on line 3
#4
Macro Macro2727
Code:
Copy      Help
RECT r
int w=win("WaterStrider - Conversation" "QWidget")
if(scan("image:h74A4C021" child("qt_scrollarea_viewport" "QWidget" w) r 1|16))
,out "x=%i y=%i width=%i height=%i" r.left r.top r.right-r.left r.bottom-r.top
else out "not found"
#5
Quote:But I am getting an error on line 3
Because in the dialog was checked "Error if not found".
#6
Thank you but this still does not seem to work. The macro always returns "not found" irrespective of the contents of the chat window (whether or not its empty). Is there something that I am doing wrong?

http://prntscr.com/anavws
#7
If the window is behind other windows when the macro runs, in dialog "Find image" check "Window can be in background". Usually better to click it 2 times (it is a 3-state checkbox). Will be faster too.
And in the dialog always click the "Test" button.

Also, may fail to find if there is a blinking text cursor.
#8
Tested with Notepad.

Macro Macro2727
Code:
Copy      Help
RECT r
SetRect &r 8 8 60 60
int w=win("Untitled - Notepad" "Notepad")
act w
if(scan("image:h5EDAC0B1" w r 16|0x1000))
,out "found"
else out "not found"

Says "found" when there is no text. Says "not found" when there is a 1 character. The image is a 50x50 pixel white rectangle.
#9
Also try accessible object functions. Use dialog "Find accessible object" to capture the text area object. Capture when it is with text, to see whether it is possible to get its text. If the dialog does not show text in the "Name" field or in the "Other properties" grid, accessible object functions cannot be used.

Example with Notepad.
Macro Macro2728
Code:
Copy      Help
int w=win("Untitled - Notepad" "Notepad")
Acc a.Find(w "TEXT" "" "class=Edit[]id=15" 0x1004)
str s=a.Value
if s.len
,out s
else
,out "<empty>"
,
#10
Thank you for your continued support.

When I tried your first suggestion it did not work for me (not even with notepad). For some reason it always returns found (whether or not the notepad is empty)

http://prntscr.com/ancf20

Your second suggestion seemed very promising and worked with notepad but did not with my application. It detects the name but the text area shows "".

Note: My chat will have an avatar of the user before the actual message (maybe thats why its not detecting the text).
#11
Need to change rectangle coordinated in the SetRect line. And make sure that it is just several pixels bigger than your captured rectangle. If rectangle not used, scan searches in whole area and therefore always finds. Make so that the rectangle would be at the place where a minimum of text can be displayed, ie several pixels to the right from the icon.

Also try dialog "Window text". Select the control when the control has text, to see whether text capturing works in it.
#12
Function DebugShowRectangle
Code:
Copy      Help
;/
function RECT'r hwnd [double'timeS] [flags] ;;flags: 1 not client area

;Shows a rectangle relative to a window or control.
;By default, relative to the client area.

;r - rectangle.
;hwnd - window/control handle.
;timeS - time in seconds. Default 2.


if hwnd
,if(flags&1) RECT k; GetWindowRect hwnd &k; OffsetRect &r k.left k.top
,else MapWindowPoints hwnd 0 +&r 2

__OnScreenRect osr.SetStyle(0x8000 1)
osr.Show(1 r)
wait iif(timeS timeS 2.0)
osr.Show(2 r)

example
Macro Macro2730
Code:
Copy      Help
;int w=win("WaterStrider - Conversation" "QWidget")
;int c=child("qt_scrollarea_viewport" "QWidget" w)
int w=win("Untitled - Notepad" "Notepad")
int c=id(15 w) ;;editable text
if(!c) end "control not found"

act w

RECT r
SetRect &r 8 8 60 60

DebugShowRectangle r c


Forum Jump:


Users browsing this thread: 1 Guest(s)