StMaSi

Richedit Control Options

14 posts in this topic

#1 ·  Posted

Two questions...

When presenting a form containing a richedit control, is there any way to make the displayed text, within said richedit control, non-selectable?

In addition, is there any way to hide the vertical line cursor, within said richedit control?

Thanx.

Share this post


Link to post
Share on other sites



#2 ·  Posted

StMaSi,

WinSetState($hRichEdit, "", @SW_DISABLE) should do both for you.

M23 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

Well, that does, in fact, disable the control, but the background now turns from white to grey and the text is greyed out as well. Is there a way to have the control disabled in this manner, but to restore the background and text color to what they were prior to disabling the control?

Share this post


Link to post
Share on other sites

#4 ·  Posted

StMaSi,

How about a mask like this:

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

Global $hGUI, $hGUI_Mask

Example()

Func Example()
    Local $hRichEdit, $iMsg
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 350, -1, -1)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit, @CRLF & "This is more text")

    $cButton = GUICtrlCreateButton("Test", 10, 300, 80, 30)

    GUISetState(@SW_SHOW)

    $aGUI_Pos = WinGetPos($hGUI)
    $hGUI_Mask = GUICreate("Mask", 300, 220, 0, 0, BitOR($WS_POPUP, $WS_BORDER), 0, $hGUI)
    GUISetBkColor(0xCCCCFF) ; Just so you can see the GUI in the example
    WinMove($hGUI_Mask, "", $aGUI_Pos[0] + 10, $aGUI_Pos[1] + 35)
    GUISetState(@SW_SHOWNOACTIVATE, $hGUI_Mask)
    WinSetTrans($hGUI_Mask, "", 100)

    ; Look for the main GUI moving
    GUIRegisterMsg($WM_MOVE, "_WM_MOVE")

    While True
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
                ; GUIDelete()   ; is OK too
                Exit
            Case $iMsg = $cButton
                ConsoleWrite("Hit" & @CRLF)
        EndSelect

        If _WinAPI_GetFocus() = $hRichEdit Then
            _WinAPI_SetFocus($hGUI_Mask)
        EndIf

    WEnd

EndFunc   ;==>Example

Func _WM_MOVE($hWnd, $iMsg, $wParam, $lParam)
    ; If the main GUI moves
    If $hWnd = $hGUI Then
        ; Move the child to follow
        Local $aGUI_Pos = WinGetPos($hWnd)
        WinMove($hGUI_Mask, "", $aGUI_Pos[0] + 10, $aGUI_Pos[1] + 35)
    EndIf
EndFunc   ;==>_WM_MOVE

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

Unfortunately, that hides my entire form.

Share this post


Link to post
Share on other sites

#6 ·  Posted

StMaSi,

No it does not, it only masks the RichEdit control - if it does more than that then you have messed up the sizing code. Please post what you are using and I will take a look.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#7 ·  Posted

Okay. Here's my code...

#include <Date.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <GuiRichEdit.au3>
#include <MenuConstants.au3>
#include <Timers.au3>
#include <WindowsConstants.au3>

AutoItSetOption("TrayIconHide", 1)
AutoItSetOption("WinDetectHiddenText", 1)
AutoItSetOption("WinSearchChildren", 1)
AutoItSetOption("WinTitleMatchMode", -2)

Local $COUNTDOWN1 = IniRead(@ScriptDir & "\welcome.ini", "Parameters", "DelayTime", 10)
Local $TIMER1 = $COUNTDOWN1
Local $WINDOWS_ONTOP = 1

HotKeySet("!{F4}", "_HawkingHole")

GUISetIcon(@ScriptDir & "\welcome.ico", -1)
$RICHTEXTFILE1 = FileRead(@ScriptDir & "\welcome.rtf")
$FORM1 = GUICreate("Welcome", 600, 400, -1, -1, $WS_EX_TOPMOST, $WM_SYSCOMMAND + $WS_EX_WINDOWEDGE)
$PICTURE1 = GUICtrlCreatePic(@ScriptDir & "\welcome.bkg.jpg", 0, 0, 594, 371)
GUICtrlSetState(-1, $GUI_DISABLE)
$PICTURE2 = GUICtrlCreatePic(@ScriptDir & "\welcome.bnr.jpg", 2, 2, 157, 331)
GUICtrlSetState(-1, $GUI_DISABLE)
$PROGRESS1 = GUICtrlCreateProgress(230, 348, 170, 10)
$LABEL1 = GUICtrlCreateLabel("* Welcome", 10, 345, 190, 25)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$BUTTON1 = GUICtrlCreateButton("Upgrade", 433, 340, 75, 25)
$BUTTON2 = GUICtrlCreateButton("Defer", 513, 340, 75, 25)
$RICHEDITCONTROL1 = _GUICtrlRichEdit_Create($FORM1, $RICHTEXTFILE1, 175, 1, 415, 185, BitOR($ES_LEFT, $ES_MULTILINE, $ES_WANTRETURN, $ES_READONLY), 0)
_GUICtrlRichEdit_SetText($RICHEDITCONTROL1, $RICHTEXTFILE1)
_GUICtrlEdit_SetSel($RICHEDITCONTROL1, 600, 600)
WinSetState($RICHEDITCONTROL1, "", @SW_DISABLE)
GUIRegisterMsg($WM_SYSCOMMAND, "On_WM_SYSCOMMAND")
DisableButton($FORM1, $SC_CLOSE)
DisableButton($FORM1, $SC_MAXIMIZE)
DisableButton($FORM1, $SC_MINIMIZE)
DisableButton($FORM1, $SC_MOVE)
DisableButton($FORM1, $SC_RESTORE)
DisableButton($FORM1, $SC_SIZE)
_Timer_SetTimer($FORM1, 1000, '_Countdown')
GUISetState(@SW_SHOW)
OnTop()

While 1
    $IMSG = GUIGetMsg()
    Switch $IMSG
        Case $GUI_EVENT_CLOSE
            Exit
        Case $BUTTON1
            $UDATE = _NowCalcDate()
            $UTIME = _NowTime(5)
            $USTRING = @ComputerName & ", " & $UDATE & ", " & $UTIME
            $UFILENAME = "results.txt"
            $UFILEPATH = FileOpen(@ScriptDir & '\_log\' & $UFILENAME, 9)
            FileWrite($UFILEPATH, $USTRING & ", Upgraded" & @CRLF)
            FileClose($UFILEPATH)
            ;GUISetState(@SW_HIDE)
            Run(@ScriptDir & "\02.upgrade.exe")
            ;Exit
        Case $BUTTON2
            $DDATE = _NowCalcDate()
            $DTIME = _NowTime(5)
            $DSTRING = @ComputerName & ", " & $DDATE & ", " & $DTIME
            $DFILENAME = "results.txt"
            $DFILEPATH = FileOpen(@ScriptDir & '\_log\' & $DFILENAME, 9)
            FileWrite($DFILEPATH, $DSTRING & ", Deferred" & @CRLF)
            FileClose($DFILEPATH)
            ;GUISetState(@SW_HIDE)
            Run(@ScriptDir & "\03.defer.exe")
            ;Exit
    EndSwitch
WEnd

Func _HawkingHole()
    ; Disable ALT+F4 key combination
EndFunc   ;==>_HawkingHole

Func On_WM_SYSCOMMAND($FORM1, $MESSAGE1, $WPARAM, $LPARAM)
    If BitAND($WPARAM, 0xFFF0) = $SC_MOVE Then Return False
    Return $GUI_RUNDEFMSG
EndFunc   ;==>On_WM_SYSCOMMAND

Func DisableButton($FORM1, $IBUTTON)
    $HSYSMENU = _GUICtrlMenu_GetSystemMenu($FORM1, 0)
    _GUICtrlMenu_RemoveMenu($HSYSMENU, $IBUTTON, False)
    _GUICtrlMenu_DrawMenuBar($FORM1)
EndFunc   ;==>DisableButton

Func _Countdown($FORM1, $IMSG, $IIDTIMER, $DWTIME)
    $COUNTDOWN1 -= 1
    $PERCENT_VALUE = Floor(($COUNTDOWN1 / $TIMER1) * 100)
    $PERCENT_VALUE = 100 - $PERCENT_VALUE
    If $COUNTDOWN1 > 0 Then
        GUICtrlSetData($PROGRESS1, $PERCENT_VALUE)
    ElseIf $COUNTDOWN1 = 0 Then
        GUICtrlSetData($PROGRESS1, $PERCENT_VALUE)
        _Timer_KillTimer($FORM1, $IIDTIMER)
        ControlClick($FORM1, '', $BUTTON1)
    EndIf
EndFunc   ;==>_Countdown

Func _SecsToTime($ITICKS)
    Local $IHOURS, $IMINUTES, $ISECONDS
    _TicksToTime($ITICKS * 1000, $IHOURS, $IMINUTES, $ISECONDS)
    Return StringFormat("%2i:%02i", $IMINUTES, $ISECONDS)
EndFunc   ;==>_SecsToTime

Func OnTop()
    Global $DISPLAY = WinGetHandle($FORM1)
    WinSetOnTop($DISPLAY, "", $WINDOWS_ONTOP)
EndFunc   ;==>OnTop

When I add the...

WinSetState($RICHEDITCONTROL1, "", @SW_DISABLE)

The richedit control is greyed out. However, when I attempted to incorporate your mask code, the entire form would not display. Like you said, I must be attempting to incorporate your code improperly (it's not currently within this code). Can you assist with the incorporation?

Thanx.

Share this post


Link to post
Share on other sites

#8 ·  Posted

Here's something a little simpler. I used this when I was working on a console application and wanted to use a rich edit

Creating a label over the area where the richedit control is and setting the label's backcolor to $GUI_BKCOLOR_TRANSPARENT

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

Global $hGUI

Example()

Func Example()
    Local $hRichEdit, $iMsg
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 350, -1, -1)
    $lblMask = GUICtrlCreateLabel("", 10, 10, 300, 220)
    GUICtrlSetBkColor($lblMask, $GUI_BKCOLOR_TRANSPARENT)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit, @CRLF & "This is more text")
    ; Prevent the richedit from being entered using the 'Tab' key
    _WinAPI_SetWindowLong($hRichEdit, $GWL_STYLE, BitAND(_WinAPI_GetWindowLong($hRichEdit, $GWL_STYLE), BitNOT($WS_TABSTOP)))

    $cButton = GUICtrlCreateButton("Test", 10, 300, 80, 30)
    ; Set the button to focus so the richedit control doesn't have focus (having focus would let someone type in it)
    GUICtrlSetState($cButton, $GUI_FOCUS)

    GUISetState(@SW_SHOW)

    While True
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
                ; GUIDelete()   ; is OK too
                Exit
            Case $iMsg = $cButton
                ConsoleWrite("Hit" & @CRLF)
        EndSelect
    WEnd

EndFunc   ;==>Example

 

Share this post


Link to post
Share on other sites

#9 ·  Posted

InunoTaishou,

Great idea and much simpler than mine. I think I became fixated on using a child GUI because I had been working on one earlier on the day.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

When utilizing the following two bits of code from InunoTaishou, the richedit control remains active (not greyed out) and the cursor is not flashing because the focus is on the label:

...
_WinAPI_SetWindowLong($RICHEDITCONTROL1, $GWL_STYLE, BitAND(_WinAPI_GetWindowLong($RICHEDITCONTROL1, $GWL_STYLE), BitNOT($WS_TABSTOP)))
...
GUICtrlSetState($LABEL1, $GUI_FOCUS)
...

However, the richedit control is still selectable...a user can click into it, which exposes the cursor and/or double-click into it and highlight text within. Short of utilizing individual labels for the information that would be contained within one richedit control, is there no other way to "lock down" (for lack of a better term) the richedit control, but avoid disabling it (the graying out)?

Thanx again for all your help, peeps.

Share this post


Link to post
Share on other sites

#11 ·  Posted

StMaSi,

Quote

However, the richedit control is still selectable...a user can click into it, which exposes the cursor and/or double-click into it and highlight text within

Really? I have just been trying to do just that and I cannot get at the RichEdit at all. How did you manage it?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#12 ·  Posted

Perhaps my mouse-clicking is more powerful than yours?

 

B)

Share this post


Link to post
Share on other sites

#13 ·  Posted

Create the RichEdit in a child window and disable the child window:

Create the RichEdit in a child window and disable the child window:

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

Example()

Func Example()
  $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 350, -1, -1)

  $hChild = GUICreate( "", 300, 220, 10, 10, $WS_CHILD, -1, $hGui )
  GUISetState( @SW_DISABLE )
  GUISetState()

  $hRichEdit = _GUICtrlRichEdit_Create($hChild, "This is a test.", 0, 0, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
  _GUICtrlRichEdit_AppendText($hRichEdit, @CRLF & "This is more text")

  GUISwitch( $hGui )
  GUISetState()

  While GUIGetMsg() <> $GUI_EVENT_CLOSE
  WEnd
EndFunc

 

Share this post


Link to post
Share on other sites

#14 ·  Posted

I'm going to guess and say that the label you created over the richedit control is not actually over the richedit control. So you're just clicking on the richedit.

Do this and see where your label is actually at

GUICtrlSetBkColor($LABEL1, 0xFF0000)

 

Share this post


Link to post
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

  • Similar Content

    • robcull
      By robcull
      Hello all! I have had some issues reading text from different types of windows, occasionally, specifically with controlgettext. 
      **Before I begin, I know there are better ways to do what I attempt in the example below. That's not the point of this post. The point is my issues with controlgettext. 
      I am about to cite an example with an application you may be familiar with called SpeedFan (v4.52). My problem is not specific to speedfan, it is simply the most recent and easily reproducible example I can think of. 
      So, the goal of the script below is to get a string of text containing the current fan RPMs from the highlighted control in the screenshot below (see "speedfan_control_details.png").

      Now, here's a simple script for grabbing the window handle and reading the text from that control: 
      $wintitle = "SpeedFan 4.52" $controlID = "197934" ;will be reformatted as "[ID:######]" $hwnd = wingethandle($wintitle) if @error<>0 then msgbox(0, "WinGetHandle", "FAILURE. @error="&@error) Exit EndIf $text = ControlGetText($hwnd, "", "[ID:"&$controlID&"]") if @error=1 then msgbox(0, "ControlGetText", "FAILURE. @error="&@error) ;failure returns "" and @error=1 Exit EndIf msgbox (0, "ControlGetText", "SUCCESS. @error="&@error &@CRLF& "$text="&$text) ;success returns string and @error=0 You'll see that the ControlGetText operation runs without error, however it does not capture any text from the control. If you explore the other controls in this one window, you'll find mixed results across the board. Neither the temps nor voltages can be read, while the log field and some other elements can be read. Even when you read the text from the whole window, those elements are not included in the visible nor hidden texts. 
       
      I have run into this issue many times in the past- inconsistencies in the ability of autoit to interact with certain controls. What is it which makes this text different than any other readable texts? Is there an alternate method of reading the text in the window/control which could work? Any and all info to help me solve this mystery and satisfy my curiosity would be greatly appreciated. 
      Thanks  -Rob C
      PS: Running Autoit v3.3.14.2 on Win7 Ultimate x64
    • thoms
      By thoms
      Hello Forum,
      I'm trying to vertically center text in label controls, but no way. The search on the forum returns no result, or I don't search the right way
      When I insert a button and a label of same size close to each other, the text is centered on the button, but top aligned on the label, or edit. Which doesn't look really aesthetic
      Any idea is welcome
      Thanks in advance,
      Thoms
    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I am a totally blind young man
      for easier to read books and articles Among the blind
      i has programmed a tool
      This tool converts text to audio with the possibility to save it into a wav or mp3 file
      It is also compatible with all persons, whether blind or ordinary
      I have completed the work of this tool and want to take your opinion
      i Especially published here for anyone looking about how to convert text to speech, I will put this tool open source for you
      I want to know what your think about it
      and if it need any other additions?
      Note :
      This tool converts texts to audio using sapi 5 voices
      so i was also puted a hot keys to control the tool
      Now I put this project to you for public benefit and I am ready to answer any question.
      Apology :
      I am an Arab youth from Algeria
      I do not mastered English very well
      So I apologize to you if there are written mistakes
      With my greetings and best wishes
      My texts to audio converter.zip
    • FroVN
      By FroVN
      Hi, i want read all text in website doc.google, link : https://docs.google.com/document/d/1ePaOK3w4mOi0fmOF7WQmF5kYvAXQtztVI7018wei_xs/edit (This is all my account , don't remember :v) how i read all text in this web? Tks
    • StMaSi
      By StMaSi
      Is there any way to embed characters/codes/data/etc. within a text file so that when the script reads the text file to populate the edit box, said characters/codes/data/etc. can let the script know this word needs to be capitalized, that word needs to be underscored, etc.?
      For example, the text file would contain something along these lines...
      <bold>This is the title</bold> This is a <italic>sample</italic> text file. This is <underscore>only</underscore> a text file. Does that make sense?
      Thanx.