Jump to content

Live character's counter when is typing with _GUICtrlRichtEdit


 Share

Go to solution Solved by mikell,

Recommended Posts

Hi Forum!

In this example, it work with _GUICtrlRichtEdit, how to implemente a character's total counter when is typing?

I try with GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') without success.

Thank you.

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

Example()

Func Example()
    Local $hGui, $hRichEdit, $iMsg
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 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")
    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
        EndSelect
    WEnd
EndFunc   ;==>Example

Visit my repository

Link to comment
Share on other sites

  • Moderators

Detefon,

How about this: :)

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

Global $hRichEdit, $cLabel

Example()

Func Example()
    Local $hGui, $iMsg
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    ConsoleWrite($hRichEdit & @CRLF)
    $cLabel = GUICtrlCreateLabel("", 10, 250, 200, 20)
    GUICtrlSetData($cLabel, _GUICtrlRichEdit_GetTextLength($hRichEdit, True, True))
    GUISetState(@SW_SHOW)

    ; Tell RichEdit to send EN_CHANGE messages <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    _SendMessage($hRichEdit, $EM_SETEVENTMASK, 0, $ENM_CHANGE)

    GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

    $nBegin = TimerInit()

    While True
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
                ; GUIDelete()   ; is OK too
                Exit
        EndSelect

        If TimerDiff($nBegin) > 1000 Then
            _GUICtrlRichEdit_AppendText($hRichEdit, @CRLF & "This is more text")
            $nBegin = TimerInit()
        EndIf

    WEnd
EndFunc   ;==>Example

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $iCode = BitShift($wParam, 16) ;HiWord
    If $lParam = $hRichEdit And $iCode = $EN_CHANGE Then
        GUICtrlSetData($cLabel, _GUICtrlRichEdit_GetTextLength($hRichEdit, True, True))
    EndIf
EndFunc   ;==>_WM_COMMAND
Please ask if you have any questions. :)

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

mikell,

 

No need of _SendMessage

Have you tried running the code without that line? :huh:

You might want to read the Remarks on this MSDN page. ;)

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

  • Solution

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

Global $hRichEdit, $cLabel

Example()

Func Example()
    Local $hGui, $iMsg
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    ConsoleWrite($hRichEdit & @CRLF)
    $cLabel = GUICtrlCreateLabel("", 10, 250, 200, 20)
    GUICtrlSetData($cLabel, _GUICtrlRichEdit_GetTextLength($hRichEdit, True, True))
    GUISetState(@SW_SHOW)

    ; Tell RichEdit to send EN_CHANGE messages <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  ;  _SendMessage($hRichEdit, $EM_SETEVENTMASK, 0, $ENM_CHANGE)

    GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

    $nBegin = TimerInit()

    While True
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
                ; GUIDelete()   ; is OK too
                Exit
        EndSelect

        If TimerDiff($nBegin) > 1000 Then
            _GUICtrlRichEdit_AppendText($hRichEdit, @CRLF & "This is more text")
            $nBegin = TimerInit()
        EndIf

    WEnd
EndFunc   ;==>Example

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $iCode = BitShift($wParam, 16) ;HiWord
    If $lParam = $hRichEdit And $iCode = $EN_UPDATE Then
        GUICtrlSetData($cLabel, _GUICtrlRichEdit_GetTextLength($hRichEdit, True, True))
    EndIf
EndFunc   ;==>_WM_COMMAND

:)

Link to comment
Share on other sites

  • Moderators

mikell,

So there are 2 ways of doing it. :P

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

@FireFox, thank you!

@Melba23, thank you again!  :bye:

@mikell, thank you too!

I am so sorry, I want mark the two scripts with solved (@Melba and @mikell) but I have only one option.

@Melba23, I have thounsands of doubts! Is the better one question by day! ^^

Edited by Detefon

Visit my repository

Link to comment
Share on other sites

  • Moderators

Detefon,

 

It is important or irrelevant?

_WM_COMMAND and WM_COMMAND are the same commands/functions?

Completely irrelevant - you could name the handler function "Fred" if you so desired. What is important is the message you are registering ($WM_COMMAND) as otherwise you will not intercept the Windows message stream and the code will not work. ;)

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