Debug_En.au3 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. #include-once
  2. #include "ArrayDisplayInternals.au3"
  3. #include "AutoItConstants.au3"
  4. #include "MsgBoxConstants.au3"
  5. #include "SendMessage.au3"
  6. #include "StringConstants.au3"
  7. #include "WinAPIError.au3"
  8. ; #INDEX# =======================================================================================================================
  9. ; Title .........: Debug
  10. ; AutoIt Version : 3.3.14.5
  11. ; Language ......: English
  12. ; Description ...: Functions to help script debugging.
  13. ; Author(s) .....: Nutster, Jpm, Valik, guinness, water
  14. ; ===============================================================================================================================
  15. ; #CONSTANTS# ===================================================================================================================
  16. Global Const $__g_sReportWindowText_Debug = "Debug Window hidden text"
  17. ; ===============================================================================================================================
  18. ; #VARIABLE# ====================================================================================================================
  19. Global $__g_sReportTitle_Debug = "AutoIt Debug Report"
  20. Global $__g_iReportType_Debug = 0
  21. Global $__g_bReportWindowWaitClose_Debug = True, $__g_bReportWindowClosed_Debug = True
  22. Global $__g_hReportEdit_Debug = 0
  23. Global $__g_hReportNotepadEdit_Debug = 0
  24. Global $__g_sReportCallBack_Debug
  25. Global $__g_bReportTimeStamp_Debug = False
  26. Global $__g_bComErrorExit_Debug = False, $__g_oComError_Debug = Null
  27. ; ===============================================================================================================================
  28. ; #CURRENT# =====================================================================================================================
  29. ; _Assert
  30. ; _DebugArrayDisplay
  31. ; _DebugBugReportEnv
  32. ; _DebugCOMError
  33. ; _DebugOut
  34. ; _DebugReport
  35. ; _DebugReportEx
  36. ; _DebugReportVar
  37. ; _DebugSetup
  38. ; ===============================================================================================================================
  39. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  40. ; __Debug_COMErrorHandler
  41. ; __Debug_DataFormat
  42. ; __Debug_DataType
  43. ; __Debug_ReportClose
  44. ; __Debug_ReportWrite
  45. ; __Debug_ReportWindowCreate
  46. ; __Debug_ReportWindowWrite
  47. ; __Debug_ReportWindowWaitClose
  48. ; ===============================================================================================================================
  49. ; #FUNCTION# ====================================================================================================================
  50. ; Author ........: Valik
  51. ; Modified.......: jpm
  52. ; ===============================================================================================================================
  53. Func _Assert($sCondition, $bExit = True, $iCode = 0x7FFFFFFF, $sLine = @ScriptLineNumber, Const $_iCurrentError = @error, Const $_iCurrentExtended = @extended)
  54. Local $bCondition = Execute($sCondition)
  55. If Not $bCondition Then
  56. MsgBox($MB_SYSTEMMODAL, "AutoIt Assert", "Assertion Failed (Line " & $sLine & "): " & @CRLF & @CRLF & $sCondition)
  57. If $bExit Then Exit $iCode
  58. EndIf
  59. Return SetError($_iCurrentError, $_iCurrentExtended, $bCondition)
  60. EndFunc ;==>_Assert
  61. ; #FUNCTION# ====================================================================================================================
  62. ; Author ........: Melba23
  63. ; Modified.......: jpm
  64. ; ===============================================================================================================================
  65. Func _DebugArrayDisplay(Const ByRef $aArray, $sTitle = Default, $sArrayRange = Default, $iFlags = Default, $vUser_Separator = Default, $sHeader = Default, $iMax_ColWidth = Default, $hUser_Function = Default)
  66. Local $iRet = __ArrayDisplay_Share($aArray, $sTitle, $sArrayRange, $iFlags, $vUser_Separator, $sHeader, $iMax_ColWidth, $hUser_Function, True)
  67. Return SetError(@error, @extended, $iRet)
  68. EndFunc ;==>_DebugArrayDisplay
  69. ; #FUNCTION# ====================================================================================================================
  70. ; Author ........: jpm
  71. ; Modified.......:
  72. ; ===============================================================================================================================
  73. Func _DebugBugReportEnv(Const $_iCurrentError = @error, Const $_iCurrentExtended = @extended)
  74. Local $sAutoItX64, $sAdminMode, $sCompiled, $sOsServicePack, $sMUIlang, $sKBLayout, $sCPUArch
  75. If @AutoItX64 Then $sAutoItX64 = "/X64"
  76. If IsAdmin() Then $sAdminMode = ", AdminMode"
  77. If @Compiled Then $sCompiled = ", Compiled"
  78. If @OSServicePack Then $sOsServicePack = "/" & StringReplace(@OSServicePack, "Service Pack ", "SP")
  79. If @OSLang <> @MUILang Then $sMUIlang = ", MUILang: " & @MUILang
  80. If @OSLang <> StringRight(@KBLayout, 4) Then $sKBLayout = ", Keyboard: " & @KBLayout
  81. If @OSArch <> @CPUArch Then $sCPUArch = ", CPUArch: " & @CPUArch
  82. Return SetError($_iCurrentError, $_iCurrentExtended, "AutoIt: " & @AutoItVersion & $sAutoItX64 & $sAdminMode & $sCompiled & _
  83. ", OS: " & @OSVersion & $sOsServicePack & "/" & @OSArch & _
  84. ", OSLang: " & @OSLang & $sMUIlang & $sKBLayout & $sCPUArch & _
  85. ", Script: " & @ScriptFullPath)
  86. EndFunc ;==>_DebugBugReportEnv
  87. ; #FUNCTION# ====================================================================================================================
  88. ; Author ........: water
  89. ; Modified ......: jpm
  90. ; ===============================================================================================================================
  91. Func _DebugCOMError($iComDebug = Default, $bExit = False)
  92. If $__g_iReportType_Debug <= 0 Or $__g_iReportType_Debug > 6 Then Return SetError(3, 0, 0)
  93. If $iComDebug = Default Then $iComDebug = 1
  94. If Not IsInt($iComDebug) Or $iComDebug < -1 Or $iComDebug > 1 Then Return SetError(1, 0, 0)
  95. Switch $iComDebug
  96. Case -1
  97. Return SetError(IsObj($__g_oComError_Debug), $__g_bComErrorExit_Debug, 1)
  98. Case 0
  99. If $__g_oComError_Debug = Null Then SetError(0, 3, 1) ; COM error handler already disabled
  100. $__g_oComError_Debug = Null
  101. $__g_bComErrorExit_Debug = False
  102. Return 1
  103. Case Else
  104. ; A COM error handler will be initialized only if one does not exist
  105. $__g_bComErrorExit_Debug = $bExit
  106. Local $vComErrorChecking = ObjEvent("AutoIt.Error")
  107. If $vComErrorChecking = "" Then
  108. $__g_oComError_Debug = ObjEvent("AutoIt.Error", __Debug_COMErrorHandler) ; Creates a custom error handler
  109. If @error Then Return SetError(4, @error, 0)
  110. Return SetError(0, 1, 1)
  111. ElseIf FuncName($vComErrorChecking) = FuncName(__Debug_COMErrorHandler) Then
  112. Return SetError(0, 2, 1) ; COM error handler already set by a previous call to this function
  113. Else
  114. Return SetError(2, 0, 0) ; COM error handler already set to another function - not by this UDF
  115. EndIf
  116. EndSwitch
  117. EndFunc ;==>_DebugCOMError
  118. ; #FUNCTION# ====================================================================================================================
  119. ; Author ........: Nutster
  120. ; Modified.......: jpm
  121. ; ===============================================================================================================================
  122. Func _DebugOut(Const $sOutput, Const $_iCurrentError = @error, Const $_iCurrentExtended = @extended)
  123. If IsNumber($sOutput) = 0 And IsString($sOutput) = 0 And IsBool($sOutput) = 0 Then Return SetError(1, 0, 0) ; $sOutput can not be printed
  124. If _DebugReport($sOutput) = 0 Then Return SetError(3, 0, 0) ; _DebugSetup() as not been called.
  125. Return SetError($_iCurrentError, $_iCurrentExtended, 1) ; Return @error and @extended as before calling _DebugOut()
  126. EndFunc ;==>_DebugOut
  127. ; #FUNCTION# ====================================================================================================================
  128. ; Author ........: jpm
  129. ; Modified.......: guinness
  130. ; ===============================================================================================================================
  131. Func _DebugSetup(Const $sTitle = Default, $bBugReportInfos = Default, $vReportType = Default, $sLogFile = Default, $bTimeStamp = False)
  132. If $__g_iReportType_Debug Then Return SetError(1, 0, $__g_iReportType_Debug) ; already registered
  133. If $bBugReportInfos = Default Then $bBugReportInfos = False
  134. If $vReportType = Default Then $vReportType = 1
  135. If $sLogFile = Default Then $sLogFile = ""
  136. Switch $vReportType
  137. Case 1
  138. ; Report Log window
  139. $__g_sReportCallBack_Debug = "__Debug_ReportWindowWrite("
  140. Case 2
  141. ; ConsoleWrite
  142. $__g_sReportCallBack_Debug = "ConsoleWrite("
  143. Case 3
  144. ; Message box
  145. $__g_sReportCallBack_Debug = "MsgBox(4096, '" & $__g_sReportTitle_Debug & "',"
  146. Case 4
  147. ; Log file
  148. $__g_sReportCallBack_Debug = "FileWrite('" & $sLogFile & "',"
  149. Case 5
  150. ; Report notepad window
  151. $__g_sReportCallBack_Debug = "__Debug_ReportNotepadWrite("
  152. Case Else
  153. If Not IsString($vReportType) Then Return SetError(2, 0, 0) ; invalid Report type
  154. ; private callback
  155. If $vReportType = "" Then Return SetError(3, 0, 0) ; invalid callback function
  156. $__g_sReportCallBack_Debug = $vReportType & "("
  157. $vReportType = 6
  158. EndSwitch
  159. If Not ($sTitle = Default) Then $__g_sReportTitle_Debug = $sTitle
  160. $__g_iReportType_Debug = $vReportType
  161. $__g_bReportTimeStamp_Debug = $bTimeStamp
  162. OnAutoItExitRegister("__Debug_ReportClose")
  163. If $bBugReportInfos Then _DebugReport(_DebugBugReportEnv() & @CRLF)
  164. Return $__g_iReportType_Debug
  165. EndFunc ;==>_DebugSetup
  166. ; #FUNCTION# ====================================================================================================================
  167. ; Author ........: jpm
  168. ; Modified.......:
  169. ; ===============================================================================================================================
  170. Func _DebugReport($sData, $bLastError = False, $bExit = False, Const $_iCurrentError = @error, $_iCurrentExtended = @extended)
  171. If $__g_iReportType_Debug <= 0 Or $__g_iReportType_Debug > 6 Then Return SetError($_iCurrentError, $_iCurrentExtended, 0)
  172. $_iCurrentExtended = __Debug_ReportWrite($sData, $bLastError)
  173. If $bExit Then Exit
  174. Return SetError($_iCurrentError, $_iCurrentExtended, 1)
  175. EndFunc ;==>_DebugReport
  176. ; #FUNCTION# ====================================================================================================================
  177. ; Author ........: jpm
  178. ; Modified.......:
  179. ; ===============================================================================================================================
  180. Func _DebugReportEx($sData, $bLastError = False, $bExit = False, Const $_iCurrentError = @error, $_iCurrentExtended = @extended)
  181. If $__g_iReportType_Debug <= 0 Or $__g_iReportType_Debug > 6 Then Return SetError($_iCurrentError, $_iCurrentExtended, 0)
  182. If IsInt($_iCurrentError) Then
  183. Local $sTemp = StringSplit($sData, "|", $STR_ENTIRESPLIT + $STR_NOCOUNT)
  184. If UBound($sTemp) > 1 Then
  185. If $bExit Then
  186. $sData = "<<< "
  187. Else
  188. $sData = ">>> "
  189. EndIf
  190. Switch $_iCurrentError
  191. Case 0
  192. $sData &= "Bad return from " & $sTemp[1] & " in " & $sTemp[0] & ".dll"
  193. Case 1
  194. $sData &= "Unable to open " & $sTemp[0] & ".dll"
  195. Case 3
  196. $sData &= "Unable to find " & $sTemp[1] & " in " & $sTemp[0] & ".dll"
  197. EndSwitch
  198. EndIf
  199. EndIf
  200. $_iCurrentExtended = __Debug_ReportWrite($sData, $bLastError)
  201. If $bExit Then Exit
  202. Return SetError($_iCurrentError, $_iCurrentExtended, 1)
  203. EndFunc ;==>_DebugReportEx
  204. ; #FUNCTION# ====================================================================================================================
  205. ; Author ........: jpm
  206. ; Modified.......:
  207. ; ===============================================================================================================================
  208. Func _DebugReportVar($sVarName, $vVar, $bErrExt = False, Const $iDebugLineNumber = @ScriptLineNumber, Const $_iCurrentError = @error, Const $_iCurrentExtended = @extended)
  209. If $__g_iReportType_Debug <= 0 Or $__g_iReportType_Debug > 6 Then Return SetError($_iCurrentError, $_iCurrentExtended, 0)
  210. If IsBool($vVar) And IsInt($bErrExt) Then
  211. ; to kept some compatibility with 3.3.1.3 if really needed for non breaking
  212. If StringLeft($sVarName, 1) = "$" Then $sVarName = StringTrimLeft($sVarName, 1)
  213. $vVar = Eval($sVarName)
  214. $sVarName = "???"
  215. EndIf
  216. Local $sData = "@@ Debug(" & $iDebugLineNumber & ") : " & __Debug_DataType($vVar) & " -> " & $sVarName
  217. If IsArray($vVar) Then
  218. Local $nDims = UBound($vVar, $UBOUND_DIMENSIONS)
  219. Local $nRows = UBound($vVar, $UBOUND_ROWS)
  220. Local $nCols = UBound($vVar, $UBOUND_COLUMNS)
  221. For $d = 1 To $nDims
  222. $sData &= "[" & UBound($vVar, $d) & "]"
  223. Next
  224. If $nDims <= 2 Then
  225. For $r = 0 To $nRows - 1
  226. $sData &= @CRLF & "[" & $r & "] "
  227. If $nDims = 1 Then
  228. $sData &= __Debug_DataFormat($vVar[$r]) & @TAB
  229. Else
  230. For $c = 0 To $nCols - 1
  231. $sData &= __Debug_DataFormat($vVar[$r][$c]) & @TAB
  232. Next
  233. EndIf
  234. Next
  235. EndIf
  236. ElseIf IsDllStruct($vVar) Or IsObj($vVar) Then
  237. Else
  238. $sData &= ' = ' & __Debug_DataFormat($vVar)
  239. EndIf
  240. If $bErrExt Then $sData &= @CRLF & @TAB & "@error=" & $_iCurrentError & " @extended=0x" & Hex($_iCurrentExtended)
  241. __Debug_ReportWrite($sData)
  242. Return SetError($_iCurrentError, $_iCurrentExtended)
  243. EndFunc ;==>_DebugReportVar
  244. ; #INTERNAL_USE_ONLY#============================================================================================================
  245. ; Name ..........: __Debug_COMErrorHandler
  246. ; Description ...: Called when a COM error occurs and writes the error message with _DebugOut().
  247. ; Syntax.........: __Debug_COMErrorHandler ( $oCOMError )
  248. ; Parameters ....: $oCOMError - Error object
  249. ; Return values .: None
  250. ; Author ........: water
  251. ; Modified ......: jpm
  252. ; Remarks .......:
  253. ; Related .......:
  254. ; Link ..........:
  255. ; Example .......:
  256. ; ===============================================================================================================================
  257. Func __Debug_COMErrorHandler($oCOMError)
  258. _DebugReport(__COMErrorFormating($oCOMError), False, $__g_bComErrorExit_Debug)
  259. EndFunc ;==>__Debug_COMErrorHandler
  260. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  261. ; Name...........: __Debug_DataFormat
  262. ; Description ...: Returns a formatted data
  263. ; Syntax.........: __Debug_DataFormat ( $vData )
  264. ; Parameters ....: $vData - a data to be formatted
  265. ; Return values .: the data truncated if needed or the Datatype for not editable as Dllstruct, Obj or Array
  266. ; Author ........: jpm
  267. ; Modified.......:
  268. ; Remarks .......:
  269. ; Related .......:
  270. ; Link ..........:
  271. ; Example .......:
  272. ; ===============================================================================================================================
  273. Func __Debug_DataFormat($vData)
  274. Local $nLenMax = 25 ; to truncate String, Binary
  275. Local $sTruncated = ""
  276. If IsString($vData) Then
  277. If StringLen($vData) > $nLenMax Then
  278. $vData = StringLeft($vData, $nLenMax)
  279. $sTruncated = " ..."
  280. EndIf
  281. Return '"' & $vData & '"' & $sTruncated
  282. ElseIf IsBinary($vData) Then
  283. If BinaryLen($vData) > $nLenMax Then
  284. $vData = BinaryMid($vData, 1, $nLenMax)
  285. $sTruncated = " ..."
  286. EndIf
  287. Return $vData & $sTruncated
  288. ElseIf IsDllStruct($vData) Or IsArray($vData) Or IsObj($vData) Then
  289. Return __Debug_DataType($vData)
  290. Else
  291. Return $vData
  292. EndIf
  293. EndFunc ;==>__Debug_DataFormat
  294. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  295. ; Name...........: __Debug_DataType
  296. ; Description ...: Truncate a data
  297. ; Syntax.........: __Debug_DataType ( $vData )
  298. ; Parameters ....: $vData - a data
  299. ; Return values .: the data truncated if needed
  300. ; Author ........: jpm
  301. ; Modified.......:
  302. ; Remarks .......:
  303. ; Related .......:
  304. ; Link ..........:
  305. ; Example .......:
  306. ; ===============================================================================================================================
  307. Func __Debug_DataType($vData)
  308. Local $sType = VarGetType($vData)
  309. Switch $sType
  310. Case "DllStruct"
  311. $sType &= ":" & DllStructGetSize($vData)
  312. Case "Array"
  313. $sType &= " " & UBound($vData, $UBOUND_DIMENSIONS) & "D"
  314. Case "String"
  315. $sType &= ":" & StringLen($vData)
  316. Case "Binary"
  317. $sType &= ":" & BinaryLen($vData)
  318. Case "Ptr"
  319. If IsHWnd($vData) Then $sType = "Hwnd"
  320. EndSwitch
  321. Return "{" & $sType & "}"
  322. EndFunc ;==>__Debug_DataType
  323. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  324. ; Name...........: __Debug_ReportClose
  325. ; Description ...: Close the debug session
  326. ; Syntax.........: __Debug_ReportClose ( )
  327. ; Parameters ....:
  328. ; Return values .:
  329. ; Author ........: jpm
  330. ; Modified.......: guinness
  331. ; Remarks .......: If a specific reporting function has been registered then it is called without parameter.
  332. ; Related .......: _DebugSetup
  333. ; Link ..........:
  334. ; Example .......:
  335. ; ===============================================================================================================================
  336. Func __Debug_ReportClose()
  337. If $__g_iReportType_Debug = 1 Then
  338. WinSetOnTop($__g_sReportTitle_Debug, "", 1)
  339. _DebugReport('>>>>>> Please close the "Report Log Window" to exit <<<<<<<' & @CRLF)
  340. __Debug_ReportWindowWaitClose()
  341. ElseIf $__g_iReportType_Debug = 6 Then
  342. Execute($__g_sReportCallBack_Debug & ")")
  343. EndIf
  344. $__g_iReportType_Debug = 0
  345. EndFunc ;==>__Debug_ReportClose
  346. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  347. ; Name...........: __Debug_ReportWindowCreate
  348. ; Description ...: Create an report log window
  349. ; Syntax.........: __Debug_ReportWindowCreate ( )
  350. ; Parameters ....:
  351. ; Return values .: 0 if already created
  352. ; Author ........: jpm
  353. ; Modified.......:
  354. ; Remarks .......:
  355. ; Related .......:
  356. ; Link ..........:
  357. ; Example .......:
  358. ; ===============================================================================================================================
  359. Func __Debug_ReportWindowCreate()
  360. Local $nOld = Opt("WinDetectHiddenText", $OPT_MATCHSTART)
  361. Local $bExists = WinExists($__g_sReportTitle_Debug, $__g_sReportWindowText_Debug)
  362. If $bExists Then
  363. If $__g_hReportEdit_Debug = 0 Then
  364. ; first time we try to access an open window in the running script,
  365. ; get the control handle needed for writing in
  366. $__g_hReportEdit_Debug = ControlGetHandle($__g_sReportTitle_Debug, $__g_sReportWindowText_Debug, "Edit1")
  367. ; force no closing no waiting on report closing
  368. $__g_bReportWindowWaitClose_Debug = False
  369. EndIf
  370. EndIf
  371. Opt("WinDetectHiddenText", $nOld)
  372. ; change the state of the report Window as it is already opened or will be
  373. $__g_bReportWindowClosed_Debug = False
  374. If Not $__g_bReportWindowWaitClose_Debug Then Return 0 ; use of the already opened window
  375. Local Const $WS_OVERLAPPEDWINDOW = 0x00CF0000
  376. Local Const $WS_HSCROLL = 0x00100000
  377. Local Const $WS_VSCROLL = 0x00200000
  378. Local Const $ES_READONLY = 2048
  379. Local Const $EM_LIMITTEXT = 0xC5
  380. Local Const $GUI_HIDE = 32
  381. ; Variables used to control different aspects of the GUI.
  382. Local $w = 580, $h = 280
  383. GUICreate($__g_sReportTitle_Debug, $w, $h, -1, -1, $WS_OVERLAPPEDWINDOW)
  384. ; We use a hidden label with unique test so we can reliably identify the window.
  385. Local $idLabelHidden = GUICtrlCreateLabel($__g_sReportWindowText_Debug, 0, 0, 1, 1)
  386. GUICtrlSetState($idLabelHidden, $GUI_HIDE)
  387. Local $idEdit = GUICtrlCreateEdit("", 4, 4, $w - 8, $h - 8, BitOR($WS_HSCROLL, $WS_VSCROLL, $ES_READONLY))
  388. $__g_hReportEdit_Debug = GUICtrlGetHandle($idEdit)
  389. GUICtrlSetBkColor($idEdit, 0xFFFFFF)
  390. GUICtrlSendMsg($idEdit, $EM_LIMITTEXT, 0, 0) ; Max the size of the edit control.
  391. GUISetState()
  392. ; by default report closing will wait closing by user
  393. $__g_bReportWindowWaitClose_Debug = True
  394. Return 1
  395. EndFunc ;==>__Debug_ReportWindowCreate
  396. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  397. ; Name...........: __Debug_ReportWindowWrite
  398. ; Description ...: Append text to the report log window
  399. ; Syntax.........: __Debug_ReportWindowWrite ( $sData )
  400. ; Parameters ....: $sData text to be append to the window
  401. ; Return values .:
  402. ; Author ........: jpm
  403. ; Modified.......:
  404. ; Remarks .......:
  405. ; Related .......:
  406. ; Link ..........:
  407. ; Example .......:
  408. ; ===============================================================================================================================
  409. Func __Debug_ReportWindowWrite($sData)
  410. If $__g_bReportWindowClosed_Debug Then __Debug_ReportWindowCreate()
  411. Local Const $WM_GETTEXTLENGTH = 0x000E
  412. Local Const $EM_SETSEL = 0xB1
  413. Local Const $EM_REPLACESEL = 0xC2
  414. Local $nLen = _SendMessage($__g_hReportEdit_Debug, $WM_GETTEXTLENGTH, 0, 0, 0, "int", "int")
  415. _SendMessage($__g_hReportEdit_Debug, $EM_SETSEL, $nLen, $nLen, 0, "int", "int")
  416. _SendMessage($__g_hReportEdit_Debug, $EM_REPLACESEL, True, $sData, 0, "int", "wstr")
  417. EndFunc ;==>__Debug_ReportWindowWrite
  418. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  419. ; Name...........: __Debug_ReportWindowWaitClose
  420. ; Description ...: Wait the closing of the report log window
  421. ; Syntax.........: __Debug_ReportWindowWaitClose ( )
  422. ; Parameters ....:
  423. ; Return values .:
  424. ; Author ........: jpm
  425. ; Modified.......:
  426. ; Remarks .......:
  427. ; Related .......:
  428. ; Link ..........:
  429. ; Example .......:
  430. ; ===============================================================================================================================
  431. Func __Debug_ReportWindowWaitClose()
  432. If Not $__g_bReportWindowWaitClose_Debug Then Return 0 ; use of the already opened window so no need to wait
  433. Local $nOld = Opt("WinDetectHiddenText", $OPT_MATCHSTART)
  434. Local $hWndReportWindow = WinGetHandle($__g_sReportTitle_Debug, $__g_sReportWindowText_Debug)
  435. Opt("WinDetectHiddenText", $nOld)
  436. $nOld = Opt('GUIOnEventMode', 0) ; save event mode in case user script was using event mode
  437. Local Const $GUI_EVENT_CLOSE = -3
  438. Local $aMsg
  439. While WinExists(HWnd($hWndReportWindow))
  440. $aMsg = GUIGetMsg(1)
  441. If $aMsg[1] = $hWndReportWindow And $aMsg[0] = $GUI_EVENT_CLOSE Then GUIDelete($hWndReportWindow)
  442. WEnd
  443. Opt('GUIOnEventMode', $nOld) ; restore event mode
  444. $__g_hReportEdit_Debug = 0
  445. $__g_bReportWindowWaitClose_Debug = True
  446. $__g_bReportWindowClosed_Debug = True
  447. EndFunc ;==>__Debug_ReportWindowWaitClose
  448. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  449. ; Name...........: __Debug_ReportNotepadCreate
  450. ; Description ...: Create an report log window
  451. ; Syntax.........: __Debug_ReportNotepadCreate ( )
  452. ; Parameters ....:
  453. ; Return values .: 0 if already created
  454. ; Author ........: jpm
  455. ; Modified.......:
  456. ; Remarks .......:
  457. ; Related .......:
  458. ; Link ..........:
  459. ; Example .......:
  460. ; ===============================================================================================================================
  461. Func __Debug_ReportNotepadCreate()
  462. Local $bExists = WinExists($__g_sReportTitle_Debug)
  463. If $bExists Then
  464. If $__g_hReportEdit_Debug = 0 Then
  465. ; first time we try to access an open window in the running script,
  466. ; get the control handle needed for writing in
  467. $__g_hReportEdit_Debug = WinGetHandle($__g_sReportTitle_Debug)
  468. Return 0 ; use of the already opened window
  469. EndIf
  470. EndIf
  471. Local $pNotepad = Run("Notepad.exe") ; process ID of the Notepad started by this function
  472. $__g_hReportEdit_Debug = WinWait("[CLASS:Notepad]")
  473. If $pNotepad <> WinGetProcess($__g_hReportEdit_Debug) Then
  474. Return SetError(3, 0, 0)
  475. EndIf
  476. WinActivate($__g_hReportEdit_Debug)
  477. WinSetTitle($__g_hReportEdit_Debug, "", String($__g_sReportTitle_Debug))
  478. Return 1
  479. EndFunc ;==>__Debug_ReportNotepadCreate
  480. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  481. ; Name...........: __Debug_ReportNotepadWrite
  482. ; Description ...: Append text to the report notepad window
  483. ; Syntax.........: __Debug_ReportNotepadWrite ( $sData )
  484. ; Parameters ....: $sData text to be append to the window
  485. ; Return values .:
  486. ; Author ........: jpm
  487. ; Modified.......:
  488. ; Remarks .......:
  489. ; Related .......:
  490. ; Link ..........:
  491. ; Example .......:
  492. ; ===============================================================================================================================
  493. Func __Debug_ReportNotepadWrite($sData)
  494. If $__g_hReportEdit_Debug = 0 Then __Debug_ReportNotepadCreate()
  495. ControlCommand($__g_hReportEdit_Debug, "", "Edit1", "EditPaste", String($sData))
  496. EndFunc ;==>__Debug_ReportNotepadWrite
  497. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  498. ; Name...........: __Debug_ReportWrite
  499. ; Description ...: Write on Report
  500. ; Syntax.........: __Debug_ReportWrite ( $sData [, $bLastError [, $iCurEXT = @extended]} )
  501. ; Parameters ....:
  502. ; Return values .: $iCurEXT
  503. ; Author ........: jpm
  504. ; Modified.......:
  505. ; Remarks .......:
  506. ; Related .......:
  507. ; Link ..........:
  508. ; Example .......:
  509. ; ===============================================================================================================================
  510. Func __Debug_ReportWrite($sData, $bLastError = False, $iCurEXT = @extended)
  511. Local $sError = @CRLF
  512. If $__g_bReportTimeStamp_Debug And ($sData <> "") Then $sData = @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " " & $sData
  513. If $bLastError Then
  514. $iCurEXT = _WinAPI_GetLastError()
  515. Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x1000
  516. Local $aResult = DllCall("kernel32.dll", "dword", "FormatMessageW", "dword", $FORMAT_MESSAGE_FROM_SYSTEM, "ptr", 0, _
  517. "dword", $iCurEXT, "dword", 0, "wstr", "", "dword", 4096, "ptr", 0)
  518. ; Don't test @error since this is a debugging function.
  519. $sError = " : " & $aResult[5]
  520. EndIf
  521. $sData &= $sError
  522. Local $bBlock = BlockInput(1)
  523. BlockInput(0) ; force enable state so user can move mouse if needed
  524. $sData = StringReplace($sData, "'", "''") ; in case the data contains '
  525. Execute($__g_sReportCallBack_Debug & "'" & $sData & "')")
  526. If Not $bBlock Then BlockInput(1) ; restore disable state
  527. Return $iCurEXT
  528. EndFunc ;==>__Debug_ReportWrite