Jump to content

Search the Community

Showing results for tags 'rich edit'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • Forum FAQ
  • AutoIt

Calendars

  • Community Calendar

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 3 results

  1. This is an example script, showing how to avoid having Richedit control stealing focus from other controls. I have seen several person on the forum having the same issue as me. When using a RichEdit Control in a chat software, RichEdit steals focus from the Input everytime a user posts a message. I think I found a work around : find a way to append the text without making a text selection, because the selection moves the caret in the richedit control. Problems and solutions I found : 1 - "_GUICtrlRichEdit_AppendText" Steals focus because there is "_GuiCtrlRichEdit_SetSel" in the function ( "_GuiCtrlRichEdit_SetSel" is used to input the text at the end of the richedit control, and also used to scroll the page to the last line ). --- > AppendText Solution = I use "_GUICtrlEdit_AppendText" from "GuiEdit.au3". It appends the text at the end of the Richedit Control, without moving the caret to the richedit control. --- > Scrolling Solution = I used "_GUICtrlRichEdit_ScrollLines" to scroll one line down. Later I'll try to find how many lines really need to be scrolled ( if multiline text ). 2 - "_GUICtrlRichEdit_SetCharColor" Also needs a selection to apply the color. ( _GUICtrlRichEdit_SetFont Doesn't need a selection ) --- > Color solution = I edited the "_GUICtrlRichEdit_SetCharColor" by Jpm ( and named it "_GUICtrlRichEdit_SetCharColor_No_Selection" ) and commented the _GuiCtrlRichEdit_GetSel lines. So the color needs to be chosen before appending the text. Here is an example script showing the problem ( I tried to simulate a chat situation ) : ;INCLUDES #include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;OPT Opt("GUIOnEventMode", 1) ;VARIABLES GUI Global $GUI_SIZE_X = 600 Global $GUI_SIZE_Y = 600 Global $GUI_RICHEDIT_SIZE_X = $GUI_SIZE_X Global $GUI_RICHEDIT_SIZE_Y = $GUI_SIZE_Y / 3 ;GUI Global $GUI = GUICreate("Test", $GUI_SIZE_X, $GUI_SIZE_Y) ;RICHEDIT Global $GUI_RICHEDIT = _GUICtrlRichEdit_Create($GUI, "", 0, 0, $GUI_RICHEDIT_SIZE_X, $GUI_RICHEDIT_SIZE_Y * 2, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) ;INPUT Global $sINPUT_TEXT = "Try to Type some text here ! (Then press ENTER to send)" & @CRLF & @CRLF & _ "It's IMPOSSIBLE !" & @CRLF & @CRLF & _ "the _GUICtrlRichEdit_AppendText steals focus from the input all the time, making RichEdit almost unusable in a chat software (Even if you use !" & @CRLF & @CRLF & _ "Also, _GUICtrlRichEdit_SetCharColor needs to have a selection to apply the color on the incoming text. If no Selection, then the color is applied on the whole control" & @CRLF & @CRLF & _ "Even with 'GUICtrlSetState ( $GUI_INPUT, $GUI_FOCUS )' it doesn't help" Global $GUI_INPUT = GUICtrlCreateInput($sINPUT_TEXT, 0, $GUI_RICHEDIT_SIZE_Y * 2, $GUI_SIZE_X, $GUI_RICHEDIT_SIZE_Y, $ES_MULTILINE) GUISetState() GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") HotKeySet("{ENTER}", "_Send") ;LOOP While 1 ;HERE WE ADD RANDOM TEXT WITH RANDOM COLOR EVERY 'Random' ms (TRY TO SIMULATE A CHAT SITUATION) _Chat_Add_Line($GUI_RICHEDIT, _ "Chat Line " & Random(0, 999999), _ "0x" & StringFormat("%02d", Random(0, 99, 1)) & StringFormat("%02d", Random(0, 99, 1)) & StringFormat("%02d", Random(0, 99, 1)), _ 8) Sleep(Random(50, 2000, 1)) WEnd Func _Send() _Chat_Add_Line($GUI_RICHEDIT, "You Said : " & GUICtrlRead($GUI_INPUT), 0xFF0000, 12) GUICtrlSetState($GUI_INPUT, $GUI_FOCUS) GUICtrlSetData($GUI_INPUT, "") Return 1 EndFunc ;==>_Send Func _Chat_Add_Line($hWnd, $sMessage, $sColor, $iFont) StringReplace(_GUICtrlRichEdit_GetText($hWnd, True), @CRLF, "") Local $iLines = @extended Local $iStart = _GUICtrlRichEdit_GetTextLength($hWnd, True, True) - $iLines _GUICtrlRichEdit_PauseRedraw($hWnd) _GUICtrlRichEdit_AppendText($hWnd, $sMessage & @CRLF) _GUICtrlRichEdit_SetSel($hWnd, $iStart, -1, False) _GUICtrlRichEdit_SetCharColor($hWnd, $sColor) _GUICtrlRichEdit_SetFont($hWnd, $iFont) _GUICtrlRichEdit_Deselect($hWnd) _GUICtrlRichEdit_ResumeRedraw($hWnd) ;---> ( TRY TO UN-COMMENT THE NEXT LINE ) ; HERE WE EVEN TRY TO GIVE BACK THE FOCUS TO THE INPUT, BUT IT DOESN'T HELP ;~ GUICtrlSetState ( $GUI_INPUT, $GUI_FOCUS ) Return 1 EndFunc ;==>_Chat_Add_Line Func _Exit() _GUICtrlRichEdit_Destroy($GUI_RICHEDIT) Exit EndFunc ;==>_ExitAnd Here is my modified version : ;INCLUDES #include <GuiEdit.au3> #include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;OPT Opt("GUIOnEventMode", 1) ;VARIABLES GUI Global $GUI_SIZE_X = 600 Global $GUI_SIZE_Y = 600 Global $GUI_RICHEDIT_SIZE_X = $GUI_SIZE_X Global $GUI_RICHEDIT_SIZE_Y = $GUI_SIZE_Y / 3 ;GUI Global $GUI = GUICreate("Test", $GUI_SIZE_X, $GUI_SIZE_Y) ;RICHEDIT Global $GUI_RICHEDIT = _GUICtrlRichEdit_Create($GUI, "", 0, 0, $GUI_RICHEDIT_SIZE_X, $GUI_RICHEDIT_SIZE_Y * 2, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) ;INPUT Global $GUI_INPUT = GUICtrlCreateInput("Type some text here, then press Enter", 0, $GUI_RICHEDIT_SIZE_Y * 2, $GUI_SIZE_X, $GUI_RICHEDIT_SIZE_Y, $ES_MULTILINE) GUISetState() GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") HotKeySet("{ENTER}", "_Send") ;LOOP While 1 ;HERE WE ADD RANDOM TEXT WITH RANDOM COLOR EVERY 'Random' ms (TRY TO SIMULATE A CHAT SITUATION) _Chat_Add_Line($GUI_RICHEDIT, _ "Chat Line " & Random(0, 999999), _ "0x" & StringFormat("%02d", Random(0, 99, 1)) & StringFormat("%02d", Random(0, 99, 1)) & StringFormat("%02d", Random(0, 99, 1)), _ 8) Sleep(Random(50, 1000, 1)) WEnd Func _Send() _Chat_Add_Line($GUI_RICHEDIT, "You Said : " & GUICtrlRead($GUI_INPUT), 0xFF0000, 12) GUICtrlSetState($GUI_INPUT, $GUI_FOCUS) GUICtrlSetData($GUI_INPUT, "") Return 1 EndFunc ;==>_Send Func _Chat_Add_Line($hWnd, $sMessage, $sColor, $iFont) _GUICtrlRichEdit_PauseRedraw($hWnd) ;SET THE COLOR FOR THE INCOMING TEXT USING THE MODIFIED _GUICtrlRichEdit_SetCharColor THAT DOESN'T STEAL INPUT FOCUS _GUICtrlRichEdit_SetCharColor_No_Selection($hWnd, $sColor) _GUICtrlRichEdit_SetFont($hWnd, $iFont) ;THE "_GUICtrlRichEdit_AppendText" STEALS FOCUS FROM THE INPUT (Because there is a _GuiCtrlRichEdit_SetSel in the function). ;SO I APPEND THE TEXT USING "_GUICtrlEdit_AppendText" FROM "GuiEdit.au3". _GUICtrlEdit_AppendText($hWnd, $sMessage & @CRLF) _GUICtrlRichEdit_ScrollLines($hWnd, 1) _GUICtrlRichEdit_ResumeRedraw($hWnd) Return 1 EndFunc ;==>_Chat_Add_Line ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GUICtrlRichEdit_SetCharColor ; Description....: Sets the color of incoming text inserted at the insertion point ; Syntax ........: _GUICtrlRichEdit_SetCharColor($hWnd[, $iColor]) ; Parameters.....: $hWnd - Handle to the control ; $iColor - one of the following: (Optional) ; |a number - a COLORREF value ; |Default keyword - the system color (default) ; Return values..: Success - True ; Failure - False and sets @error: ; |101 - $hWnd is not a handle ; |1022 - $iColor is invalid ; Authors........: Chris Haslam (c.haslam) ; Modified ......: Jpm, Jmon ; Remarks .......: This Function has been modified to avoid stealing focus from another control ; Related .......: _GUICtrlRichEdit_GetCharColor, _GUICtrlRichEdit_SetCharColor ; Link ..........: @@MsdnLink@@ EM_SETCHARFORMAT ; Example .......: Yes ; =============================================================================================================================== Func _GUICtrlRichEdit_SetCharColor_No_Selection($hWnd, $iColor = Default) If Not IsHWnd($hWnd) Then Return SetError(101, 0, False) Local $tCharFormat = DllStructCreate($tagCHARFORMAT) DllStructSetData($tCharFormat, 1, DllStructGetSize($tCharFormat)) If IsKeyword($iColor) Then DllStructSetData($tCharFormat, 3, $CFE_AUTOCOLOR) $iColor = 0 Else If BitAND($iColor, 0xff000000) Then Return SetError(1022, 0, False) EndIf DllStructSetData($tCharFormat, 2, $CFM_COLOR) DllStructSetData($tCharFormat, 6, $iColor) ;I COMMENTED THOSE NEXT LINES, OTHERWISE THE COLOR WOULD BE APPLIED TO THE WHOLE CONTROL ;~ Local $ai = _GuiCtrlRichEdit_GetSel($hWnd) ;~ If $ai[0] = $ai[1] Then ;~ Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $SCF_ALL, DllStructGetPtr($tCharFormat)) <> 0 ;~ Else Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $SCF_SELECTION, DllStructGetPtr($tCharFormat)) <> 0 ;~ EndIf EndFunc ;==>_GUICtrlRichEdit_SetCharColor_No_Selection Func _Exit() _GUICtrlRichEdit_Destroy($GUI_RICHEDIT) Exit EndFunc ;==>_Exit In Both Example, you can try to type some text in the Input, at the bottom. Use "Enter" to send the text in the Richedit control. Well I hope that solves the problems that others had before. [EDIT1] I ran "tidy" on the scripts for better formatting.
  2. Trying to enter colored text into a rich edit is a pain in the ass and complicated, and after searching for a few hours I always end up in the help file staring at this text: _GUICtrlRichEdit_SetText ( $hWnd, $sText ) Parameters $hWnd Handle to the control $sText Plain or RTF text to put into the control What is this RTF text it speaks of? What I am THINKING of is how if you copy bold text from a page, and paste it into wordpad, it is bold. But if you paste that text into notepad and then copy it and paste it into wordpad it will have no formatting. There is some kind of extra formatting that can be on the text in clipboard In the same way if you _GUICtrlRichEdit_SetText with plain text it sends it in the richedit as plain text. How do I send pre-formatted "RTF text" to a richedit using _GUICtrlRichEdit_SetText?
  3. I found this example by zedna, it worked perfectly (entering text into the control with specified color), that is until you add any form of line break (@CR, @LF or @CRLF). If the line breaks aren't there, the text entered is colored correctly, but when they are, the colors gets off and I can't figure out why, anyone know what's the matter? #include <GUIConstants.au3> #include <GuiRichEdit.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 448, 269, 192, 124) $Edit1 = _GUICtrlRichEdit_Create($Form1,"", 16, 24, 417, 225) GUISetState(@SW_SHOW) _GUICtrlRichEdit_AppendTextColor($Edit1, "Hello "& @CR, "0x00FF00") _GUICtrlRichEdit_AppendTextColor($Edit1, "Autoit "& @CR, "0xFF0000") _GUICtrlRichEdit_AppendTextColor($Edit1, "World", "0x000000") ;~ _GUICtrlRichEdit_AppendText($Edit1, "World") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($Edit1) Exit EndSwitch WEnd Func _GUICtrlRichEdit_AppendTextColor($hWnd, $sText, $iColor) Local $iLength = Int(_GUICtrlRichEdit_GetTextLength($hWnd)/2) ; RichEdit stores text as 2 Byte Unicode chars _GUICtrlRichEdit_AppendText($hWnd, $sText) _GUICtrlRichEdit_SetSel($hWnd, $iLength, $iLength + StringLen($sText)*2) ; position in 2 Byte "Unicode" _GUICtrlRichEdit_SetCharColor($hWnd, $iColor) _GuiCtrlRichEdit_Deselect($hWnd) EndFunc
×
×
  • Create New...