|
24.01.2007, 16:04
#34279330
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
Ссылка на профиль пользователя:
|
|
|
Участник
Сообщения: 15 530
Рейтинг:
0
/ 0
|
|
|
|
Вот класс-обертка над CreateProcess()
есть запуск, ожидание завершения, время работы
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. 193. 194. 195. 196. 197. 198. 199. 200.
**************************************************
*-- Class: waitexec (c:\исходники\classes\objects.vcx)
*-- ParentClass: custom
*-- BaseClass: custom
*-- Time Stamp: 12/08/06 08:55:10 PM
*
DEFINE CLASS waitexec AS custom
Height = 15
Width = 101
HIDDEN nhandle
nhandle = - 1
*-- Время в момент запуска
HIDDEN nsecond
nsecond = 0
Name = "waitexec"
*-- Скрыть окно вызываемой программы.
lhide = .F.
HIDDEN PROCEDURE long2str
LPARAMETERS tnlongval
* Passed : 32 -bit non-negative numeric value (m.longval)
* Returns : ASCII character representation of passed
* value in low-high format (m.retstr)
* Example :
* m.long = 999999
* m.longstr = long2str(m.long)
local i, lсretstr
lcretstr = ""
FOR i = 24 TO 0 STEP - 8
lcretstr = CHR(INT(tnlongval/( 2 ^i))) + lcretstr
tnlongval = MOD(tnlongval, ( 2 ^i))
NEXT
RETURN lcretstr
ENDPROC
HIDDEN PROCEDURE str2long
LPARAMETERS tclongstr
* Passed: 4 -byte character string (m.longstr)
* in low-high ASCII format
* returns: long integer value
* example:
* m.longstr = "1111"
* m.longval = str2long(m.longstr)
PRIVATE i, lnretval
lnretval = 0
FOR i = 0 TO 24 STEP 8
lnretval = lnretval + (ASC(tclongstr) * ( 2 ^i))
tclongstr = RIGHT(tclongstr, LEN(tclongstr) - 1 )
NEXT
RETURN lnretval
ENDPROC
*-- Запуск указанного приложения. Параметр - полный путь к файлу. Возвращает .t. если выполнено
PROCEDURE execute
#DEFINE NORMAL_PRIORITY_CLASS 32
#DEFINE IDLE_PRIORITY_CLASS 64
#DEFINE HIGH_PRIORITY_CLASS 128
#DEFINE REALTIME_PRIORITY_CLASS 1600
lpara tcExe
local llRet, lcstart, lcprocess_info, lcPath
this.Free()
if this.lHide
lcstart = this.long2str( 68 ) + REPLICATE(CHR( 0 ), 40 ) + this.long2str( 1 ) + REPLICATE(CHR( 0 ), 20 )
else
lcstart = this.long2str( 68 ) + REPLICATE(CHR( 0 ), 64 )
endif
lcprocess_info = REPLICATE(CHR( 0 ), 16 )
lcPath = alltrim(tcExe)
if left(lcPath, 1 ) = '"'
lcPath = substr(lcPath, 2 )
if at('"', lcPath) != 0
lcPath = left(lcPath, at('"', lcPath))
endif
else
if at(' ', lcPath) != 0
lcPath = left(lcPath, at(' ', lcPath))
endif
endif
lcPath = addbs(justpath(lcPath))
if left(tcExe, 1 ) = '"' and at('"', tcExe, 2 ) = len(tcExe)
* Убирание лишних кавычек
tcExe = substr(tcExe, 2 )
tcExe = Left(tcExe, len(tcExe) - 1 )
endif
if empty(lcPath)
lcPath = addbs(fullpath(''))
endif
if CreateProcess( 0 , tcExe, 0 , 0 , 1 , NORMAL_PRIORITY_CLASS, 0 , lcPath, @lcstart, @lcprocess_info) = 0
llRet = .f.
this.nHandle = - 1
else
llRet = .t.
this.nHandle = this.str2long(SUBSTR(lcprocess_info, 1 , 4 ))
this.nSecond = second()
endif
return llRet
ENDPROC
*-- Ожидание завершения работы приложения. Параметр - время ожидания в мс, если не указан, то ждать до конца. Возвращает .t. если завершено.
PROCEDURE waitstop
#DEFINE WAIT_TIMEOUT 0x00000102
lpara tnTime
local llRet, llCircle
if vartype(tnTime) != 'N'
tnTime = 200
llCircle = .t.
endif
if this.nHandle != - 1
do while .t.
IF WaitForSingleObject(this.nHandle, tnTime) != WAIT_TIMEOUT
llRet = .t.
this.Free()
exit
else
if !llCircle
exit
endif
ENDIF
enddo
else
llRet = .t.
endif
return llRet
ENDPROC
*-- Отказ от контроля за запущенным процессом.
PROCEDURE free
if this.nHandle != - 1
CloseHandle(this.nHandle)
this.nHandle = - 1
endif
ENDPROC
*-- Время, которое программа работает с момента запуска, в секундах.
PROCEDURE getworkingtime
return second() - this.nSecond
ENDPROC
PROCEDURE Init
DECLARE INTEGER CreateProcess IN kernel32.DLL ;
INTEGER lpApplicationName, ;
STRING lpCommandLine, ;
INTEGER lpProcessAttributes, ;
INTEGER lpThreadAttributes, ;
INTEGER bInheritHandles, ;
INTEGER dwCreationFlags, ;
INTEGER lpEnvironment, ;
STRING @lpCurrentDirectory, ;
STRING @lpStartupInfo, ;
STRING @lpProcessInformation
DECLARE INTEGER WaitForSingleObject IN kernel32.DLL ;
INTEGER hHandle, INTEGER dwMilliseconds
DECLARE INTEGER CloseHandle IN kernel32.DLL ;
INTEGER hObject
DECLARE INTEGER GetLastError IN kernel32.DLL
ENDPROC
PROCEDURE Destroy
this.Free()
ENDPROC
ENDDEFINE
*
*-- EndDefine: waitexec
**************************************************
|
|
|