invoke PeekNamedPipe,hRead2,addr szBuffer,511,addr @dwBytesRead,NULL,NULL
.if @dwBytesRead != 0
invoke RtlZeroMemory,addr szBuffer,512
invoke ReadFile,hRead2,addr szBuffer,@dwBytesRead,\
addr @dwBytesRead,NULL
mov @stRange.cpMin,-1
mov @stRange.cpMax,-1
invoke SendMessage,hWinText,EM_EXSETSEL,0,addr @stRange
invoke SendMessage,hWinText,EM_REPLACESEL,FALSE,addr szBuffer
invoke SendMessage,hWinText,EM_SCROLLCARET,NULL,NULL
invoke SendMessage,hWinText,WM_SETFONT,hFont,0
.endif
.endw
invoke CloseHandle,stProcInfo.hProcess
invoke CloseHandle,stProcInfo.hThread
.else
invoke MessageBox,hWinMain,addr szExcuteError,NULL,MB_OK or MB_ICONERROR
.endif
;********************************************************************
; 关闭管道
;********************************************************************
invoke CloseHandle,hRead1
invoke CloseHandle,hWrite1
invoke CloseHandle,hRead2
invoke CloseHandle,hWrite2
;********************************************************************
; 把“结束”菜单改为“执行”
;********************************************************************
invoke EnableMenuItem,hMenu,IDM_EXEC,MF_ENABLED
invoke EnableMenuItem,hMenu,IDM_EXIT,MF_ENABLED
invoke EnableWindow,hWinText,FALSE
and dwFlag,not F_RUNNING
ret
_RunThread endp
;********************************************************************
; 窗口程序
;********************************************************************
WndMainProc proc uses ebx edi esi, \
hWnd:DWORD,wMsg:DWORD,wParam:DWORD,lParam:Dword
mov eax,wMsg
;********************************************************************
.if eax == WM_CREATE
mov eax,hWnd
mov hWinMain,eax
call _Init
;********************************************************************
.elseif eax == WM_SIZE
mov edx,lParam
mov ecx,edx
shr ecx,16
and edx,0ffffh
invoke MoveWindow,hWinText,0,0,edx,ecx,TRUE
invoke PostMessage,hWinText,WM_SIZE,wParam,lParam
;********************************************************************
.elseif eax == WM_CLOSE
test dwFlag,F_RUNNING
.if ZERO?
invoke DestroyWindow,hWinMain
invoke PostQuitMessage,NULL
.endif
;********************************************************************
.elseif eax == WM_COMMAND
mov eax,wParam
.if ax == IDM_EXEC
;********************************************************************
; 如果没有在执行中(dwFlag 没有置位) 则建立线程,在线程中执行程序
; 如果已经在执行中,则用 TerminateProcess 终止执行
;********************************************************************
test dwFlag,F_RUNNING
汇编中的管道操作方法(三)