Jump to content

[Solved] How to get a "RichEdit Full" alert?


qwert
 Share

Recommended Posts

Below is a small script that demonstrates an aspect of rich edit controls that I've never been able to figure out.

The control is set to hold a maximum of 1000 characters. If you copy one of the Lorum paragraphs and paste it at the bottom of the control, only part of it will fit ... which confirms that the 1000 character limit is in force.

With the control "full", if you try to scroll or page downward, you get an audible alert (a "ding" on my PC). But if you try to type additional characters, there is no such alert. Yet, no more characters are accepted.

What does it take to get an audible alert—or a popup message—when no more characters can be entered?

Thanks in advance for any help.

 

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

$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " & _
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in " & _
"reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, " & _
"sunt in culpa qui officia deserunt mollit anim id est laborum."

$hGUI = GUICreate("Scroll Test Panel", 400, 280)
GUISetBkColor(0xFFFFFF)

$hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 20, 30, 362, 224, BitOR($ES_MULTILINE, $WS_VSCROLL))
$iExStyte = _WinAPI_GetWindowLong( $hRichEdit, $GWL_EXSTYLE ) - $WS_EX_CLIENTEDGE
_WinAPI_SetWindowLong( $hRichEdit, $GWL_EXSTYLE, $iExStyte )

_GUICtrlRichEdit_SetText($hRichEdit, $text)
_GUICtrlRichEdit_AppendText($hRichEdit, @CRLF & @CRLF & $text)
;~ _GUICtrlRichEdit_AppendText($hRichEdit, @CRLF & @CRLF & $text)

_GUICtrlRichEdit_SetSel($hRichEdit, 0, -1)              ; select all and set the font for the block
_GUICtrlRichEdit_SetFont($hRichEdit, 14, "Arial")
_GUICtrlRichEdit_SetSel($hRichEdit, 0, 0)                ; set cursor to start

GUISetState()
_SendMessage($hRichEdit, $EM_EXLIMITTEXT, 0, 1000)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        _GUICtrlRichEdit_Destroy($hRichEdit)
        Exit
    EndSwitch
WEnd

 

Edited by qwert
Link to comment
Share on other sites

16 hours ago, qwert said:

when no more characters can be entered?

Suggestion : use  _GUICtrlRichEdit_SetEventMask and WM_NOTIFY to get key events in the richedit, then get the content using _GUICtrlRichEdit_GetText, and if StringLen of content = 1000 then throw a warning, or change a label color green/red, etc

Edited by mikell
Link to comment
Share on other sites

3 minutes ago, mikell said:

use  _GUICtrlRichEdit_SetEventMask and WM_NOTIFY

Would you happen to know of an example of this method?  I tried setting the event mask at one point, but didn't any "change" event once the control was full.  (code segment shown below)

Thanks for your response.

 

_GUICtrlRichEdit_SetEventMask($hRichEdit, $ENM_CHANGE)
:
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
:
Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    If $lParam = $hRichEdit And _WinAPI_HiWord($wParam) = $EN_CHANGE Then
        ConsoleWrite("Edit content changed" & @CRLF)
    EndIf
EndFunc

 

Link to comment
Share on other sites

An analysis/test of which $ENM_CHANGE events are reported for the control has revealed that it generates a HiWord of 1281 upon any attempt to enter a character, once the control is at its character limit. (code is below)

Although I haven't been able to determine what, specifically, a 1281 event is, I'm glad to have something that detects the case.

 

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    If $lParam = $hRichEdit And _WinAPI_HiWord($wParam) = 1281 Then
        ConsoleWrite("Edit content full" & @CRLF)
    EndIf
EndFunc

 

Link to comment
Share on other sites

@qwert

If you look closely in the Help file about _GUICtrlRichEdit_SetEventMask(), you'll see that Notification Codes are captured by a WM_NOTIFY Windows Message, instead of a WM_COMMAND one, as it is stated even in the MSDN documentation.

I was trying to give you an example yesterday, but didn't be able to do it ( not so much spare time ).

And I've found one of many posts where someone already helped you with these RichEdit controls :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Thanks for your response.  I had overlooked the example that you provided.

But what I've done is implement according to a response Melba23 gave me a couple of years back:

Quote

qwert, You need to register WM_COMMAND, not WM_NOTIFY - then you get a response whenever the content is changed

I'll be the first to admit I don't have a good grasp on the COMMAND vs NOTIFY differences. But the fact that the WM_COMMAND catches the "full" condition makes me believe it's a valid method.

Am I missing something?  Here's the link to M23's post: link

Link to comment
Share on other sites

@qwert
Hmm nice catch. In this case SetEventMask is not needed

" EN_MAXTEXT notification code :
Sent when the current text insertion has exceeded the specified number of characters for the edit control. The text insertion has been truncated.
(...) The parent window of the edit control receives this notification code through a WM_COMMAND message.

Remarks : The parent window always receives a WM_COMMAND message for this event, it does not require a notification mask sent with EM_SETEVENTMASK. "

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") 

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)  
    If $lParam = $hRichEdit And _WinAPI_HiWord($wParam) = $EN_MAXTEXT Then
        ConsoleWrite("Edit content full" & @CRLF)
    EndIf
  Return 'GUI_RUNDEFMSG'
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...