Что нового

Получение значения из TProgressBar в сторонних программах

MEXAH

What if?
Сообщения
28
Репутация
1
Пожалуйста, приведите пример как можно получить значение текущего прогресса из такого прогресс-бара:

Запутался в
Код:
_GUICtrlSlider_GetPos
в инструкции сказано нужно вставить дексриптор или идентификатор элемента, TProgressBar1 - явно не подходит.
Код:
MsgBox(0, '', _GUICtrlSlider_GetPos("попрыгун 3.fb2.txt - ABoo","TProgressBar1")

Так тоже не получается.
Код:
MsgBox(0, " ", _GUICtrlSlider_GetPos(460682))

а так выдает 0
 

Tempo

AutoIT Гуру
Сообщения
616
Репутация
205
Код:
#include <ProgressConstants.au3>
#include <MsgBoxConstants.au3>
#include <SendMessage.au3>
Opt("WinTitleMatchMode", -2)

Local $hProgress = ControlGetHandle(" - ABoo", "", "[CLASS:TProgressBar; INSTANCE:1]")
MsgBox($MB_ICONINFORMATION + $MB_TOPMOST, "Пример", _GUICtrlProgress_GetPos($hProgress))

Func _GUICtrlProgress_GetPos($hWnd)
	If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
	Local $iRet = _SendMessage($hWnd, $PBM_GETPOS, 0, 0, 0, "wparam", "lparam", "uint")
	Return SetError(@error, @extended, $iRet)
EndFunc   ;==>_GUICtrlProgress_GetPos
 
Автор
MEXAH

MEXAH

What if?
Сообщения
28
Репутация
1
hwm9699g.jpg

а как перевести значение этой линейки в проценты?
 

Tempo

AutoIT Гуру
Сообщения
616
Репутация
205
Код:
#include <ProgressConstants.au3>
#include <MsgBoxConstants.au3>
#include <TrayConstants.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>
#include <Memory.au3>
Opt("WinTitleMatchMode", -2)
Opt("TrayAutoPause", 0)

Global $hLastWnd
Global Const $tagPBRANGE = "int iLow;int iHigh"

Global $hProgress, $iTemp, $iCurr

While Sleep(10)
	$hProgress = ControlGetHandle(" - ABoo", "", "[CLASS:TProgressBar; INSTANCE:1]")
	If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "Пример", "Окно не найдено")

	$iTemp = _GUICtrlProgress_GetPercent($hProgress)
	If $iTemp <> $iCurr Then
		$iCurr = $iTemp
		TrayTip("Пример", $iCurr & "%", 10, $TIP_ICONASTERISK)
	EndIf
WEnd

Func _GUICtrlProgress_GetPercent($hWnd)
	If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
	Local $aRange = _GUICtrlProgress_GetRange($hWnd)
	Local $iPerc = ($aRange[0] + $aRange[1]) / 100
	Return Int(_GUICtrlProgress_GetPos($hWnd) / $iPerc)
EndFunc   ;==>_GUICtrlProgress_GetPercent

Func _GUICtrlProgress_GetPos($hWnd)
	If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
	Local $iRet = _SendMessage($hWnd, $PBM_GETPOS, 0, 0, 0, "wparam", "lparam", "uint")
	Return SetError(@error, @extended, $iRet)
EndFunc   ;==>_GUICtrlProgress_GetPos

Func _GUICtrlProgress_GetRange($hWnd)
	If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
	Local $tPBRANGE = DllStructCreate($tagPBRANGE)
	If _WinAPI_InProcess($hWnd, $hLastWnd) Then
		_SendMessage($hWnd, $PBM_GETRANGE, False, $tPBRANGE, 0, "wparam", "struct*")
	Else
		Local $iSize = DllStructGetSize($tPBRANGE), $tMemMap
		Local $pMemory = _MemInit($hWnd, $iSize, $tMemMap)
		_SendMessage($hWnd, $PBM_GETRANGE, False, $pMemory, 0, "wparam", "ptr")
		_MemRead($tMemMap, $pMemory, $tPBRANGE, $iSize)
		_MemFree($tMemMap)
	EndIf
	Local $aRet[2] = [DllStructGetData($tPBRANGE, "iLow"), DllStructGetData($tPBRANGE, "iHigh")]
	Return SetError(@error, @extended, $aRet)
EndFunc   ;==>_GUICtrlProgress_GetRange
 
Автор
MEXAH

MEXAH

What if?
Сообщения
28
Репутация
1
Верх