【已解决】求助,调用文件执行时窗口闪烁
本帖最后由 h111666b 于 2024-10-7 08:33 编辑#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $SubGui, $Width = 560, $Height = 280, $BfBtn
$SubGui = GUICreate("备份窗口", $Width, $Height, -1, -1)
;备份
$BfBtn = GUICtrlCreateButton("备份(&Y)", 262, 168, 80, 30)
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $BfBtn
;备份
Example()
EndSwitch
WEnd
Func Example()
RunWait(@ScriptDir & "\Imagex.exe" & " /capture " & "G:\WinPE G:\Win7.wim Win7备份 Win7说明" & " /compress fast", "", @SW_HIDE)
EndFunc ;==>Example
;以上代码调用微软Imagex.exe备份程序,执行时窗口和备份按钮闪烁不断,特此求助。
用run会不会好些
还闪不闪
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <WinAPI.au3>
#include <NamedPipes.au3>
Opt('GUIOnEventMode', 1)
Global $hProcess, $SubGui, $Width = 560, $Height = 280, $BfBtn, $hEdit
$SubGui = GUICreate("备份窗口", $Width, $Height, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')
$BfBtn = GUICtrlCreateButton("备份(&Y)", 475, 50, 80, 30)
GUICtrlSetOnEvent(-1, 'Backup')
$hEdit = GUICtrlCreateEdit('', 10, 10, 460, 260, 0x00200000)
GUISetState(@SW_SHOW)
While 1
Sleep(100)
WEnd
Func Backup()
CaptureConsole('Imagex.exe /capture E:\IDA_Pro E:\Win7.wim Win7备份 Win7说明 /compress fast', 'UpdateEdit')
EndFunc ;==>Example
Func UpdateEdit($sData)
_GUICtrlEdit_AppendText($hEdit, $sData)
GUICtrlSendMsg($hEdit, 0x00B7, 0, 0)
EndFunc
Func _Exit()
If _WinAPI_GetExitCodeProcess($hProcess) = 259 Then _WinAPI_TerminateProcess($hProcess, 0)
_WinAPI_CloseHandle($hProcess)
Exit
EndFunc
Func CaptureConsole($sCommand, $callback)
Local $buffer, $hRead, $hWrite, $bytesRead, $SzBuffer = DllStructCreate('char SzBuffer')
Local $tagSTARTUPINFO = DllStructCreate("int Size;ptr Reserved1;ptr Desktop;ptr Title;int X;int Y;int XSize;int YSize;int XCountChars;" & _
"int YCountChars;int FillAttribute;int Flags;short ShowWindow;short Reserved2;ptr Reserved3;int StdInput;" & _
"int StdOutput;int StdError")
Local $tagPROCESS_INFORMATION = DllStructCreate('hwnd hProcess;hwnd hThread;int ProcessID;int ThreadID')
Local $tagSECURITY_ATTRIBUTES = DllStructCreate('int Length;ptr Descriptor;int InheritHandle')
DllStructSetData($tagSECURITY_ATTRIBUTES, 'Length', DllStructGetSize($tagSECURITY_ATTRIBUTES))
DllStructSetData($tagSECURITY_ATTRIBUTES, 'InheritHandle', True)
DllStructSetData($tagSECURITY_ATTRIBUTES, 'Descriptor', Null)
If _NamedPipes_CreatePipe($hRead, $hWrite,DllStructGetPtr($tagSECURITY_ATTRIBUTES)) <> False Then
DllStructSetData($tagSTARTUPINFO, 'Size', DllStructGetSize($tagSTARTUPINFO))
DllStructSetData($tagSTARTUPINFO, 'StdOutput', $hWrite)
DllStructSetData($tagSTARTUPINFO, 'StdError', $hWrite)
DllStructSetData($tagSTARTUPINFO, 'Flags', '0x101')
DllStructSetData($tagSTARTUPINFO, 'ShowWindow', @SW_HIDE)
If _WinAPI_CreateProcess('', $sCommand, Null, Null, True, 0, Null, Null, DllStructGetPtr($tagSTARTUPINFO), DllStructGetPtr($tagPROCESS_INFORMATION)) <> False Then
$hProcess = DllStructGetData($tagPROCESS_INFORMATION, 'hProcess')
_WinAPI_CloseHandle($hWrite)
While 1
If _WinAPI_GetExitCodeProcess($hProcess) <> 259 Then ExitLoop
Local $aInfo = _NamedPipes_PeekNamedPipe($hRead)
If @error Then
ConsoleWrite('PeekNamedPipe error: ' & @error & @CRLF)
ExitLoop
EndIf
If $aInfo > 0 Then
_WinAPI_ZeroMemory(DllStructGetPtr($SzBuffer), DllStructGetSize($szBuffer))
If _WinAPI_ReadFile($hRead, DllStructGetPtr($SzBuffer), DllStructGetSize($SzBuffer), $bytesRead) = False Then
ConsoleWrite(StringFormat('ReadFile error:%d\r\nReadFile error msg:%s\r\n', _WinAPI_GetLastError(), _WinAPI_GetLastErrorMessage()))
ExitLoop
Else
$buffer &= DllStructGetData($SzBuffer, 1)
Call($callback, $buffer)
$buffer = ''
EndIf
EndIf
WEnd
EndIf
_WinAPI_CloseHandle($hRead)
_WinAPI_CloseHandle(DllStructGetData($tagPROCESS_INFORMATION, 'hThread'))
EndIf
EndFunc ;==>CaptureConsole
感谢楼上,解决了
页:
[1]