Jump to content

RichText Control Read Only


Recommended Posts

Hey

Ive got the following problem:

I downloaded some Rich Controls for AutoIt from this forum,

but no one of them got the function i need...

I want to set some lines / or a selected text of my RichTextBox to ReadOnly,

but the user should be aviable to type a command into it.

An Code Example_

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <RichText.au3>

$main = GUICreate("Test Window", 251, 137, 890, 631, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE,$WS_EX_TOPMOST))
$con = RichText_Create($main, 0, 0, 251, 138)
winsettrans($main, "", 215)
GUISetState(@SW_SHOW)
RichText_HideSelection($con)
RichText_SetFont($con, "Consolas")
RichText_SetBold($con, true)
RichText_BkColor($con, 0x000000)

info() ;This call's a Text from a Function + this Text should be ReadOnly
RichText_AppendText($con, "some random text"& @crlf) ;This Text also should be ReadOnly
uinp() ;Same as above + this Text should be ReadOnly

Func info()
    RichText_SetBold($con, true)
    RichText_SetFont($con, "Consolas")
    RichText_SetColor($con, 0x0AFEFE)
    RichText_AppendText($con, "[INFO]: ")
    RichText_SetColor($con, 0xFFFFFF)
EndFunc

Func uinp()
    RichText_SetBold($con, true)
    RichText_SetFont($con, "Consolas")
    RichText_SetColor($con, 0x4BC04B)
    RichText_AppendText($con, "[USER]: ")
    RichText_SetColor($con, 0xFFFFFF)
EndFunc

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

After the Text of the Function uinp() appends to the RTB, the user should insert a command like /help, no ReadOnly =)

I hope ive Explained this understandable, and waiting hopefull for Reply's.

Ps: Sorry for my Bad English, im German =)

Greez xPLiciT

Link to comment
Share on other sites

here is an approach that will work...

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#Include <GuiEdit.au3>
#include <date.au3>
#include <Array.au3>
#include <Color.au3>

opt("GUIOnEventMode", 1)

Demo()




Exit
;------------------------------------------------------------------------------------------------------
;-                                      C O N S O L E   D E M O
;------------------------------------------------------------------------------------------------------
Func Demo()
    Global $ConsoleID=0
    Global $about = StringSplit("*** Autoit Means ***,,Appreciation, Application, Amazing, Automation, Admirable, Awesome, Astonishing, Advanced, Academic," & _
    "Utility, Understandable, Unselfish, Unmatched, Universal, Unparalleled, Useful, Unequaled, Unique, Unsurpassed, Unlimited," & _
    "Thorough, Thoughtful, Timeless, Terrific, Tremendous, Transforming, Transcending, Topless," & _
    "Overriding, Outstanding, Overwhelming, Outdone, Overpowering, Originality, Overshadow, Overruling, Outshining, Overtaking, Outperform," & _
    "Inventiveness, Interactive, Intellectual, Incredible, Interface, Innovation, Imagination, Initiative, Impressive, Inspiring, Incomparable," & _ 
    ".............................., A U T O I T,....................., , , , Thank you Jon!!!!,,Have a Wonderful Day!!!", ",")
    $about[0] = ""
    $ConsoleID = ConsoleWinCreate(-1, -1, 638, 326, "Age Demo...", "Starting demo..." & @CRLF, True)
    $answer1 = ConsoleWinInput($ConsoleID, "Please input your Year of Birth (example.. 1985) ?", 15, 1 )
    $Vanswer1 =ConsoleWinVerify($ConsoleID, $answer1, "Please input your Year of Birth (example.. 1985) ?", True, 4, 4)
    ConsoleWinWrite($ConsoleID, "OK.. " & @CRLF, 30, 1)
    $answer2 = ConsoleWinInput($ConsoleID, "Please input your Month of Birth (example.. 3 = March) ?", 45, 1 )
    $Vanswer2 =ConsoleWinVerify($ConsoleID, $answer2, "Please input your Month of Birth (example.. 3 = March) ?", True, 1, 2)
    ConsoleWinWrite($ConsoleID, "Good.. " & @CRLF, 60, 1)
    $answer3 = ConsoleWinInput($ConsoleID, "Please input your Day of Birth (ex.. 22) ?" , 75, 1 )
    $Vanswer3 =ConsoleWinVerify($ConsoleID, $answer3, "Please input your Month of Birth (example.. 22) ?", True, 1, 2)
    ConsoleWinWrite($ConsoleID, "Great!.. Please wait while i calculate your age..." & @CRLF, 90, 1)
    Sleep(1000)
    ConsoleWinWrite($ConsoleID, " You have been alive " & _DateDiff( 'd',$Vanswer1 &"/"& $Vanswer2 &"/"& $Vanswer3,_NowCalc()) & " days!" & @CRLF, 100, 1)
    Sleep(5000)
    ConsoleWinWrite($ConsoleID, "Example: Clearing console in five seconds...Thanks Valuater 8) ")
    Sleep(5000)
    ConsoleWinClear($ConsoleID)
    ConsoleWinWrite($ConsoleID, "Demo finished! Exiting in five seconds...")
    Sleep(5000)
    Exit
    ;_txt_eff__about_messages ($ConsoleID, $ConsoleID[1], $about, 5, 10, 1, "modern") ; "raining", "right_to_left", "left_to_right", "right_to_right", "left_to_left", "enlarge_left", "enlarge_right", "modern"


EndFunc

;------------------------------------------------------------------------------------------------------
;-                                      C O N S O L E   L I B R A R Y 
;------------------------------------------------------------------------------------------------------

;===============================================================================
; Description:      Create a Window console to display status text information with history
; Parameter(s):     $x                - x position of the window
;                    $y                - y position of the window
;                    $width            - Optional - Window width
;                    $height            - Optional - Window height
;                    $Title            - Optional - Console Window title
;                    $text            - Optional - Initial text to display.
;                    $CreateProgress    - Optional - Create Progress (True/False)
;                    $BgColor        - Optional - background color
;                    $FgColor        - Optional - Foreground color
;                    $Transparency    - Optional - Transparency (0=Invisible, 255=Visible)
; Requirement(s):   None
; Return Value(s):  The Console ID
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Note(s):            None
;===============================================================================
Func ConsoleWinCreate($x, $y, $width=638, $height=126, $Title="Console", $Text="", $CreateProgress=False, $BgColor=0xFFFFFF, $FgColor=0xFF0000, $Transparency=255)
    Dim $Console[3]
    $Console[0] = GuiCreate($Title, $width, $height, $x, $y, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), $WS_EX_TOOLWINDOW)
    GUISetOnEvent($GUI_EVENT_CLOSE, "ConsoleWinExitEvent")
    If $CreateProgress Then $height -= 20
    $Console[1] = GuiCtrlCreateEdit($Text & @CRLF, 0, 0, $width-1, $height-1, BitOR($ES_MULTILINE, $ES_READONLY, $ES_AUTOVSCROLL,$WS_HSCROLL,$WS_VSCROLL))
    GUICtrlSetBkColor($Console[1],    $BgColor)
    GUICtrlSetColor($Console[1],    $FgColor)
    GUICtrlSetResizing($Console[1],    $GUI_DOCKBORDERS)
    GUICtrlSetFont($Console[1], 12, 400, 0, "Courrier New")
    $Console[2] =0
    If $CreateProgress Then $Console[2] = GUICtrlCreateProgress(0, $height+5, $width-1, 12)
    WinSetTrans($Console[0], "", $Transparency)
    GuiSetState()
    Return $Console
EndFunc

Func ConsoleWinExitEvent()
    GUIDelete(@GUI_WinHandle)
    Exit
EndFunc

;===============================================================================
; Description:      Write a message to the console
; Parameter(s):     $ConsoleID        - Console ID returned by ConsoleWinCreate
;                    $text            - Text to display.
;                    $Progress        - Optional - Progress value (0-100)
;                    $NoCRLF            - Optional - Don't add CRLF and the end of text
;                    $Replace        - Optional - Replace last line
; Requirement(s):   ConsoleWinCreate called first
; Return Value(s):  None
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Note(s):            None
;===============================================================================
Func ConsoleWinWrite($ConsoleID, $Text, $Progress=-1, $Speak=False, $NoCRLF=False, $Replace=False)
    If $Replace Then
        $string = GUICtrlRead($ConsoleID[1])
        $pos = StringInStr($string, @CRLF, 0, -1)
        If $pos > 0 Then $pos += 1
        $end = StringLen($string)
        _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $end)
    Else
        $pos = StringLen(GUICtrlRead($ConsoleID[1]))
        _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $pos)
    EndIf
    If $NoCRLF = False Then $Text = $Text & @CRLF
    GUICtrlSetData ($ConsoleID[1], $Text, 1)
    If $Speak Then ConsoleSpeak($Text)
    If $ConsoleID[2] >0 And $Progress>=0 Then GUICtrlSetData($ConsoleID[2], $Progress)
EndFunc

;===============================================================================
; Description:      Ask for the user to input something
; Parameter(s):     $ConsoleID        - Console ID returned by ConsoleWinCreate
;                    $text            - Text to display, the question.
;                    $Progress        - Optional - Progress value (0-100)
; Requirement(s):   ConsoleWinCreate called first
; Return Value(s):  What user have typed.
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Note(s):            $text could be an empty string
;===============================================================================
Func ConsoleWinInput($ConsoleID, $Text, $Progress=-1, $Speak = 0)
    WinSetOnTop($ConsoleID[0], "", 1)
    WinActivate($ConsoleID[0])
    $string = GUICtrlRead($ConsoleID[1])
    $pos = StringLen($string)
    _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $pos)
    GUICtrlSetData ($ConsoleID[1], $Text, 1)
    GUICtrlSetStyle($ConsoleID[1], BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_HSCROLL, $WS_VSCROLL, $ES_WANTRETURN))
    If $Speak Then ConsoleSpeak($Text)
    If $Text <> "" Then
       ; Wait for the user to input something
        While 1
            Sleep(100)
            $String=GUICtrlRead($ConsoleID[1])
            If StringRight($string, 2) = @CRLF Then ExitLoop
           ; Ensure that everything is typed at the end of edit control
            $pos = StringLen($String)
            _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $pos)
        WEnd
        $pos = StringInStr($string, $Text, 0, -1)
        If $pos >0 Then $pos += StringLen($Text)
    Else
        $str = $string
       ; Wait for the user to input something
        While 1
            Sleep(100)
            $String=GUICtrlRead($ConsoleID[1])
            If StringRight($string, 2) = @CRLF And $string <> $str Then ExitLoop
           ; Ensure that everything is typed at the end of edit control
            $pos = StringLen($String)
            _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $pos)
        WEnd
        $pos = StringInStr(StringLeft($string, StringLen($string)-2), @CRLF, 0, -1)
        If $pos > 0 Then $pos += 1
    EndIf
    $string = StringMid($string, $pos)
    $string = StringLeft($string, StringLen($string)-2)
    GUICtrlSetStyle($ConsoleID[1], BitOR($ES_MULTILINE, $ES_READONLY, $ES_AUTOVSCROLL,$WS_HSCROLL,$WS_VSCROLL))
    If $ConsoleID[2] >0 And $Progress>=0 Then GUICtrlSetData($ConsoleID[2], $Progress)
    Return $string
    WinSetOnTop($ConsoleID[0], "", 0)
EndFunc

;===============================================================================
; Description:      Clear the console
; Parameter(s):     $ConsoleID    - The console ID
; Requirement(s):   None
; Return Value(s):  None
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Note(s):            None
;===============================================================================
Func ConsoleWinClear($ConsoleID)
    GUICtrlSetData ($ConsoleID[1], "")
    If $ConsoleID[2] >0 Then GUICtrlSetData($ConsoleID[2], 0)
EndFunc

;===============================================================================
; Description:      Save the content of the console to a file
; Parameter(s):     $ConsoleID    - The console ID
;                    $FileName    - The filename used to save
; Requirement(s):   None
; Return Value(s):  Write status, same as FileWrite
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Note(s):            None
;===============================================================================
Func ConsoleWinSave($ConsoleID, $FileName)
    $string = GUICtrlRead($ConsoleID[1])
    Return FileWrite($FileName, $string)
EndFunc

;===============================================================================
; Description:      Ask for the user to verify input something
; Parameter(s):     $ConsoleID      - Console ID returned by ConsoleWinCreate
;                   $VAns         - info to verify
;               $Text           - Text to display, the question.
;                   $VNum         - Optional - to verify an Intreger
;           $VMin         - Optional - Minimum length of string
;               $VMax      - Otional - Maximum length of string
; Requirement(s):   ConsoleWinCreate available and ConsoleWinInput called first
; Return Value(s):  What user has typed.
; Author(s):        Jerome DERN  (jdern "at" free "dot" fr)
; Co - Author      Valuater
; Note(s):          $Text may not be an empty string
;===============================================================================
Func ConsoleWinVerify($ConsoleID, $VAns, $Text, $VNum = False, $VMin = 1, $VMax = 1000)
    While 1
        ConsoleWinWrite($ConsoleID, "You have answered: " & $VAns)
        $VLen = StringLen($VAns)
        If $VNum And Int($VAns) > 0 And $VLen >= $VMin And $VLen <= $VMax Then
            If ConsoleWinInput($ConsoleID, 'Is this Correct? "Y" or "N" ') = "y" Then Return $VAns
        ElseIf Not $VNum And $VLen >= $VMin And $VLen <= $VMax Then
            If ConsoleWinInput($ConsoleID, 'Is this Correct? "Y" or "N" ') = "y" Then Return $VAns
        EndIf
        $VAns = ConsoleWinInput($ConsoleID, $Text)
        Sleep(10)
    WEnd
EndFunc

Func ConsoleSpeak($S_text)
;~     Local $oi_speech = ObjCreate("SAPI.SpVoice")
;~     $oi_speech.Speak ($S_text)
;~     $oi_speech = ""
EndFunc 



Func _txt_eff__about_messages($winhandle, $control_id, $texts, $delay = 50, $showtime = 2000, $pause = 750, $type = "right_to_left")
   
        Local $static = _IsStatic($winhandle, $control_id)
       
        If $static = 1 Then GUISetState(@SW_LOCK, $winhandle)
        ControlSetText($winhandle, "", $control_id, "")
        If $static = 1 Then GUISetState(@SW_UNLOCK, $winhandle)
        If ($type = "right_to_left") or ($type = "left_to_right") or ($type = "left_to_left") or ($type = "right_to_right") Then
            $text_min_width = 14
            For $i = 0 To UBound($texts) - 1
                If StringLen($texts[$i]) > $text_min_width Then $text_min_width = StringLen($texts[$i])
            Next
            $text_min_width = $text_min_width + 5
           
        ElseIf $type = "modern" Then
           
            ; ------- parameters -------
            Local $_l_height = 20 ; height of a single line (label)
            Local $_no_color = 0xECE9D8
            Local $_black = 0x000000
            Local $_messages = 5
            Dim $_labels[$_messages]
           
            ; enlarge Arrray
            For $k = 1 To $_messages
                _ArrayInsert($texts, 0, "")
                _ArrayInsert($texts, UBound($texts), "")
            Next
           
            $_txt_eff_about_gui = GUICreate("About", 250, $_l_height + 20 + $_l_height * $_messages + 60) ; the about win's title, width and height here
            $_txt_eff_gui_ok_button = GUICtrlCreateButton("&Ok", 10, $_l_height + 20 + $_l_height * $_messages + 25, 230, 25, $BS_DEFPUSHBUTTON )
               
           
            For $k = 1 To $_messages
                $_style = $SS_CENTER ; styles are located here!
                $_labels[$k - 1] = GUICtrlCreateLabel("[Error]", 10, 50 + 25 * $k, 210, $_l_height, $_style)
            Next
           
            GUISetState(@SW_SHOW)
                       
           
            For $k = 0 To UBound($texts) - $_messages
               
                GUICtrlSetColor($_labels[$_messages - 1], 0xECE9D8)
                For $p = 0 To $_messages - 1
                    GUICtrlSetPos($_labels[$p], 19, $_l_height + 20 + $_l_height * $p, 210, $_l_height)
                    GUICtrlSetData($_labels[$p], $texts[$k + $p])
                Next
               
                For $c = 0 To - $_l_height Step - 1   ; control's height is here again
                    Sleep($delay)
                   
                    GUISetState(@SW_LOCK)
                    ; move
                    For $z = 0 To $_messages - 1
                        GUICtrlSetPos($_labels[$z], 19, $_l_height + 20 + $_l_height * $z + $c, 210, $_l_height)
                    Next
                   
                    ; fade
                    $red_diff = _ColorGetRed($_black) - _ColorGetRed($_no_color)
                    $green_diff = _ColorGetGreen($_black) - _ColorGetGreen($_no_color)
                    $blue_diff = _ColorGetBlue($_black) - _ColorGetBlue($_no_color)
                    $red_res = Hex(_ColorGetRed($_black) + Round($red_diff / $_l_height * ($c + $_l_height + 1)), 2)
                    $green_res = Hex(_ColorGetGreen($_black) + Round($green_diff / $_l_height * ($c + $_l_height + 1)), 2)
                    $blue_res = Hex(_ColorGetBlue($_black) + Round($blue_diff / $_l_height * ($c + $_l_height + 1)), 2)
                    GUICtrlSetColor($_labels[0], "0x" & $red_res & $green_res & $blue_res)
                   
                    $red_diff = _ColorGetRed($_no_color) - _ColorGetRed($_black)
                    $green_diff = _ColorGetGreen($_no_color) - _ColorGetGreen($_black)
                    $blue_diff = _ColorGetBlue($_no_color) - _ColorGetBlue($_black)
                    $red_res = Hex(_ColorGetRed($_black) + Round($red_diff / $_l_height * ($c + $_l_height + 1)), 2)
                    $green_res = Hex(_ColorGetGreen($_black) + Round($green_diff / $_l_height * ($c + $_l_height + 1)), 2)
                    $blue_res = Hex(_ColorGetBlue($_black) + Round($blue_diff / $_l_height * ($c + $_l_height + 1)), 2)
                    GUICtrlSetColor($_labels[$_messages - 1], "0x" & $red_res & $green_res & $blue_res)
                   
                    GUISetState(@SW_UNLOCK)
                   
                    ; check if close event is there
                    $_about_msg = GUIGetMsg()
                    If $_about_msg = $GUI_EVENT_CLOSE Or $_about_msg = $_txt_eff_gui_ok_button Then ExitLoop 2
                Next
            Next
            GUIDelete($_txt_eff_about_gui)
        EndIf
EndFunc
Func _IsStatic($winhandle, $control_id)
    Local $ret = DllCall("user32.dll", "int", "GetClassName", "hwnd", ControlGetHandle($winhandle, "", $control_id), "str", "", "int", 128)
    If StringInStr($ret[2], "Static") <> 0 Then Return 1
    Return 0
EndFunc   ;==>_IsStatic[b][/b]

8)

NEWHeader1.png

Link to comment
Share on other sites

There is a charformat, CFM_PROTECTED :D i'll try to create an example :D

//Edit: This is really difficult. I don't know if i will be able to proivde a working example right now.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Hello Guys,

Thanks for the fast reply's.

@ Valuater : Thanks for the very nice Console Demo ! :-)

@ProgAndy : Thanks for reply, i hope u find a way how to solve this problem,

but anyway's, thanks in advance !

Greez xPLiciT

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...