Что нового

GUICtrlRichEdit UDF - Создание RichEdit-элемента

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8 160
Репутация
2 329
Внимание: Данная библиотека была добавлена в основной пакет AutoIt (3.3.6.1).



AutoIt: 3.3.6.1
Версия: 0.5

Категория: Элементы GUI

Описание: Библиотека позволяющая создавать RichEdit-элемент, который в отличии от обычного Edit-элемента поддерживает форматирование текста.

Список поддерживаемых функции:
Код:
;_GUICtrlRichEdit_AppendText
;_GUICtrlRichEdit_AutoDetectURL
;_GUICtrlRichEdit_CanPaste
;_GUICtrlRichEdit_CanPasteSpecial
;_GUICtrlRichEdit_CanRedo
;_GUICtrlRichEdit_CanUndo
;_GUICtrlRichEdit_ChangeFontSize
;_GUICtrlRichEdit_Copy
;_GUICtrlRichEdit_Create
;_GUICtrlRichEdit_Cut
;_GUICtrlRichEdit_Deselect
;_GUICtrlRichEdit_Destroy
;_GUICtrlRichEdit_EmptyUndoBuffer
;_GUICtrlRichEdit_FindText
;_GUICtrlRichEdit_FindTextInRange
;_GUICtrlRichEdit_GetCharAttributes
;_GUICtrlRichEdit_GetCharPosFromXY
;_GUICtrlRichEdit_GetCharPosOfNextWord
;_GUICtrlRichEdit_GetCharPosOfPreviousWord
;_GUICtrlRichEdit_GetCharWordBreakInfo
;_GUICtrlRichEdit_GetCtrlText
;_GUICtrlRichEdit_GetCtrlTextLength
;_GUICtrlRichEdit_GetCtrlZoom
;_GUICtrlRichEdit_GetFirstCharPosOnLine
;_GUICtrlRichEdit_GetFont
;_GUICtrlRichEdit_GetFormattingRect
;_GUICtrlRichEdit_GetLineCount
;_GUICtrlRichEdit_GetLineLength
;_GUICtrlRichEdit_GetLineNUmberFromCharPos
;_GUICtrlRichEdit_GetNextRedo
;_GUICtrlRichEdit_GetNextUndo
;_GUICtrlRichEdit_GetNumberOfFirstVisibleLine
;_GUICtrlRichEdit_GetParaAlignment
;_GUICtrlRichEdit_GetParaAttributes
;_GUICtrlRichEdit_GetParaBorder
;_GUICtrlRichEdit_GetParaIndents
;_GUICtrlRichEdit_GetParaNumbering
;_GUICtrlRichEdit_GetParaShading
;_GUICtrlRichEdit_GetParaSpacing
;_GUICtrlRichEdit_GetParaTabStops
;_GUICtrlRichEdit_GetPasswordChar
;_GUICtrlRichEdit_GetScrollPos
;_GUICtrlRichEdit_GetSel
;_GUICtrlRichEdit_GetSelAA
;_GUICtrlRichEdit_GetSelText
;_GUICtrlRichEdit_GetSpaceUnit
;_GUICtrlRichEdit_GetTextinLine
;_GUICtrlRichEdit_GetTextInRange
;_GUICtrlRichEdit_GetVersion
;_GUICtrlRichEdit_GetXYFromCharPos
;_GUICtrlRichEdit_GotoCharPos
;_GUICtrlRichEdit_HideSelection
;_GUICtrlRichEdit_InsertText
;_GUICtrlRichEdit_IsModified
;_GUICtrlRichEdit_IsTextSelected
;_GUICtrlRichEdit_Paste
;_GUICtrlRichEdit_PasteSpecial
;_GUICtrlRichEdit_PauseRedraw
;_GUICtrlRichEdit_Redo
;_GUICtrlRichEdit_ReplaceText
;_GUICtrlRichEdit_ResumeRedraw
;_GUICtrlRichEdit_ScrollLineOrPage
;_GUICtrlRichEdit_ScrollLines
;_GUICtrlRichEdit_ScrollToCaret
;_GUICtrlRichEdit_SetCharAttributes
;_GUICtrlRichEdit_SetCtrlBkColor
;_GUICtrlRichEdit_SetCtrlLimitOnText
;_GUICtrlRichEdit_SetCtrlTabStops
;_GUICtrlRichEdit_SetCtrlZoom
;_GUICtrlRichEdit_SetEventMask
;_GUICtrlRichEdit_SetFont
;_GUICtrlRichEdit_SetModified
;_GUICtrlRichEdit_SetParaAlignment
;_GUICtrlRichEdit_SetParaAttributes
;_GUICtrlRichEdit_SetParaBorder
;_GUICtrlRichEdit_SetParaIndents
;_GUICtrlRichEdit_SetParaNumbering
;_GUICtrlRichEdit_SetParaShading
;_GUICtrlRichEdit_SetParaSpacing
;_GUICtrlRichEdit_SetParaTabStops
;_GUICtrlRichEdit_SetPasswordChar
;_GUICtrlRichEdit_SetScrollPos
;_GUICtrlRichEdit_SetSel
;_GUICtrlRichEdit_SetSpaceUnit
;_GUICtrlRichEdit_SetText
;_GUICtrlRichEdit_SetUndoLimit
;_GUICtrlRichEdit_StreamFromFile
;_GUICtrlRichEdit_StreamFromVar
;_GUICtrlRichEdit_StreamToFile
;_GUICtrlRichEdit_StreamToVar
;_GUICtrlRichEdit_Undo

Код/Пример:
Код:
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GUIRichEdit.au3>
;

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("GUI Log Demo", 320, 200, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_CLIPSIBLINGS))
GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI_Events")

$hRichText = _GUICtrlRichEdit_Create($hGUI, "", 0, 0, 320, 200, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
_GUICtrlRichEdit_SetReadOnly($hRichText, True)
_GUICtrlRichEdit_HideSelection($hRichText, True)

GUISetState(@SW_SHOW, $hGUI)

Copy_Process()

While 1
	Switch GUIGetMsg()
		Case $GUI_EVENT_CLOSE
			Exit
	EndSwitch
WEnd

Func _GUI_Events()
	Switch @GUI_CtrlId
		Case $GUI_EVENT_CLOSE
			Exit
	EndSwitch
EndFunc

Func Copy_Process()
	Local $aAction[10], $aResult[10][2]
	Local $aExts[5] = [".txt", ".png", ".doc", ".exe", ".au3"]
	
	For $i = 0 To 8 Step 2
		$aAction[$i] = "Копирую"
		$aAction[$i+1] = "Архивирую"
		
		$aResult[$i][0] = "Успешно!"
		$aResult[$i][1] = 0x008000
		$aResult[$i+1][0] = "Ошибка!"
		$aResult[$i+1][1] = 0x0000FF
	Next
	
	For $i = 0 To 4
		$iRnd_Action = Random(0, 9, 1)
		$iRnd_Result = Random(0, 9, 1)
		$iRnd_Exts = Random(0, 4, 1)
		
		_Write_GUI_Log($aAction[$iRnd_Action] & " " & _FileGetRandomName($aExts[$iRnd_Exts]) & "... ", 1, 0x666666)
		Sleep(1500)
		_Write_GUI_Log($aResult[$iRnd_Result][0] & @CRLF & @CRLF, 1, $aResult[$iRnd_Result][1], True)
		
		Sleep(1000)
		
		$iRnd_Action = Random(0, 9, 1)
		$iRnd_Result = Random(0, 9, 1)
		$iRnd_Exts = Random(0, 4, 1)
		
		_Write_GUI_Log($aAction[$iRnd_Action] & " " & _FileGetRandomName($aExts[$iRnd_Exts]) & "... ", 1, 0x666666)
		Sleep(1500)
		_Write_GUI_Log($aResult[$iRnd_Result][0] & @CRLF & @CRLF, 1, $aResult[$iRnd_Result][1], True)
		
		Sleep(1000)
	Next
	
	For $i = 5 To 1 Step -1
		_Write_GUI_Log("Завершение работы через... ", 0)
		_Write_GUI_Log($i, 1, 0x0000FF, True)
		
		Sleep(1000)
	Next
	
	Exit
EndFunc

Func _Write_GUI_Log($sData, $iAppend = True, $iColor = 0, $iBold = False, $iItalic = False, $iUnderline = False, $iFontSize = 8)
	Local $sCurrent_Data = _GUICtrlRichEdit_GetCtrlText($hRichText)
	
	Local $sAttributes = "+bo+it+un"
	If Not $iBold Then $sAttributes = StringReplace($sAttributes, "+bo", "-bo")
	If Not $iItalic Then $sAttributes = StringReplace($sAttributes, "+it", "-it")
	If Not $iUnderline Then $sAttributes = StringReplace($sAttributes, "+un", "-un")
	
	_GUICtrlRichEdit_GotoCharPos($hRichText, -1) ;Set the selection to -1 (to scroll to the end)
	
	_GUICtrlRichEdit_SetCharColor($hRichText, 0)
	_GUICtrlRichEdit_SetCharAttributes($hRichText, StringReplace($sAttributes, "+", "-"))
	_GUICtrlRichEdit_SetFont($hRichText, 8)
	
	If $iAppend Then
		_GUICtrlRichEdit_AppendText($hRichText, $sData)
	Else
		_GUICtrlRichEdit_SetText($hRichText, $sData)
	EndIf
	
	Local $iSelStart = StringLen($sCurrent_Data)
	Local $iSelLength = StringLen($sData)
	
	_GUICtrlRichEdit_SetSel($hRichText, $iSelStart, $iSelStart + $iSelLength + 1)
	
	_GUICtrlRichEdit_SetCharColor($hRichText, $iColor)
	_GUICtrlRichEdit_SetCharAttributes($hRichText, $sAttributes)
	_GUICtrlRichEdit_SetFont($hRichText, $iFontSize)
	
	_GUICtrlRichEdit_GotoCharPos($hRichText, -1) ;Set the selection to -1 (to scroll to the end)
EndFunc

Func _FileGetRandomName($sExt, $i_RandomLength=7)
	Local $s_TempName = ""
	
	While StringLen($s_TempName) < $i_RandomLength
		$s_TempName &= Chr(Random(97, 122, 1))
	WEnd
	
	Return $s_TempName & $sExt
EndFunc

Источник: http://www.autoitscript.com/forum/index.php?showtopic=89358
Автор(ы): GaryFrost, grham, [email protected], KIP, Chris Haslam (c.haslam), Yoan Roblet (Arcker), Paul Campbell (PaulIA)
 
Верх