ControlCommand: Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
==Description==
<!-- Autogenerated Wiki Page. See this post for more info: http://www.autoitscript.com/forum/topic/153680-convert-helpfile-to-wiki-text/-->
 
<font face='Segoe UI, Lucida Grande, Verdana, Helvetica, sans-serif'>
 
===<font size='4'><div id='Section' style='color:#DB7100;'>Description</div></font>===
<font size='3' weight='normal'>
Sends a command to a control.
Sends a command to a control.
</font>


<pre>
<div id='Syntax' style='background-color:#FFFFAA;'>
ControlCommand ( "title", "text", controlID, "command" [, "option"] )
:ControlCommand ( "title", "text", controlID, "command" [, "option"] )
</pre>
</div>


==Parameters==
===<font size='4'><div id='Section' style='color:#DB7100;'>Parameters</div></font>===
{| border='1' class='wikitable'
{| class='wikitable'
|-
| title || The title/hWnd/class of the window to access.
| title || The title/hWnd/class of the window to access.
|-
|-
| text || The text of the window to access.
| text || The text of the window to access.
|-
|-
| controlID || The control to interact with.  See [[Controls]]
| controlID || The control to interact with.  See [../intro/controls.htm Controls].
|-
|-
| command || The command to send to the control.
| command || The command to send to the control.
|-
|-
| option || [optional] Additional parameter required by some commands.
| option || '''[optional]''' Additional parameter required by some commands.
|}
|}


==Return Value==
===<font size='4'><div id='Section' style='color:#DB7100;'>Return Value</div></font>===
Depends on command as table below shows.  In case of an error (such as an invalid command or window/control), @error=1.
Depends on command as table below shows.  In case of an error (such as an invalid command or window/control), @error=1.


{| border='1' class='wikitable'
{| class='wikitable'
! scope='col' | '''Command''', '''Option'''
! | '''Command''', '''Option'''
! scope='col' | '''Return Value'''
! | '''Return Value'''
|-
|-
| "IsVisible", "" || Returns 1 if Control is visible, 0 otherwise
| "IsVisible", "" || Returns 1 if Control is visible, 0 otherwise
Line 73: Line 80:
|}
|}


==Remarks==
===<font size='4'><div id='Section' style='color:#DB7100;'>Remarks</div></font>===
Some controls will resist automation unless they are the active window. Use the [[WinActivate]] function to force the control's window to the top before using [[WinActivate]] on these controls.
Some controls will resist automation unless they are the active window. Use the [[WinActivate()]] function to force the control's window to the top before using [[WinActivate()]] on these controls.


Certain commands that work on normal Combo and ListBoxes do not work on "ComboLBox" controls.
Certain commands that work on normal Combo and ListBoxes do not work on "ComboLBox" controls.


==Related==
===<font size='4'><div id='Section' style='color:#DB7100;'>Related</div></font>===
[[ControlTreeView]]
[[ControlClick]], [[ControlDisable]], [[ControlEnable]], [[ControlFocus]], [[ControlGetPos]], [[ControlGetText]], [[ControlHide]], [[ControlMove]], [[ControlSetText]], [[ControlShow]], [[StatusbarGetText]], [[WinActivate]], [[WinMenuSelectItem]], [[WinGetClassList]], [[ControlGetFocus]], [[ControlListView]], [[ControlSend]], [[ControlTreeView]]


==Example==
===<font size='4'><div id='Section' style='color:#DB7100;'>Example</div></font>===
<syntaxhighlight lang='autoit'>
<syntaxhighlight lang='autoit'>
#include <MsgBoxConstants.au3>
#include <MsgBoxConstants.au3>
Line 104: Line 111:
EndFunc  ;==>Example
EndFunc  ;==>Example
</syntaxhighlight>
</syntaxhighlight>
</font>


__NOTOC__
__NOTOC__

Revision as of 18:28, 19 August 2013


Description

Sends a command to a control.

ControlCommand ( "title", "text", controlID, "command" [, "option"] )

Parameters

title The title/hWnd/class of the window to access.
text The text of the window to access.
controlID The control to interact with. See [../intro/controls.htm Controls].
command The command to send to the control.
option [optional] Additional parameter required by some commands.

Return Value

Depends on command as table below shows. In case of an error (such as an invalid command or window/control), @error=1.

Command, Option Return Value
"IsVisible", "" Returns 1 if Control is visible, 0 otherwise
"IsEnabled", "" Returns 1 if Control is enabled, 0 otherwise
"ShowDropDown", "" Displays the ComboBox dropdown
"HideDropDown", "" Hides the ComboBox dropdown
"AddString", 'string' Adds a string to the end in a ListBox or ComboBox
"DelString", occurrence Deletes a string according to occurrence in a ListBox or ComboBox
"FindString", 'string' Returns occurrence ref of the exact string in a ListBox or ComboBox
"SetCurrentSelection", occurrence Sets selection to occurrence ref in a ListBox or ComboBox
"SelectString", 'string' Sets selection according to string in a ListBox or ComboBox
"IsChecked", "" Returns 1 if Button is checked, 0 otherwise
"Check", "" Checks radio or check Button
"UnCheck", "" Unchecks radio or check Button
"GetCurrentLine", "" Returns the line # where the caret is in an Edit
"GetCurrentCol", "" Returns the column # where the caret is in an Edit
"GetCurrentSelection", "" Returns name of the currently selected item in a ListBox or ComboBox
"GetLineCount", "" Returns # of lines in an Edit
"GetLine", line# Returns text at line # passed of an Edit
"GetSelected", "" Returns selected text of an Edit
"EditPaste", 'string' Pastes the 'string' at the Edit's caret position
"CurrentTab", "" Returns the current Tab shown of a SysTabControl32
"TabRight", "" Moves to the next tab to the right of a SysTabControl32
"TabLeft", "" Moves to the next tab to the left of a SysTabControl32
"SendCommandID", Command ID Simulates the WM_COMMAND message. Usually used for ToolbarWindow32 controls - use the ToolBar tab of Au3Info to get the Command ID.

Remarks

Some controls will resist automation unless they are the active window. Use the WinActivate() function to force the control's window to the top before using WinActivate() on these controls.

Certain commands that work on normal Combo and ListBoxes do not work on "ComboLBox" controls.

Related

ControlClick, ControlDisable, ControlEnable, ControlFocus, ControlGetPos, ControlGetText, ControlHide, ControlMove, ControlSetText, ControlShow, StatusbarGetText, WinActivate, WinMenuSelectItem, WinGetClassList, ControlGetFocus, ControlListView, ControlSend, ControlTreeView

Example

#include <MsgBoxConstants.au3>

Example()

Func Example()
	; Run Notepad
	Run("notepad.exe")

	; Wait 10 seconds for the Notepad window to appear.
	Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)

	; Send a command to the edit control of Notepad to find the number of lines. The handle returned by WinWait is used for the "title" parameter of ControlCommand.
	Local $iCount = ControlCommand($hWnd, "", "Edit1", "GetLineCount", "")

	; Display the number of lines.
	MsgBox($MB_SYSTEMMODAL, "", "The number of lines in Notepad are: " & $iCount)

	; Close the Notepad window using the handle returned by WinWait.
	WinClose($hWnd)
EndFunc   ;==>Example