#RequireAdmin
#include <MsgBoxConstants.au3>
_Example()
Func _Example()
Local $hWnd, $hSaveWnd, $hControl, $sTitle1 = "Печать", $sTitle2 = "Сохранить как", $sItem = "SmartDraw"
Local $sCombo = "ComboBox1", $sEdit = "Edit1", $sButton1 = "Button11", $sButton2 = "Button2"
$hWnd = WinWait($sTitle1, Null, 5)
If Not $hWnd Then Exit _Error('Не удалось найти окно "' & $sTitle1 & '"')
$hControl = _ControlWait($hWnd, Null, $sCombo, 5)
If @error Then _Error('Не удалось получить дескриптор элемента управления "' & $sCombo & '"')
ControlCommand($hWnd, Null, $hControl, "SelectString", $sItem)
If @error Then _Error('Не удалось найти пункт "' & $sItem & '"')
$hControl = _ControlWait($hWnd, Null, $sButton1, 5)
If @error Then _Error('Не удалось получить дескриптор элемента управления "' & $sButton1 & '"')
ControlClick($hWnd, Null, $hControl)
$hSaveWnd = WinWait($sTitle2, Null, 5)
If Not $hSaveWnd Then _Error('Не удалось найти окно "' & $sTitle2 & '"')
$hControl = _ControlWait($hSaveWnd, Null, $sEdit, 5)
If @error Then _Error('Не удалось получить дескриптор элемента управления "' & $sEdit & '"')
ControlSetText($hSaveWnd, Null, $hControl, "G:\печать документа\1.pdf")
$hControl = _ControlWait($hSaveWnd, Null, $sButton2, 5)
If @error Then _Error('Не удалось получить дескриптор элемента управления "' & $sButton2 & '"')
ControlClick($hSaveWnd, Null, $hControl)
EndFunc ;==>_Example
Func _ControlWait($vWnd, $sText, $sControl, $iTimeout = 0)
If $iTimeout = Default Then $iTimeout = 0
Local $hControl, $iWait = Opt("WinWaitDelay"), $hTimer = TimerInit()
$iTimeout *= 1000
Do
Sleep($iWait)
$hControl = ControlGetHandle($vWnd, $sText, $sControl)
If $iTimeout And TimerDiff($hTimer) >= $iTimeout Then Return SetError(1, 0, 0)
Until $hControl
Return SetError(0, 0, $hControl)
EndFunc ;==>_ControlWait
Func _Error($sText)
Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "Ошибка", $sText)
EndFunc ;==>_Error