I am listing all open windows using WinList() to get window title and -handle in AutoIt.
I want to check if resulting array contains a specific title. What is the best way to do this? There is no WinList().Contains("TitleName") or something like that.
Local $aList = WinList() ;Gets a list of Window Titles and IDs
OK, I got it now:
For $i = 1 To $aList[0][0]
If $aList[$i][0] = "Title/String you search for" Then
MsgBox($MB_SYSTEMMODAL, "", "MessageBox shows this text if title is in list.")
EndIf
Next
You could also use something similar to what you wrote.
#include <Array.au3>
Opt("WinDetectHiddenText", 0) ;0=don't detect, 1=do detect
Opt("WinSearchChildren", 0) ;0=no, 1=search children also
Opt("WinTextMatchMode", 1) ;1=complete, 2=quick
Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Local $title = 'AutoIt Help (v3.3.14.2)'
Local $aList = WinList()
;~ _ArrayDisplay($aList)
Local $iIndex = _ArraySearch($aList,$title)
WinActivate($aList[$iIndex][1], '')
Window exists?
"I am listing all open windows … I want to check if … contains a specific title. What is the best way to do this?"
As per Documentation - Function Reference - WinExists() :
Checks to see if a specified window exists.
Example.
Global Const $g_sWndTitle = 'Window title here'
If WinExists($g_sWndTitle) Then WinFlash($g_sWndTitle)
Retrieve window handle, -text and -title
Handle
"… to get window title and -handle …"
As per Documentation - Function Reference - WinGetHandle() :
Retrieves the internal handle of a window.
Example:
Global Const $g_sWndTitle = 'Window title here'
Global $g_hWnd
If WinExists($g_sWndTitle) Then
$g_hWnd = WinGetHandle($g_sWndTitle)
WinFlash($g_hWnd)
EndIf
Text
As per Documentation - Function Reference - WinGetText() :
Retrieves the text from a window.
Example:
Global Const $g_sWndTitle = 'Window title here'
If WinExists($g_sWndTitle) Then
WinFlash($g_sWndTitle)
ConsoleWrite(WinGetText($g_sWndTitle) & #CRLF)
EndIf
Title
Likewise, WinGetTitle().
Related
Since a Label in a PopupMenuItem, I thinks it can be set a pango text here.
PopupMenuItem: A PopupBaseMenuItem that displays text in a St.Label.
const item = new PopupMenu.PopupMenuItem("");
item.actor.set_size(300,150); <--- effect.
item.actor.create_pango_layout('<span foreground="blue" size="32">fname</span>'); <- not effect
item.actor.set_markup('<span foreground="blue" size="32">fname</span>'); <-- fail, but it worked in vala.
I read popupMenu.js source code before, but now I forgot the url.
You probably want to set this on the internal Clutter.Text of the PopupMenu.PopupMenuItems's St.Label:
const item = new PopupMenu.PopupMenuItem('');
item.label.clutter_text.set_markup(
'<span foreground="blue" size="32">fname</span>');
You can bookmark this link to the whole directory of GNOME Shell's UI:
https://gitlab.gnome.org/GNOME/gnome-shell/tree/main/js/ui
I'm using AutoIt and SciTE to create an installation script. The problem I am running into is that there is a tree menu for selection of features. I can select the whole treeview (SysTreeView32), but am not sure how to get inside it to check the boxes without doing a mouse move and click (not a great option).
The Treeview looks like this:
The Control Info from AutoIT is like this:
I'm sure it is possible, just can't figure out how to do it. This is my first attempt a such a script. Creating a response file does not work for this exe for some reason. So - this appears to be my only way out to create a somewhat silent install (not silent anymore, but at least automated).
* EDIT - Current State of Things *
I did figure out how to do some of this, but I still can't figure out if the items is selected before accessing it. So - since it toggles, I could be turning off a feature I want!
$hWnd = WinWaitActive($WindowTitle, 'Select Features')
$tvCtl = ControlGetHandle($WindowTitle, '', 'SysTreeView321')
$firstItem = _GUICtrlTreeView_FindItem($tvCtl, 'eBooks')
_GUICtrlTreeView_SelectItem($tvCtl, $firstItem, $TVGN_FIRSTVISIBLE)
_GUICtrlTreeView_ClickItem($tvCtl, $firstItem, "left", True, 1)
Send('{SPACE}')
I wouldn't think I would have to send the space since I sent the ClickItem, but seems so.
I could also do this:
ControlTreeView($hWnd, '', $tvCtl, 'Select', '#0')
ControlSend($hWnd, '', $tvCtl, ' ')
That will toggle the first one. So - i can count them all up and do it that way.
But when I check for "IsEnabled" or "IsChecked", it always says NO. So - I can't check the ones I need only. I have to hope their status is what I expect.
Here is how I am checking "IsChecked" and "IsEnabled":
If ControlCommand($hWnd, '', $logTool, 'IsEnabled') then
ConsoleWrite('Log Tool - IsEnabled' & #CRLF)
Else
ConsoleWrite('Log Tool - NOTEnabled' & #CRLF)
EndIf
and
If ControlCommand($hWnd, '', $logTool, 'IsChecked') then
ConsoleWrite('Log Tool - IsChecked' & #CRLF)
Else
ConsoleWrite('Log Tool - NOTChecked' & #CRLF)
EndIf
It always comes back NOTEnabled and NOTChecked. I made sure that I ran the same procedure above: FindItem, SelectItem, ClickItem. And, the correct item is highlighted/selected when this procedure is run - I can see that. So - it just isn't returning a proper value.
Opt('WinTitleMatchMode', 2)
$hWnd = WinGetHandle("InstallShield Wizard") ; Notice the correct title
$hTree = ControlGetHandle($hWnd, '', "[CLASS:SysTreeView32;INSTANCE:1]")
; == Now you can interact with the treeview with functions from "GuiTreeView.au3"
EDIT:
Try this
; Select the item so:
_GUICtrlTreeView_SelectItem($hTree, $hItem, $TVGN_CARET)
; Get checked state:
_GUICtrlTreeView_GetChecked($hTree, $hItem)
For more deatails read the AutoIt help.
The UI is as following:
The tool "AutoIt Window Info" can only locate the elements in red (red rectangle area), the sub items can not be located.
So how can I expand or operate these items?
Usually Windows controls can be accessed using keystrokes as well.
In the screen-dump the Farmtt element is selected. That would be your starting point.
You may try:
Send("{DOWN}") Move down an element.
Send("{TAB}") Navigate to next control (button, checkbox, etc)
Send("{NumPadMult}") Recursively expands folders in a SysTreeView32.
Send("{ENTER}") ENTER key on the main keyboard
etc.
Reference:
https://www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm
There are two things over here:
1) Use the following code snippet:
;Gets the handle for the text
Func readFirstlevelTreeNodes($hWndCtrl)
Local $firstItemHandle = _GUICtrlTreeView_GetFirstItem ($hWndCtrl)
Local $iCount = _GUICtrlTreeView_GetSiblingCount( $hWndCtrl, $firstItemHandle )
Dim $aRet[$iCount]
$aRet[0] = $firstItemHandle
For $index = 1 To $iCount - 1
$aRet[$index] = _GUICtrlTreeView_GetNextSibling ( $hWndCtrl, $firstItemHandle )
$firstItemHandle = $aRet[$index]
Next
getTreeNodeTextList($hWndCtrl,$aRet)
EndFunc
; Gets the text for given sibling node handle lists
Func getTreeNodeTextList($hWndCtrl,$aRet)
ConsoleWrite("Tree Node first level list"&#CRLF)
For $index = 0 To Ubound($aRet) -1
ConsoleWrite(_GUICtrlTreeView_GetText ( $hWndCtrl, $aRet[$index] )&#CRLF)
Next
EndFunc
You may see the output for the first level tree nodes.
2) If you still dont see the output then please verify the control handle values and window handles. If they are correct and it still doesnt show the first level tree nodes then try running your sciTE editor as administrator.
I think this should help.
Instead of returning the currect selected font, it returns 0.
ShellExecute("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("!O")
Send("F")
WinWaitActive("Font")
$select = ControlCommand("Font", "", "[CLASS:ComboLBox; INSTANCE:1]", "GetCurrentSelection", "")
MsgBox(0,"", $select)
That control is actually a "Combo L Box", not a ComboBox. As the AutoIt helpfile says under ControlCommand:
Certain commands that work on normal Combo and ListBoxes do not work
on "ComboLBox" controls.
The ComboLBox is actually a child control of the ComboBox, and is just the drop down part of it. If you use a more advanced window finder like Spy++, you will actually see there is a ComboBox there, with two children (an Edit and the ComboLBox). So your code will work if you change "[CLASS:ComboLBox; INSTANCE:1]" to "[CLASS:ComboBox; INSTANCE:1]".
Furthermore, you can improve your code for triggering the menu item, so that the entire operation can be done in the background.
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Local $IDM_FONT = 33
Local $hWindow = WinGetHandle("Untitled - Notepad")
_WinAPI_PostMessage($hWindow, $WM_COMMAND, $IDM_FONT, 0)
Local $hFontWin = WinWait("Font")
$select = ControlCommand($hFontWin, "", "ComboBox1", "GetCurrentSelection", "")
WinClose($hFontWin)
MsgBox(0,"", $select)
Alternatively, you can interact with the ComboLBox in the same way you would a listbox:
$hLBox = ControlGetHandle($hFontWin, "", "ComboLBox1")
$itemIndex = _GUICtrlListBox_GetCurSel()
$select = _GUICtrlListBox_GetText($hLBox, $itemIndex)
Why ControlCommand doesn't work with this particular type of list box I have no idea. I can only guess that internally they check the control class against "ComboBox" and "ListBox" and return zero if there is no match.
You can use ControlGetText() to read the name of the currently active font, if this is what you want to accomplish.
ShellExecute("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("!O")
Send("F")
WinWaitActive("Font")
$select = ControlGetText("Font", "", "Edit1")
MsgBox(0,"", $select)
I'm facing difficulty when creating some kind of a report in vfp. I created a text file, used the ?/?? command to write to the file, then opened it using web browser (OLE Object in vfp form).
Set Printer To 'C:\temp\test.txt'
set printer on
set console off
?? 'test'
and then i called my prg :
PARAMETERS pUrl
lcURL = pUrl
PUBLIC oForm
oForm = CREATEOBJECT('IEForm')
oForm.SHOW()
oForm.oIE.Navigate2(m.lcURL)
READ events
DEFINE CLASS IEForm AS FORM
CAPTION = 'Report Preview'
HEIGHT = 512
WIDTH = 792
AUTOCENTER = .t.
ADD OBJECT oIE AS OLECONTROL WITH ;
HEIGHT=512,WIDTH=792,OLECLASS="Shell.Explorer",ANCHOR=195
PROCEDURE oIE.REFRESH
NODEFAULT
ENDPROC
ENDDEFINE
and used the C:\temp\test.txt as the url.
This works fine. But the problem occurs when I use fcreate to create the text file( not using the already existing text file)
lcfile ='C:\temp\'+SYS(2015)+'.txt'
lchandle=FCREATE(lcfile)
Set Printer To lcfile
sometimes the problem occurs when using ? ( resulting in blank doc), and sometimes the browser can't navigate to the file.
The second problem is : the browser can't navigate to the text file if i set the windowtype property to modal in the IEform. I need to set it modal because I have to delay the rest of the execution until the preview form is closed.
I hope I described the situation clear enough.
Thank You for helping Me :)
I would avoid using SET PRINTER TO, and just use the fcreate(), fwrite() and fclose(), especially if writing a large amount of text. If only writing a small amount of data, I would just build one long string by just appending each component to the prior and add cr/lf instead of "?" for new lines, then write the entire result to a file ONCE via StrToFile(). This way, you don't have to worry if things are actually closed (if you dont clear the set printer off, set printer to, or fclose(). Being an incomplete file, the browser won't navigate since the file handle may be "locked" to read anything.
Option 1 -- building a string
lcCRLF = chr(13)+chr(10)
lcMyOutput = "Some Text to Start with" + lcCRLF ;
+ "Today is: " + dtoc( date() ) + lcCRLF
use SomeTable
scan
lcMyOutput = lcMyOutput + "Some Field: " + SomeCharField;
+ "A numeric field: " + transform( SomeNumberField, "999,999.99" ) + lcCRLF
endscan
lcMyOutput = lcMyOutput + "All Done"
lcOutputFile = "C:\Temp\" + sys(2015) + ".txt"
StrToFile( lcMyOutput, lcOutputFile )
Option 2 -- using fcreate(), fwrite(), fclose()
lnHandle = 0
do while .t.
lcOutputFile = "C:\Temp\" + sys(2015) + ".txt"
lnHandle = fcreate( lcOutputFile )
*/ Only get out if we have a proper handle and thus
*/ we are exclusive to it for duration of our process
if( lnHandle > 0 )
exit
endif
enddo
lcCRLF = chr(13)+chr(10)
fwrite( lnHandle, "Some Text to Start with" + lcCRLF ;
+ "Today is: " + dtoc( date() ) + lcCRLF )
use SomeTable
scan
fwrite( lnHandle, "Some Field: " + SomeCharField;
+ "A numeric field: " + transform( SomeNumberField, "999,999.99" ) + lcCRLF )
endscan
fwrite( lnHandle, "All Done" )
fclose( lnHandle )
For running your "batch" file attempt with the RUN command, build the WHAT you want into a string, then run that... ex:
lcCommandToRun = '"' + sys(5) + sys(2003) + '\Compress.tzs"'
run ( lcCommandToRun )
I don't know if it was failing due to a space being in the path of your sys(2003) result turning the RUN into a multi-parameter interpretation, it would fail. By wrapping the entire text within double-quotes, it will prevent such "path" issue.
ADDITIONAL FEEDBACK
Trying to simulate a preview of a DOT-matrix printer using "?" to a text file is not something I would try. I would just do a standard report and draw it with all the data you are doing manually with the "?". If the user want's to preview the report, or send to a laser printer, let the normal report version handled through Windows for generation, font, and such do it for you. Leave the ancient code going to dot-matrix with whatever specific font rendering code as you have. I would just keep the actual report version CLOSE TO your "?" version.