Jump to content

DebugGUI


darthwhatever
 Share

Recommended Posts

-Create a console to send debug data to, much like ConsoleWrite, only with much more options and works whether or not it is compiled

-Query whether a variable exists, what type it is, and what its value is

-output the value of macros as well

functions: _DebugGUI_Create, _DebugGUI_Write, _DebugGUI_ChangeSettings, _DebugGUI_QueryVar, _DebugGUI_Destroy

This is my first upload, so any input is appreciated!

#include-once
#include "ButtonConstants.au3"
#include "EditConstants.au3"
#include 'GUIConstantsEx.au3'
#include 'GUIListBox.au3'
#include 'WindowsConstants.au3'
#include 'GuiRichEdit.au3'

;   Title:          Debugging UDF
;   Filename:       DebugGUI.au3
;   Description:    Create a debugging console to write data to
;   Author:         darth_whatever
;   Version:        1.0
;   Requirements:   AutoIt v3.3 +, Developed/Tested on WindowsXP Pro Service Pack 2
;   Uses:           Standard Autoit3 UDF library GuiRichEdit.au3
;   Remarks:        You MUST use OnEventMode (not GUIMsgMode) in order to use the buttons on this script. I'm sorry, but thats the way this script is written.
;                   If this script used GuiMsgMode, then using this script would freeze the execution.
;
;
;   Functions:
;   _DebugGUI_Begin ( $sFilePath = 0, $iBkColor = 0x000000, $iAutoShowOnCritical = 1, $iShowFlag = @SW_SHOW, $sWinTitle = @ScriptName, $iAlwaysOnTop = False, _
;       $iWidth = 406, $iHeight = 432, $iLeft = 438, $iTop = 282 )
;   Begins debugging session. Returns 0 and sets @error to 1 if the debugging session has already been started.
;   Success: returns handle to the GUI
;       $sFilePath: path of the file to stream text to. If this is 0, no file is used
;       $iBkColor: the background color to use for the Rich edit control. Default is black
;       $iAutoShowOnCritical: Automatically set the state of the GUI to @SW_SHOW on a critical message
;       $iShowFlag: the beginning state of the GUI
;       $sWinTitle: the title of the debugging window
;       $iWidth, $iHeight, $iLeft, $iTop: size/position of window
;
;   _DebugGUI_Write ( $sData , $iColor = $iDebugGUI_standard, $iBkColor = 0x000000 )
;   Writes debugging data. Returns 0 and sets @error to 1 if the debugging session has not been started.
;       $sData: the data to write
;       $iColor: the color of the text to use
;       $iBkColor: the background color to use
;
;   _DebugGUI_QueryVar( $sVarName = False, $iColor = $iDebugGUI_standard )
;   Check to see if a macro variable is declared, and show its value on the console.
;       $sVarName: name of the variable or macro. THIS MUST BE THE NAME OF THE VARIABLE, NOT THE VARIABLE ITSELF!
;       $iColor: Color in which to show the text
;
;   _DebugGUI_ChangeSettings ( $sFilePath = 0, $iBkColor = 0x000000, $iAutoShowOnCritical = 1, $iShowFlag = @SW_SHOW, $sWinTitle = @ScriptName , $iAlwaysOnTop)
;   Change one or more of the settings for the main GUI. Parameters should be pretty obvious
;   If you call this function with no
;
;   _DebugGUI_Destroy ( )
;   Ends debugging session. If you did not specify an output file, this deletes all debugging data that you already have!


Global $iDebugGUI_standard = 0xFFFFFF, _
        $iDebugGUI_warning = 0x00FFFF, _
        $iDebugGUI_error = 0xFFFF00, _
        $iDebugGUI_critical = 0x0000FF, _
        $iDebugGUI_ResumeSet, _
        $iDebugGUI, _
        $hDebugGUI_MainWindow, _
        $hDebugGUI_RichEdit, _
        $hDebugGUI_Button4, _
        $hDebugGUI_Button5, _
        $hDebugGUI_Input1, _
        $iDebugGUI_AutoShowOnCritical, _
        $sDebugGUI_FilePath
OnAutoItExitRegister('_DebugGUI_ExitFunc')
Func _DebugGUI_Begin($sFilePath = False, $iBkColor = 0x000000, $iAutoShowOnCritical = 1, $iShowFlag = @SW_SHOW, $sWinTitle = @ScriptName, $iAlwaysOnTop = False, _
        $iWidth = 406, $iHeight = 432, $iLeft = 438, $iTop = 282, $iEventMode = 1)
    If $iDebugGUI Then Return SetError(1, 0, 0)
    $iOnEventMode = Opt("GUIOnEventMode", 1)
    $iDebugGUI = True
    $hDebugGUI_MainWindow = GUICreate($sWinTitle, $iWidth, $iHeight, $iLeft, $iTop)
    Opt("GUIOnEventMode", 1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_DebugGUI_SpecialEvents")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "_DebugGUI_SpecialEvents")
    GUISetOnEvent($GUI_EVENT_RESTORE, "_DebugGUI_SpecialEvents")
    $hDebugGUI_RichEdit = _GUICtrlRichEdit_Create($hDebugGUI_MainWindow, "", 10, 10, $iWidth - 20, $iHeight - 212, BitOR($ES_NOHIDESEL, $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_SetBkColor($hDebugGUI_RichEdit, $iBkColor)
    _GUICtrlRichEdit_SetCharColor($hDebugGUI_RichEdit, $iDebugGUI_standard)
;~  _GUICtrlRichEdit_SetCharAttributes($hDebugGUI_RichEdit, '+bo') ;consider skipping this to fit more text on the screen
    _GUICtrlRichEdit_SetReadOnly($hDebugGUI_RichEdit, True)
    $hDebugGUI_Button1 = GUICtrlCreateButton("Select All", 16, $iHeight - 160, 89, 25, $WS_GROUP)
    GUICtrlSetOnEvent(-1, "_DebugGUI_SelectAll")
    $hDebugGUI_Button2 = GUICtrlCreateButton("Copy Selected", 120, $iHeight - 160, 97, 25, $WS_GROUP)
    GUICtrlSetOnEvent(-1, "_DebugGUI_copySelected")
    $hDebugGUI_Input1 = GUICtrlCreateInput("", 16, $iHeight - 104, 265, 21)
    $hDebugGUI_Button3 = GUICtrlCreateButton("Query Variable", 296, $iHeight - 104, 97, 25, $WS_GROUP)
    GUICtrlSetOnEvent(-1, "_DebugGUI_QueryVar")
    $hDebugGUI_Button4 = GUICtrlCreateButton("Pause Script", 16, $iHeight - 62, 89, 25, $WS_GROUP)
    GUICtrlSetOnEvent(-1, "_DebugGUI_pause")
    $hDebugGUI_Button5 = GUICtrlCreateButton("Resume Script", 120, $iHeight - 62, 89, 25, $WS_GROUP)
    GUICtrlSetOnEvent(-1, "_DebugGUI_resume")
    GUICtrlSetState($hDebugGUI_Button5, $GUI_DISABLE)
    GUISetState($iShowFlag)
    WinSetOnTop($hDebugGUI_MainWindow, '', $iAlwaysOnTop)
    $iDebugGUI_AlwaysOnTop  =- $iAlwaysOnTop
    $sDebugGUI_FilePath = $sFilePath
    If $iAutoShowOnCritical Then $iDebugGUI_AutoShowOnCritical = True
    Opt("GUIOnEventMode", $iOnEventMode)
    If Not $iOnEventMode Then
        _DebugGUI_Write('Error: OnEventMode is not enabled. None of the buttons will work.', $iDebugGUI_warning)
        GUICtrlSetState($hDebugGUI_Button1, $GUI_DISABLE)
        GUICtrlSetState($hDebugGUI_Button2, $GUI_DISABLE)
        GUICtrlSetState($hDebugGUI_Button3, $GUI_DISABLE)
        GUICtrlSetState($hDebugGUI_Button4, $GUI_DISABLE)
        GUICtrlSetState($hDebugGUI_Button5, $GUI_DISABLE)
        GUICtrlSetState($hDebugGUI_Input1, $GUI_DISABLE)
        Return SetError(2, 0, $hDebugGUI_MainWindow)
    EndIf
    Return $hDebugGUI_MainWindow
EndFunc   ;==>_DebugGUI_Begin
Func _DebugGUI_ChangeSettings($sFilePath = 0, $iBkColor = 0x000000, $iAutoShowOnCritical = 1, $iShowFlag = @SW_SHOW, $sWinTitle = @ScriptName, $iAlwaysOnTop = False )
    If Not $iDebugGUI Then Return SetError(101, 0, 0)
    If @NumParams >= 1 Then $sDebugGUI_FilePath = $sFilePath
    If @NumParams >= 2 Then
        _GUICtrlRichEdit_SetSel($hDebugGUI_RichEdit, -1, -1)
        _GUICtrlRichEdit_SetBkColor($hDebugGUI_RichEdit, $iBkColor)
    EndIf
    If @NumParams >= 3 Then $iDebugGUI_AutoShowOnCritical = $iAutoShowOnCritical
    If @NumParams >= 4 Then GUISetState($iShowFlag, $hDebugGUI_MainWindow)
    If @NumParams >= 5 Then WinSetTitle($hDebugGUI_MainWindow, '', $sWinTitle)
    if @NumParams >= 6 then WinSetOnTop($hDebugGUI_MainWindow, '', $iAlwaysOnTop)
    If @NumParams = 0 Then ;return everything to default
        $sDebugGUI_FilePath = $sFilePath
        _GUICtrlRichEdit_SetSel($hDebugGUI_RichEdit, -1, -1)
        _GUICtrlRichEdit_SetBkColor($hDebugGUI_RichEdit, $iBkColor)
        $iDebugGUI_AutoShowOnCritical = $iAutoShowOnCritical
        GUISetState($iShowFlag, $hDebugGUI_MainWindow)
        WinSetTitle($hDebugGUI_MainWindow, '', $sWinTitle)
        WinSetOnTop($hDebugGUI_MainWindow, '', $iAlwaysOnTop)
    EndIf
EndFunc   ;==>_DebugGUI_ChangeSettings
#Region GUI Controls
Func _DebugGUI_pause()
    GUICtrlSetState($hDebugGUI_Button4, $GUI_DISABLE)
    GUICtrlSetState($hDebugGUI_Button5, $GUI_ENABLE)
    Do
        Sleep(120)
    Until $iDebugGUI_ResumeSet
    GUICtrlSetState($hDebugGUI_Button4, $GUI_ENABLE)
    GUICtrlSetState($hDebugGUI_Button5, $GUI_DISABLE)
    $iDebugGUI_ResumeSet = False
    Return
EndFunc   ;==>_DebugGUI_pause
Func _DebugGUI_resume()
    Global $iDebugGUI_ResumeSet = True
EndFunc   ;==>_DebugGUI_resume
Func _DebugGUI_QueryVar($sVarName = False, $iColor = 0xFFFFFF)
    if not $iDebugGUI Then Return
    Local $vVar
    If @NumParams = 0 Then $sVarName = GUICtrlRead($hDebugGUI_Input1)
    If $sVarName = '' Then Return SetError(1, 0, 0)
    GUICtrlSetData($hDebugGUI_Input1, '')
;~  If Not IsDeclared($sVarName) Then
;~      _DebugGUI_Write($sVarName & ' is not declared!', $iDebugGUI_error)
;~      Return
;~  EndIf
    If StringLeft($sVarName, 1) = '@' Then
        Switch $sVarName
            Case '@AppDataCommonDir'
                $vVar = @AppDataCommonDir
            Case '@AppDataDir'
                $vVar = @AppDataDir
            Case '@AutoItExe'
                $vVar = @AutoItExe
            Case '@AutoItPID'
                $vVar = @AutoItPID
            Case '@AutoItVersion'
                $vVar = @AutoItVersion
            Case '@AutoItX64'
                $vVar = @AutoItX64
            Case '@CommonFilesDir'
                $vVar = @CommonFilesDir
            Case '@Compiled'
                $vVar = @Compiled
            Case '@ComputerName'
                $vVar = @ComputerName
            Case '@ComSpec'
                $vVar = @ComSpec
            Case '@CPUArch'
                $vVar = @CPUArch
            Case '@CR'
                $vVar = @CR
            Case '@CRLF'
                $vVar = @CRLF
            Case '@LF'
                $vVar = @LF
            Case '@DesktopCommonDir'
                $vVar = @DesktopCommonDir
            Case '@DesktopDir'
                $vVar = @DesktopDir
            Case '@DesktopHeight'
                $vVar = @DesktopHeight
            Case '@DesktopWidth'
                $vVar = @DesktopWidth
            Case '@DesktopDepth'
                $vVar = @DesktopDepth
            Case '@DesktopRefresh'
                $vVar = @DesktopRefresh
            Case '@DocumentsCommonDir'
                $vVar = @DocumentsCommonDir
            Case '@error'
                $vVar = @error
            Case '@exitCode'
                $vVar = @exitCode
            Case '@exitMethod'
                $vVar = @exitMethod
            Case '@extended'
                $vVar = @extended
            Case '@FavoritesDir'
                $vVar = @FavoritesDir
            Case '@FavoritesCommonDir'
                $vVar = @FavoritesCommonDir
            Case '@HomeDrive'
                $vVar = @HomeDrive
            Case '@HomePath'
                $vVar = @HomePath
            Case '@HomeShare'
                $vVar = @HomeShare
            Case '@HOUR'
                $vVar = @HOUR
            Case '@IPAddress1'
                $vVar = @IPAddress1
            Case '@IPAddress2'
                $vVar = @IPAddress2
            Case '@IPAddress3'
                $vVar = @IPAddress3
            Case '@IPAddress4'
                $vVar = @IPAddress4
            Case '@KBLayout'
                $vVar = @KBLayout
            Case '@LogonDNSDomain'
                $vVar = @LogonDNSDomain
            Case '@LogonDomain'
                $vVar = @LogonDomain
            Case '@LogonServer'
                $vVar = @LogonServer
            Case '@MDAY'
                $vVar = @MDAY
            Case '@MIN'
                $vVar = @MIN
            Case '@MON'
                $vVar = @MON
            Case '@MSEC'
                $vVar = @MSEC
            Case '@MUILang'
                $vVar = @MUILang
            Case '@MyDocumentsDir'
                $vVar = @MyDocumentsDir
            Case '@OSArch'
                $vVar = @OSArch
            Case '@OSBuild'
                $vVar = @OSBuild
            Case '@OSLang'
                $vVar = @OSLang
            Case '@OSServicePack'
                $vVar = @OSServicePack
            Case '@OSType'
                $vVar = @OSType
            Case '@OSVersion'
                $vVar = @OSVersion
            Case '@ProgramFilesDir'
                $vVar = @ProgramFilesDir
            Case '@ProgramsCommonDir'
                $vVar = @ProgramsCommonDir
            Case '@ProgramsDir'
                $vVar = @ProgramsDir
            Case '@ScriptDir'
                $vVar = @ScriptDir
            Case '@ScriptFullPath'
                $vVar = @ScriptFullPath
            Case '@ScriptLineNumber'
                $vVar = @ScriptLineNumber
            Case '@ScriptName'
                $vVar = @ScriptName
            Case '@SEC'
                $vVar = @SEC
            Case '@StartMenuCommonDir'
                $vVar = @StartMenuCommonDir
            Case '@StartMenuDir'
                $vVar = @StartMenuDir
            Case '@StartupCommonDir'
                $vVar = @StartupCommonDir
            Case '@StartupDir'
                $vVar = @StartupDir
            Case '@SW_DISABLE'
                $vVar = @SW_DISABLE
            Case '@SW_ENABLE'
                $vVar = @SW_ENABLE
            Case '@SW_HIDE'
                $vVar = @SW_HIDE
            Case '@SW_LOCK'
                $vVar = @SW_LOCK
            Case '@SW_MAXIMIZE'
                $vVar = @SW_MAXIMIZE
            Case '@SW_MINIMIZE'
                $vVar = @SW_MINIMIZE
            Case '@SW_RESTORE'
                $vVar = @SW_RESTORE
            Case '@SW_SHOW'
                $vVar = @SW_SHOW
            Case '@SW_SHOWDEFAULT'
                $vVar = @SW_SHOWDEFAULT
            Case '@SW_SHOWMAXIMIZED'
                $vVar = @SW_SHOWMAXIMIZED
            Case '@SW_SHOWMINIMIZED'
                $vVar = @SW_SHOWMINIMIZED
            Case '@SW_SHOWMINNOACTIVE'
                $vVar = @SW_SHOWMINNOACTIVE
            Case '@SW_SHOWNA'
                $vVar = @SW_SHOWNA
            Case '@SW_SHOWNOACTIVATE'
                $vVar = @SW_SHOWNOACTIVATE
            Case '@SW_SHOWNORMAL'
                $vVar = @SW_SHOWNORMAL
            Case '@SW_UNLOCK'
                $vVar = @SW_UNLOCK
            Case '@SystemDir'
                $vVar = @SystemDir
            Case '@TAB'
                $vVar = @TAB
            Case '@TempDir'
                $vVar = @TempDir
            Case '@TRAY_ID'
                $vVar = @TRAY_ID
            Case '@TrayIconFlashing'
                $vVar = @TrayIconFlashing
            Case '@TrayIconVisible'
                $vVar = @TrayIconVisible
            Case '@UserProfileDir'
                $vVar = @UserProfileDir
            Case '@UserName'
                $vVar = @UserName
            Case '@WDAY'
                $vVar = @WDAY
            Case '@WindowsDir'
                $vVar = @WindowsDir
            Case '@WorkingDir'
                $vVar = @WorkingDir
            Case '@YDAY'
                $vVar = @YDAY
            Case '@YEAR'
                $vVar = @YEAR
            Case Else
                _DebugGUI_Write('Error: unrecognized macro', $iDebugGUI_error)
                Return SetError(4, 0, 0)
        EndSwitch
        _DebugGUI_Write('Value of macro ' & $sVarName & ': ' & $vVar)
        Return
    EndIf
    If StringLeft($sVarName, 1) = '$' Then
        $sVarName = StringTrimLeft($sVarName, 1)
    EndIf
    $vVar = Eval($sVarName)
    If @error Then
        _DebugGUI_Write('Error: ' & $sVarName & ' is not declared!', $iDebugGUI_error)
        Return SetError(2, 0, 0)
    EndIf
    $sVarName = '$' & $sVarName
    If IsArray($vVar) Then
        For $i = 0 To UBound($vVar) - 1
            If $vVar[$i] = '' Then
                _DebugGUI_Write('Warning: ' & $sVarName & '[' & $i & '] is declared, but has no value', $iDebugGUI_warning)
                ContinueLoop
            EndIf
            _DebugGUI_Write('Value of ' & $sVarName & '[' & $i & ']: ' & $vVar[$i])
            If IsPtr($vVar[$i]) Then _DebugGUI_Write($sVarName & '[' & $i & '] is pointer type')
            If IsBinary($vVar[$i]) Then _DebugGUI_Write($sVarName & '[' & $i & '] is binary type')
            If IsBool($vVar[$i]) Then _DebugGUI_Write($sVarName & '[' & $i & '] is boolean type')
            If IsDllStruct($vVar[$i]) Then _DebugGUI_Write($sVarName & '[' & $i & '] is DllStruct type')
            If IsFloat($vVar[$i]) Then _DebugGUI_Write($sVarName & '[' & $i & '] is floating type')
            If IsHWnd($vVar[$i]) Then _DebugGUI_Write($sVarName & '[' & $i & '] is HWnd type')
            If IsInt($vVar[$i]) Then _DebugGUI_Write($sVarName & '[' & $i & '] is integer type')
            If IsObj($vVar[$i]) Then _DebugGUI_Write($sVarName & '[' & $i & '] is object type')
            If IsString($vVar[$i]) Then _DebugGUI_Write($sVarName & '[' & $i & '] is string type')
        Next
        Return
    Else
        If $vVar = '' Then
            _DebugGUI_Write('Warning: ' & $sVarName & ' is declared, but has no value', $iDebugGUI_warning)
            Return SetError(3, 0, 0)
        EndIf
        If IsPtr($vVar) Then _DebugGUI_Write($sVarName & ' is pointer type')
        If IsBinary($vVar) Then _DebugGUI_Write($sVarName & ' is binary type')
        If IsBool($vVar) Then _DebugGUI_Write($sVarName & ' is boolean type')
        If IsDllStruct($vVar) Then _DebugGUI_Write($sVarName & ' is DllStruct type')
        If IsFloat($vVar) Then _DebugGUI_Write($sVarName & ' is floating type')
        If IsHWnd($vVar) Then _DebugGUI_Write($sVarName & ' is HWnd type')
        If IsInt($vVar) Then _DebugGUI_Write($sVarName & ' is integer type')
        If IsObj($vVar) Then _DebugGUI_Write($sVarName & ' is object type')
        If IsString($vVar) Then _DebugGUI_Write($sVarName & ' is string type')
        _DebugGUI_Write('Value of ' & $sVarName & ': ' & $vVar)
    EndIf
EndFunc   ;==>_DebugGUI_QueryVar
Func _DebugGUI_CopySelected()
    Local $iSel, $sData
    $iSel = _GUICtrlRichEdit_GetSel($hDebugGUI_RichEdit)
    If @error Then Return SetError(1, 0, 0)
    If $iSel[0] = $iSel[1] Then Return
    $sData = _GUICtrlRichEdit_GetSelText($hDebugGUI_RichEdit)
    If @error Then Return SetError(2, 0, 0)
    ClipPut($sData)
    Return $sData
EndFunc   ;==>_DebugGUI_CopySelected
Func _DebugGUI_SelectAll()
    _GUICtrlRichEdit_SetSel($hDebugGUI_RichEdit, 0, -1)
EndFunc   ;==>_DebugGUI_SelectAll
Func _DebugGUI_SpecialEvents()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            _DebugGUI_Destroy()
        Case $GUI_EVENT_MINIMIZE
            WinSetState($hDebugGUI_MainWindow, '', @SW_MINIMIZE)
        Case $GUI_EVENT_RESTORE
            WinSetState($hDebugGUI_MainWindow, '', @SW_RESTORE)
    EndSwitch
EndFunc   ;==>_DebugGUI_SpecialEvents
#EndRegion GUI Controls
Func _DebugGUI_Write($sData, $iColor = $iDebugGUI_standard, $iBkColor = 0x000000)
    If Not $iDebugGUI Then Return SetError(1, 0, 0)
    Local $iLines = _GUICtrlRichEdit_GetSel($hDebugGUI_RichEdit)
;~  _GUICtrlRichEdit_SetCharAttributes($hDebugGUI_RichEdit, '+bo')
    _GUICtrlRichEdit_AppendText($hDebugGUI_RichEdit, $sData & @CRLF)
    _GUICtrlRichEdit_SetSel($hDebugGUI_RichEdit, $iLines[0], -1)
    _GUICtrlRichEdit_SetCharColor($hDebugGUI_RichEdit, $iColor)
    _GUICtrlRichEdit_SetCharBkColor($hDebugGUI_RichEdit, $iBkColor)
    _GUICtrlRichEdit_SetSel($hDebugGUI_RichEdit, -1, -1)
    If $iColor = $iDebugGUI_critical And $iDebugGUI_AutoShowOnCritical Then
        GUISetState(@SW_SHOW, $hDebugGUI_MainWindow)
        WinFlash($hDebugGUI_MainWindow, '', 1)
    EndIf
EndFunc   ;==>_DebugGUI_Write
Func _DebugGUI_ExitFunc()
    If $sDebugGUI_FilePath Then
        _GUICtrlRichEdit_SetSel($hDebugGUI_RichEdit, 0, -1)
        _GUICtrlRichEdit_SetBkColor($hDebugGUI_RichEdit, 0xFFFFFF)
        _GUICtrlRichEdit_StreamToFile($hDebugGUI_RichEdit, $sDebugGUI_FilePath)
    EndIf
    _GUICtrlRichEdit_Destroy($hDebugGUI_RichEdit)
    GUIDelete($hDebugGUI_MainWindow)
EndFunc   ;==>_DebugGUI_ExitFunc
Func _DebugGUI_Destroy()
    If $iDebugGUI Then
        _GUICtrlRichEdit_Destroy($hDebugGUI_RichEdit)
        GUIDelete($hDebugGUI_MainWindow)
    EndIf
If $sDebugGUI_FilePath Then
        _GUICtrlRichEdit_SetSel($hDebugGUI_RichEdit, 0, -1)
        _GUICtrlRichEdit_SetBkColor($hDebugGUI_RichEdit, 0xFFFFFF)
        _GUICtrlRichEdit_StreamToFile($hDebugGUI_RichEdit, $sDebugGUI_FilePath)
    EndIf
    $iDebugGUI = False
EndFunc   ;==>_DebugGUI_Destroy
Func _DebugGUI_GUICtrlRichEdit_StreamToFile($hWnd, $sFileSpec, $fIncludeCOM = True, $iOpts = 0, $iCodePage = 0)
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _GUICtrlRichEdit_StreamToFile
    ; Description....: Writes contens of a control to a file
    ; Syntax ........: _GUICtrlRichEdit_StreamToFile($hWnd, $sFilespec[, $fIncludeCOM=True[, $iOpts=0[, $iCodePage = 0]]])
    ; Parameters.....: $hWnd        - Handle to the control
    ;                  $sFileSpec - file specification
    ;                  $fIncludeCOM - (Optional)
    ;                  |True (default):
    ;                  |    If writing to a .rtf file, includes any COM objects (space consuming)
    ;                  |    If writing to any other file, writes a text represntation of COM objects
    ;                  |False: Writes spaces instead of COM objects
    ;                  $iOpts - additional options: (Optional) (default: 0)
    ;                  |$SFF_PLAINTRTF - write only rich text keywords common to all languages
    ;                  |$SF_UNICODE    - write Unicode
    ;                  $iCodePage - Generate UTF-8 and text using this code page (Optional)
    ;                  |Default: do not
    ; Return values..: Success - True
    ;                  Failure - False and sets @error:
    ;                  |101  - $hWnd is not a handle
    ;                  |102  - Can't create $sFilespec
    ;                  |1041 - $SFF_PLAINRTF is invalid for a text file
    ;                  |1042 - $opts: invalid option
    ;                  |1043 - $SF_UNICODE is only valid for a text file
    ;                  |700  - internal error
    ; Authors........: Chris Haslam (c.haslam)
    ; Modified ......:
    ; Remarks .......: If text is selected, writes only the selection, else writes all text in the control
    ;+
    ;                  If the extension in $sFileSpec is .rtf, RTF is written, else text
    ; Related .......: _GUICtrlRichEdit_SetLimitOnText, _GUICtrlRichEdit_StreamFromVar, _GUICtrlRichEdit_StreamToFile
    ; Link ..........: @@MsdnLink@@ EM_STREAMIN
    ; Example .......: Yes
    ; ===============================================================================================================================
    If Not IsHWnd($hWnd) Then Return SetError(101, 0, False)

    Local $iWparam
    If StringRight($sFileSpec, 4) = ".rtf" Then
        $iWparam = _Iif($fIncludeCOM, $SF_RTF, $SF_RTFNOOBJS)
    Else
        $iWparam = _Iif($fIncludeCOM, $SF_TEXTIZED, $SF_TEXT)
        If BitAND($iOpts, $SFF_PLAINRTF) Then Return SetError(1041, 0, False)
    EndIf
    ; only opts are $SFF_PLAINRTF and $SF_UNICODE
    If BitAND($iOpts, BitNOT(BitOR($SFF_PLAINRTF, $SF_UNICODE))) Then Return SetError(1042, 0, False)
    If BitAND($iOpts, $SF_UNICODE) Then
        If Not BitAND($iWparam, $SF_TEXT) Then Return SetError(1043, 0, False)
    EndIf

    If _GUICtrlRichEdit_IsTextSelected($hWnd) Then $iWparam = BitOR($iWparam, $SFF_SELECTION)

    $iWparam = BitOR($iWparam, $iOpts)
    If $iCodePage <> 0 Then
        $iWparam = BitOR($iWparam, $SF_USECODEPAGE, BitShift($iCodePage, -16))
    EndIf
    Local $tEditStream = DllStructCreate($tagEDITSTREAM)
    DllStructSetData($tEditStream, "pfnCallback", DllCallbackGetPtr($_GRC_StreamToFileCallback))
    Local $hFile = FileOpen($sFileSpec, 2) ; overwrite
    If $hFile - 1 Then Return SetError(102, 0, False)

    DllStructSetData($tEditStream, "dwCookie", $hFile) ; -> Send handle to CallbackFunc
    _SendMessage($hWnd, $EM_STREAMOUT, $iWparam, DllStructGetPtr($tEditStream))
    FileClose($hFile)
    Local $iError = DllStructGetData($tEditStream, "dwError")
    If $iError <> 0 Then SetError(700, $iError, False)
    Return True
EndFunc   ;==>_DebugGUI_GUICtrlRichEdit_StreamToFile

example:

#include <DebugGUI.au3>

Global $i, $hDebugWindow, $temp, $aArray[4] = [1, DllStructCreate("int var1;ubyte var2;uint var3;char var4[128]"), 4, 'five']
Opt('GUIOnEventMode', 1)

$hDebugWindow = _DebugGUI_Begin(@DesktopDir & '\example.rtf', 0x000000, False, @SW_HIDE, StringTrimRight(@ScriptName, 4), 500, 600)
;stream to file on the desktop, background is black, GUI is not set to @SW_SHOW on a critical error, GUI starts as hidden, title of window is @scriptname, size of window is 500x600
GUISetState(@SW_SHOW, $hDebugWindow)
While 1
    Sleep(1000)
    $i += 1
    If $i < 5 Then
        _DebugGUI_Write($i & ' seconds.', $iDebugGUI_standard)
        If $i = 3 Then GUISetState(@SW_SHOW, $hDebugWindow)
    ElseIf $i >= 5 And $i < 10 Then
        _DebugGUI_Write($i & ' seconds.', $iDebugGUI_warning)
    ElseIf $i >= 10 And $i < 15 Then
        _DebugGUI_Write($i & ' seconds.', $iDebugGUI_error)
    ElseIf $i >= 15 And $i < 20 Then
        _DebugGUI_Write($i & ' seconds!', $iDebugGUI_critical)
    Else
        ExitLoop
    EndIf
WEnd

_DebugGUI_QueryVar($hDebugWindow, $iDebugGUI_standard) ;!! will not work because func searches for var with the value of $hDebugWindow
_DebugGUI_QueryVar('$temp', $iDebugGUI_warning)
_DebugGUI_QueryVar('hDebugWindow', $iDebugGUI_error) ;will work, string does not need $ at beginning
_DebugGUI_QueryVar('@ScriptName', $iDebugGUI_critical) ;works with macros, but only if they begin with @
_DebugGUI_QueryVar('$aArray', $iDebugGUI_error) ;works on arrays

While 1
    Sleep(100)
WEnd
_debugGUI_Destroy()
Edited by darthwhatever

[font=arial, sans-serif]How is education supposed to make me feel smarter? Besides, every time I learn something new, it pushes some old stuff out of my brain. Remember when I took that home winemaking course, and I forgot how to drive?[/font][font=arial, sans-serif]<div>This is how you annoy a web developer.</span>[/font]

Link to comment
Share on other sites

Always good to have an extra debugger in pure autoit! I would call the UDF "Debug.au3" and then it would be nice to have to options

1) To start the gui (DebugGui.exe) and debug from there by selecting a script from the gui. Similar to what the C# debugger for Autoit does (Autoit GUI debugger)

2) Add the Debug.au3 to a script and let the debugger write to the console

BTW: Don't for to close the quotes for $sVarName, otherwise the UDF gives an error

Line 349 If StringLeft($sVarName, 1) = '' Then

Line 357 $sVarName = '' & $sVarName

Link to comment
Share on other sites

sorry about the slow reply - I have only intermittent access to the internet

this is supposed to be compiled with the script - start in debug mode if there is some command line, or if there is some error

I wrote it this way because the scripts that I write invariably don't work on other computers, so I wanted something to try and find out what was going wrong

[font=arial, sans-serif]How is education supposed to make me feel smarter? Besides, every time I learn something new, it pushes some old stuff out of my brain. Remember when I took that home winemaking course, and I forgot how to drive?[/font][font=arial, sans-serif]<div>This is how you annoy a web developer.</span>[/font]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...