The Capture$ function returns the text found in the specified window.
Used to test the content of a window.
Video: How to capture the whole content of a window using Capture$ WinTask function. The SplitIntoArray function is then used to split the long captured string.
<window_name>, string, name of the window to capture. The <window_name> must include the instance number.
<mode>, integer, constant only, sum of three bit flags. The possible values for each bit are:
Bit 0 (weight 1) specifies how the text is captured:
0: the text is captured as a long string without CRLF
1: each line of the text is captured and separated by CRLF
If this bit is set to 0, the two others are set to 0 (so mode=2, 4 and 6 are invalid and an error is returned at compilation).
Bit 1 (weight 2) specifies the font and its size:
0: the font is not captured
1: font and size are captured
Bit 2 (weight 4) specifies the underlined and color of the background attributes:
0: these attributes are not captured
1: these attributes are captured
So <mode> can be:
0: the text is captured as a long string without CRLF and attributes
1: the text is captured as several lines without attributes
3: the text is captured as several lines and font and size are captured
5: the text is captured as several lines, the attributes and the color of background are captured
7: the text is captured a several lines, font, size, attributes and color of background are captured
9: special value, the text is captured inside an emulator software using non-proportional fonts. Use this mode if the other modes ignore some blank fields.
var$, string. It contains the captured text. If <window_name> is not found, or if there is nothing to capture, an empty string is returned (an emty string is "").
Generate the Capture$ syntax using its wizard: in the Language pane of the WinTask Editor, double-click the Capture$ function name to start the wizard (if the Language pane is not displayed, press F4 or select Insert/Statement menu).
Capture$ tries to capture the text in the order in which this text is displayed on the screen.
Capture$ also works with multiline Editboxes, a single-line EditBox, an entire DialogBox or a static control, if you specify the name of this static in the Capture$ parameters. Use it the same way for capturing the text of icons, buttons, listboxes.
Capture$ does NOT capture the text which overflows the window.
If Capture$ returns an empty string whereas there is a displayed text, use Clipboard to retrieve the content of the window. The statements in the script would be:
Pause 5 ticks
'Copy the selection to the Clipboard
Pause 5 ticks
'Retrieve the content of the Clipboard
PERFORMANCE: Capture$ activates a complex analysis process (0.9 second). If you need better performance, you can automate those steps:
select text then copy it into the clipboard (via Ctrl+C) then get its content with GetClipBoard$ function.
With such a WordPad window (launch wordpad.exe located in C:\Program Files (x86)\Windows NT\Accessories):
mode 0 returns:
First line to captureSecond line to captureThird line to capture
mode 1 returns:
First line to capture
Second line to capture
Third line to capture
mode 3 returns:
|X20,Y4,Times New Roman,H15,L133|First line to capture
|X109,Y19,Arial,H16,L65| to capture
|X20,Y35,Courier New,H17,L234|Third line to capture
|Color||R value||G value||B value|
'This script captures the text that you typed into WordPad.
Shell(Chr$(34)+"C:\Program Files (x86)\Windows NT\Accessories\wordpad.exe"+Chr$(34),1)
UseWindow("WORDPAD.EXE|RICHEDIT50W|Document - WordPad") 'UseWindow waits until the wordpad window is displayed
Msgbox("Write some text in WordPad and press F12")
'Wait until F12 has been pressed
MsgBox("Pause at line " + #ErrorLine$ + " has failed !",16,"Runtime error")
' captures the text that you typed in WordPad
text$=Capture$("WORDPAD.EXE|RICHEDIT50W|Document - WordPad",1,1)
msgbox("Your text is : "+text$)