http://autoitscript.fr/forum/viewtopic. ... 744#p44744
Bonjour,
Etant newbies avec AutoIt je cherche depuis quelques jours la fonction qui me permettrai de récupérer
le contenu de cmd.exe et de l'injecter dans mon application sous forme de variable.
L'envoi est possible et sans problèmes grâce à ce code:
► Afficher le texte
Code : Tout sélectionner
#NoTrayIcon
; Change into the WinTitleMatchMode that supports classnames and handles
AutoItSetOption("WinTitleMatchMode", 4)
AutoItSetOption("WinSearchChildren", 1)
; Get the handle of a cmd.exe window (from its classname)
$handle = WinGetHandle("classname=ConsoleWindowClass", "")
If @error Then
MsgBox(4096, "Error", "Could not find the correct window")
Else
; get the string from commandline
$Param=$CmdLine[1]
; get the length of obtained string
$Param_Len=StringLen($Param)
; activate the cmd.exe window
WinActivate($handle, "")
; send the parametr to cmd.exe via Send command
For $i = 1 to $Param_Len
$CharSend=StringMid($Param,$i,1)
Send($CharSend)
Next
Send("{ENTER}")
EndIfMMBLib.au3
► Afficher le texte
Code : Tout sélectionner
; Rewritten by Yuraj, originally by Odklizec
#include-once
#include <SendMessage.au3>
#Include <Memory.au3>
Global Const $WM_RUNSCRIPTCODE = 0x08C7
Global Const $RUNSCRIPTCODE_LOUD = 0
Global Const $RUNSCRIPTCODE_QUIET = 1
Local $iItem, $pMemory, $tMemMap, $pText,$pid
Func SendScriptMMB($title,$script)
; get handle of MMB window
$hwnd = WinGetHandle($title)
if @error Then
;~ MsgBox(48,"","Can't find window with title " & $title)
exit
endif
$slen = stringlen($script) +1
$str = "char[" & $slen & "]"; structure item must be "char"
$struct= DllStructCreate($str); create a struct for the string so we can get a pointer to it
if @error Then
;~ MsgBox(0,"","Error in DllStructCreate " & @error)
exit
endif
$iItem = DllStructGetSize($struct); get structure size
$pMemory = _MemInit($hwnd, $iItem, $tMemMap); init memory and return pointer to initialized memory in target app
DllStructSetData($struct, 1, $script); set string to structure
$pointer = DllStructGetPtr($struct,1); pointer to string in structure
_MemWrite($tMemMap, $pointer, $pMemory, $iItem); write string pointer to application memory
_SendMessage($hwnd,$WM_RUNSCRIPTCODE,$RUNSCRIPTCODE_LOUD,$pMemory)
If @error Then
;~ MsgBox(0,"", "_SendMessage Error: " & @error)
Exit
EndIf
_MemFree($tMemMap);release the memory
EndFuncMPlayerController.au3
► Afficher le texte
Code : Tout sélectionner
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=GenericMovie.ico
#AutoIt3Wrapper_Outfile=try\MPlayerController.exe
#AutoIt3Wrapper_Compression=0
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Comment=MPlayerController by xAx Company
#AutoIt3Wrapper_Res_Description=MPlayerController
#AutoIt3Wrapper_Res_Fileversion=0.6.0.0
#AutoIt3Wrapper_Res_LegalCopyright=xAx
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------
AutoIt Version: v3.3.0.0
Author: Abduljabbar Faaiz (xAx Company)
Script Function:
MPlayer Controller.
Copyright 2009, 20010 Abduljabbar Faaiz
The Program is distributed under the terms of the GNU General Public License v3
#ce ----------------------------------------------------------------------------
#include<Constants.au3>
#include<GUIConstantsEx.au3>
#include<WindowsConstants.au3>
#include <MMBLib.au3>
#include <WinAPI.au3>
If Not IsDeclared("WM_LBUTTONDOWN") Then Global Const $WM_LBUTTONDOWN = 0x0201
If Not IsDeclared("WM_LBUTTONDBLCLK") Then Global Const $WM_LBUTTONDBLCLK = 0x0203
If Not IsDeclared("GCL_STYLE") Then Global Const $GCL_STYLE = -26
Local $fDblClk = False
Local $iDoubleClickTime = 300
Global $CorrectedVW, $h_GUI_Main, $h_GUI_Slave, $cmd, $Fullscreen, $Pause, $FileOk
HotKeySet("{ESCAPE}", "_FullScreen")
If $CmdLine[0] <> 0 Then
$MCmdLine = StringSplit($CmdLine[1], "|")
If $MCmdLine[0] < 5 Then
MsgBox(16, "MPlayer Controller by xAx Company", "There is an error in the command line !")
EndIf
$InfoOptions = StringSplit($MCmdLine[5], ";")
$title = $InfoOptions[1]
$script = "MPlayer_Status$='Connecting'" & @LF & 'RunScript("MPlayerController_Handler")'
SendScriptMMB($title, $script)
If $MCmdLine[1] <> "" Then
$XYWH = StringSplit($MCmdLine[1], ";")
$h_GUI_Main = WinGetHandle($XYWH[1], "")
$h_GUI_Slave = GUICreate("MPC Video Window", 100, 100, 100, 100, $WS_POPUP)
GUISetBkColor(0 * 0, $h_GUI_Slave)
GUIRegisterMsg($WM_LBUTTONDBLCLK, "_WM_LBUTTONDBLCLK")
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")
;****
$tempfullwin = GUICreate("MPC", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
GUISetBkColor(0, $tempfullwin)
;****
_WinAPI_SetParent($h_GUI_Slave, $h_GUI_Main)
GUISetState(@SW_SHOW, $h_GUI_Slave)
WinMove($h_GUI_Slave, "", $XYWH[2], $XYWH[3], $XYWH[4], $XYWH[5])
$mplayerpid = Run('"' & $MCmdLine[2] & '" ' & $MCmdLine[3] & ' -slave -wid ' & Number($h_GUI_Slave) & ' "' & $MCmdLine[4] & '"', '', @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD)
$title = $InfoOptions[1]
$script = 'RunScript("VideoWindow_Handler")'
SendScriptMMB($XYWH[1], $script)
Else
$mplayerpid = Run('"' & $MCmdLine[2] & '" ' & $MCmdLine[3] & ' -slave "' & $MCmdLine[4] & '"', '', @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
EndIf
$RegPath1 = "HKEY_CURRENT_USER\Software\MediaChance\Multimedia Builder 4.9.8\" & $InfoOptions[2]
$RegPath2 = "HKEY_CURRENT_USER\Software\MediaChance\Multimedia Player 4.9.8\" & $InfoOptions[2]
$WidthLine = StringSplit('=', '=')
$HeightLine = StringSplit('=', '=')
While $cmd <> "stop" ; <--- The (while) loop starts here
; check for input
For $rrg = 1 To 2 Step +1
If $rrg = 1 Then
$RegPath = $RegPath1
Else
$RegPath = $RegPath2
EndIf
$cmdG = RegRead($RegPath, "MC_INPUT")
If ($cmdG <> "") Then
RegWrite($RegPath, "MC_INPUT", "REG_SZ", "")
$testNVOH = StringMid($cmdG, 1, 9)
If ($testNVOH = 'ResVidObj') Then
$NXYWH = StringSplit($cmdG, ";")
$XYWH[2] = $NXYWH[2]
$XYWH[3] = $NXYWH[3]
$XYWH[4] = $NXYWH[4]
$XYWH[5] = $NXYWH[5]
_Correct_Video_Resolution()
Else
If $cmdG = 'fullscreen' Or $cmdG = 'vo_fullscreen' Then
If $Fullscreen = 0 Then
_WinAPI_SetParent($h_GUI_Slave, '')
WinMove($h_GUI_Slave, "", 0, 0, @DesktopWidth, @DesktopHeight)
StdinWrite($mplayerpid, @LF & 'vo_fullscreen' & @LF)
WinActivate("MPC Video Window", "")
$Fullscreen = 1
Else
StdinWrite($mplayerpid, @LF & 'vo_fullscreen' & @LF)
_Correct_Video_Resolution()
_WinAPI_SetParent($h_GUI_Slave, $h_GUI_Main)
GUISetState(@SW_HIDE, $tempfullwin)
$Fullscreen = 0
EndIf
Else
If $cmdG = 'Hide_Video' Then
GUISetState(@SW_HIDE, $h_GUI_Slave)
Else
If $cmdG = 'Show_Video' Then
GUISetState(@SW_SHOW, $h_GUI_Slave)
Else
If ($cmdG = 'Pause') Or ($cmdG = 'frame_step') Then
StdinWrite($mplayerpid, @LF & $cmdG & @LF)
If $Pause = 0 Then
$Pause = 1
Else
$Pause = 0
EndIf
Else
$testGP = StringMid($cmdG, 1, 12)
If $testGP = 'get_property' Then
$Pause = 0
StdinWrite($mplayerpid, @LF & $cmdG & @LF)
$GetLine = StringSplit($cmdG, @LF)
Sleep($GetLine[0] * 100)
$line = StdoutRead($mplayerpid)
_SEND_STDOUT_TO_MMB()
Else
$testSVW = StringMid($cmdG, 1, 17)
If $testSVW = 'SwitchVideoWindow' Then
$testSVW2 = StringSplit($cmdG, ";")
$XYWH[1] = $testSVW2[2]
$XYWH[2] = $testSVW2[3]
$XYWH[3] = $testSVW2[4]
$XYWH[4] = $testSVW2[5]
$XYWH[5] = $testSVW2[6]
$h_GUI_Main = WinGetHandle($XYWH[1], "")
_WinAPI_SetParent($h_GUI_Slave, $h_GUI_Main)
_Correct_Video_Resolution()
$script = 'RunScript("VideoWindow_Handler")'
SendScriptMMB($XYWH[1], $script)
Else
$Pause = 0
StdinWrite($mplayerpid, @LF & $cmdG & @LF)
If $cmdG = 'stop' Then
$cmd = $cmdG
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
Next
If (WinActive($h_GUI_Slave)) And ($Fullscreen = 0) And ($MCmdLine[1] <> "") Then
WinActivate($XYWH[1], "")
EndIf
; set output
If $Pause = 0 Then
If $FileOk <> 'Yes' Then
StdinWrite($mplayerpid, @LF & "get_time_pos" & @LF & "get_time_length" & @LF & "get_property width" & @LF & "get_property height" & @LF & "get_meta_title" & @LF & "get_file_name" & @LF & _
"get_meta_album" & @LF & "get_meta_artist" & @LF & "get_meta_comment" & @LF & "get_meta_genre" & @LF & _
"get_meta_track" & @LF & "get_meta_year" & @LF & "get_video_resolution" & @LF & "get_video_codec" & @LF & _
"get_audio_bitrate" & @LF & "get_audio_codec" & @LF & "get_video_bitrate" & @LF & "get_vo_fullscreen" & @LF)
$line = StdoutRead($mplayerpid)
$line = StringReplace($line, "ANS_TIME_POSITION", "TIME_POSITION")
$line = StringReplace($line, "ANS_LENGTH", "TIME_LENGTH")
$line = StringReplace($line, "ANS_FILENAME", "FILENAME$")
$line = StringReplace($line, "ANS_META_TITLE", "META_TITLE$")
$line = StringReplace($line, "ANS_META_ALBUM", "META_ALBUM$")
$line = StringReplace($line, "ANS_META_ARTIST", "META_ARTIST$")
$line = StringReplace($line, "ANS_META_COMMENT", "META_COMMENT$")
$line = StringReplace($line, "ANS_META_GENRE", "_META_GENRE$")
$line = StringReplace($line, "ANS_META_TRACK", "_META_TRACK$")
$line = StringReplace($line, "ANS_META_YEAR", "META_YEAR$")
$line = StringReplace($line, "ANS_VIDEO_RESOLUTION", "VIDEO_RESOLUTION$")
$line = StringReplace($line, "ANS_VIDEO_CODEC", "VIDEO_CODEC$")
$line = StringReplace($line, "ANS_AUDIO_BITRATE", "AUDIO_BITRATE$")
$line = StringReplace($line, "ANS_AUDIO_CODEC", "AUDIO_CODEC$")
$line = StringReplace($line, "ANS_VIDEO_BITRATE", "VIDEO_BITRATE$")
$line = StringReplace($line, "ANS_VO_FULLSCREEN", "VO_FULLSCREEN")
$LineTest = StringMid($line, 1, 13)
If $LineTest = 'TIME_POSITION' Then
$FileOk = 'Yes'
$InfoLine = StringSplit($line, @LF)
$TimeLen = StringSplit($InfoLine[2], '=')
;~ Getting length and width
$WidthLine = StringSplit($InfoLine[3], '=')
$HeightLine = StringSplit($InfoLine[4], '=')
_Correct_Video_Resolution()
EndIf
Else
StdinWrite($mplayerpid, @LF & "get_time_pos" & @LF)
$line = StdoutRead($mplayerpid)
$line = StringReplace($line, "ANS_TIME_POSITION", "TIME_POSITION")
EndIf
EndIf
$LineTest = StringMid($line, 1, 13)
If $LineTest = 'TIME_POSITION' Then
$InfoLine = StringSplit($line, @LF)
$TimePos = StringSplit($InfoLine[1], '=')
If $TimePos[2] <> '0' Then
If $Pause = 0 Then
$MPStatus = 'Playing'
Else
$MPStatus = 'Paused'
EndIf
Else
$MPStatus = 'Connecting'
EndIf
$line = $line & @LF & "MPlayer_Status$='" & $MPStatus & "'"
$title = $InfoOptions[1]
$script = $line & @LF & 'RunScript("MPlayerController_Handler")'
SendScriptMMB($title, $script)
EndIf
$mtest = ProcessExists($mplayerpid)
If $mtest = 0 Then
$cmd = "stop"
EndIf
Sleep($InfoOptions[3])
WEnd ; <--- The (while) loop ends here
If $FileOk = 'Yes' Then
$PosInt = Int($TimePos[2])
$LenInt = Int($TimeLen[2])
$FinishTest = $LenInt - $PosInt
If $FinishTest < 3 Then
$MPStatus = 'Finished'
Else
$MPStatus = 'Not running'
EndIf
Else
$MPStatus = 'Faild'
EndIf
$script = "MPlayer_Status$='" & $MPStatus & "'" & @LF & 'RunScript("MPlayerController_Handler")'
StdinWrite($mplayerpid, "quit" & @LF)
$title = $InfoOptions[1]
SendScriptMMB($title, $script)
Exit
Else
MsgBox(16, "MPlayer Controller by xAx Company", "No command line was detected !")
EndIf
Func _FullScreen()
If WinActive($h_GUI_Slave) And $Fullscreen = 1 Then
StdinWrite($mplayerpid, @LF & 'vo_fullscreen' & @LF)
_Correct_Video_Resolution()
_WinAPI_SetParent($h_GUI_Slave, $h_GUI_Main)
GUISetState(@SW_HIDE, $tempfullwin)
$Fullscreen = 0
Else
$script = 'RunScript("Master Layer::CBK_EXIT")'
SendScriptMMB($XYWH[1], $script)
EndIf
EndFunc ;==>_FullScreen
Func _WM_LBUTTONDBLCLK($hWnd, $iMsg, $iwParam, $ilParam)
Local $iX = BitAND($ilParam, 0xFFFF), $iY = BitShift($ilParam, 16)
$fDblClk = True
$script = 'MC_MouseX=' & $iX & @LF & 'MC_MouseY=' & $iY & @LF & 'RunScript("MC_DClick_Handler")'
SendScriptMMB($title, $script)
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_LBUTTONDBLCLK
Func _WM_LBUTTONDOWN($hWnd, $iMsg, $iwParam, $ilParam)
Local $iX = BitAND($ilParam, 0xFFFF), $iY = BitShift($ilParam, 16)
Sleep($iDoubleClickTime)
If $fDblClk Then
$fDblClk = False
Return 0
EndIf
$script = 'MC_MouseX=' & $iX & @LF & 'MC_MouseY=' & $iY & @LF & 'RunScript("MC_LClick_Handler")'
SendScriptMMB($title, $script)
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_RBUTTONDOWN
Func _SEND_STDOUT_TO_MMB()
$GetLine = StringSplit($line, @LF)
For $i = 1 To $GetLine[0] Step +1
$TestLine = StringSplit($GetLine[$i], "=")
If ($TestLine[1] = 'ANS_pause') Or ($TestLine[1] = 'ANS_filename') Or ($TestLine[1] = 'ANS_path') Or ($TestLine[1] = 'ANS_demuxer') Or ($TestLine[1] = 'ANS_metadata') Or ($TestLine[1] = 'ANS_mute') Or ($TestLine[1] = 'ANS_audio_codec') Or ($TestLine[1] = 'ANS_fullscreen') Or ($TestLine[1] = 'ANS_deinterlace') Or ($TestLine[1] = 'ANS_ontop') Or ($TestLine[1] = 'ANS_rootwin') Or ($TestLine[1] = 'ANS_border') Or ($TestLine[1] = 'ANS_vsync') Or ($TestLine[1] = 'ANS_video_codec') Or ($TestLine[1] = 'ANS_sub_visibility') Or ($TestLine[1] = 'ANS_sub_forced_only') Or ($TestLine[1] = 'ANS_teletext_mode') Then
$Property_Value = StringMid($TestLine[2], 1, StringLen($TestLine[2]) - 1)
$NewLine = $TestLine[1] & "$='" & $Property_Value & "'"
$line = StringReplace($line, $GetLine[$i], $NewLine)
EndIf
Next
$line = StringLower($line)
$title = $InfoOptions[1]
$script = $line & @LF & 'RunScript("MPlayerController_Handler")'
SendScriptMMB($title, $script)
EndFunc ;==>_SEND_STDOUT_TO_MMB
Func _Correct_Video_Resolution()
If $WidthLine[2] <> '' And $HeightLine[2] <> '' Then
$R_X = Int($XYWH[2])
$R_Y = Int($XYWH[3])
$R_W = Int($XYWH[4])
$R_H = Int($XYWH[5])
$REAL_W = Int($WidthLine[2])
$REAL_H = Int($HeightLine[2])
$CorrectedVW = $R_W
$CorrectedVH = ($REAL_H / $REAL_W) * $R_W
If $CorrectedVH > $R_H Then
$CorrectedVW = ($REAL_W / $REAL_H) * $R_H
$CorrectedVH = $R_H
EndIf
$CorrectedVX = ($R_W / 2) - ($CorrectedVW / 2) + $R_X
$CorrectedVY = ($R_H / 2) - ($CorrectedVH / 2) + $R_Y
WinMove($h_GUI_Slave, "", $CorrectedVX, $CorrectedVY, $CorrectedVW, $CorrectedVH)
EndIf
EndFunc ;==>_Correct_Video_ResolutionLa variable $ est inversé dans:
AutoIt => $Title
MMB => Title$
1° le nom de la fenêtre (Title$ dans MMB) => C:\Windows\system32\cmd.exe
2° le contenu (Batch$ dans MMB)
► Afficher le texte
Code : Tout sélectionner
D:\Temp\RipBot264temp\job1>"C:\Program Files (x86)\RipBot264\tools\avs2yuv\pipeb
uf.exe" "C:\Program Files (x86)\RipBot264\tools\avs2yuv\avs2yuv.exe" "D:\temp\Ri
pBot264temp\job1\job1.avs" - : "C:\Program Files (x86)\RipBot264\tools\x264\x264
_x64.exe" --pass 1 --bitrate 1024 --stats "D:\temp\RipBot264temp\job1\job1.stats
" --fps 24000/1001 --force-cfr --min-keyint 24 --keyint 240 --frames 123122 --s
ar 1:1 --level 4.0 --aud --nal-hrd vbr --vbv-bufsize 25000 --vbv-maxrate 25000 -
-filter 0,0 --ref 3 --bframes 3 --b-adapt 1 --b-pyramid none --subme 7 --aq-m
ode 1 --trellis 1 --partitions all --me umh --stdin y4m --output "D:\temp\RipBot
264temp\video.264" - : 2
D:\temp\RipBot264temp\job1\job1.avs: 3840x1080, 10000000/417083 fps, 123122 fram
es
y4m [info]: 3840x1080p 1:1 @ 10000000/417083 fps (cfr)
x264 [info]: using SAR=1/1
x264 [warning]: frame MB size (240x68) > level limit (8192)
x264 [warning]: VBV bitrate (25000) > level limit (20000)
x264 [warning]: MB rate (391288) > level limit (245760)
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.1 Cach
e64
x264 [info]: profile Main, level 4.0
[0.1%] 160/123122 frames, 17.78 fps, 1962.91 kb/s, eta 1:55:16Je met à disposition le programme de test
- how get.rar
- how get.rar
- (508.27 Kio) Téléchargé 307 fois







