Jump to content

Richedit Control Options


StMaSi
 Share

Recommended Posts

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.

Link to comment
Share on other sites

  • Moderators

StMaSi,

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

M23 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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

 

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

×
×
  • Create New...