Rich Edit control: Prevent immediate repainting/updating? - windows-controls

I'm trying to replace some text in a range in a rich edit control. The two line way to do it is by sending a EM_EXSETSEL followed by a EM_REPLACESEL. However, this causes an annoying flickering when the text is briefly selected, before being replaced. Is there any way to suspend repainting? I'm hoping for something like this:
SendMessage(EM_SUSPEND_PAINTING)
SendMessage(EM_EXSETSEL)
SendMessage(EM_REPLACESEL)
SendMessage(EM_RESUME_PAINTING)
(with the appropriate WPARAM and LPARAM values, of course)

The EM_HIDESELECTION command is most excellent.

Related

Remove the limit on the number of characters that can be entered into a Win32 Edit control

I've searched everywhere and it seems I can't find a solution to this problem..
My problem isn't limiting the amount of characters that can be entered into an edit control, my problem is I am limited by the size of the edit control. I want to be able to type past the size of the edit control.
I've tried extending the character limit to a high number with SendMessage and sending EM_LIMITTEXT, but that only seems to work if I want to limit it even more.
Here's an image example of my problem:
I use CreateWindowEx to create the edit control, but there doesn't seem to be an extended window style OR an edit control style that achieves what I want.
The style you're looking for is ES_AUTOHSCROLL. Without this style, input cannot go past the length of the edit control. With this style, text is automatically scrolled to the right by 10 characters when the input reaches the end of the control.
You may also be interested in ES_MULTILINE, which does exactly what it says. The default (without this style) is a single-line edit control.
All of the available styles are documented here. These are just regular window styles, not extended ones.
Also, I am pretty sure that you cannot change these styles at runtime, after the control has been created. Therefore, make sure that they are specified when you call CreateWindowEx, or in your resource file if the control lives on a dialog.

displaying ellipsis in CEdit control

I'm surprised that i haven't found much online concerning the display of ellipsis in a CEdit control in MFC. We have a control that can show only about 20 characters but the max length of the string that goes into the control is 32 characters. I am interested in showing a middle or end ellipsis if the string length goes beyond the visible length. Has anyone tried this? Something that concerns me is whether the string pulled out of that control using GetWindowText will return the actual string or the string with the displayed ellipsis?
CEdit displays the window text. If you want to change the display, change the text.
You can change the window text to something more readable when the edit loses focus, and restore the original text when the window gain focus again. Also adjust your GetWindowText calls to read from a variable instead of a window.

Display tooltip for a selected word

I'm writing a simple text editor using Python 2.7, pyqt library. I basically want to display the meaning of a word when the user selects the word in the text editor.
So far I can detect the word under the cursor, look it up in my dictionary and return the meaning (using a print statement) so I know I can get the guts to work.
My trouble is displaying the meaning of the word in a tooltip that doesn't dissapear in less than 2 miliseconds. So far I have been using this:
QtGui.QToolTip.showText(QtGui.QCursor.pos(), tool_tip_text)
Ideally want to show the meaning just over where the selection was made, so far this displays the tooltip so quickly that I can't even read the meaning of the word under the cursor. It just pops up and dissapears almost immediately. Can anyone share how to make the tooltip remain visible for at least 5 seconds, or until the user de-selects the word.
I am not using the QHELPEVENT (not even quite sure how the helpevent is triggered) I am just calling my lookup_word_in_dictionary() function when a word has been selected.
Any samples are much appreciated.
Thanks, I found a solution, creating my own popup class, subclassed from QWidget
and used a simple timer to hide the tooltip
QTimer.singleShot(5000, self.hide_tooltip) #check to see if the tooltip shold be hidden after 5 secs
you can replace QToolTip by QSplashScreen,if you are Chinese ,please look at this post .
BTW , can you share the method that you detect the word under the cursor with me ?

Constraining Edit Control content

I've scanned through all pages in MSDN, but still not found asnwers of following.
Minimum Character Length of edit control.
Specifying range for input values in edit control.
Permitting only alphabets in edit control.
Setting tooltip for button control.
Please tell me how to do this in Win32.
This is hard to do properly. A naive approach would handle WM_KEYDOWN messages to intercept the backspace and delete keys (VK_BACK and VK_DELETE). However, you also need to handle a user selecting some of the existing text and then deleting it (via backspace or delete), cutting it, or replacing it (by typing a key or by pasting some other text). I don't think it's worthwhile, and even if you could do this well, it is likely to be confusing when you break all of those normal behaviors. (It also can be incredibly annoying. Imagine that you have some text "bar" in the control but you want to change it to "baz". If the control enforces a minimum length of 3, then attempting to backspace over the last character won't work. You would have to change it to "barz" first and before being able to delete the "r" character. Ugh.)
If your control needs a minimum length, you're better off enforcing it during a separate validation step (such as when the user clicks an OK button or moves focus to another control) and showing an appropriate error message.
I'm not sure whether you mean allowing only certain characters to be entered into an edit control or whether you want to restrict it to a range of numeric values. For the former, see 3.
If you want to restrict values to a certain numeric range, I again recommend doing it during a separate validation step instead. Otherwise you again might prevent the user from inserting and deleting characters in a normal way. If you can, avoid using using an Edit control and use a Trackbar (slider) control.
You would have to subclass the Edit control, handle WM_CHAR messages, and reject characters that you don't want. You additionally would need to handle WM_PASTE messages and perform similar validation.
This doesn't have anything to do with Edit controls and probably should be a separate question. What have you tried? Have you read http://msdn.microsoft.com/en-us/library/bb760250.aspx ?

Paste multi-line text into single-line Edit Box control

My app uses standard single-line Edit Box controls. Is there any way to accept a multi-line "paste", discarding carriage return / linefeeds?
Notes
I don't want to use multi-line controls
My app is VS2010 C++ with WTL (not MFC or ATL)
The reason I want this is because actual input is normally quite short, but could in rare circumstances be hundreds or even thousands of characters. In which case users might well want to build the string using NotePad or whatever, then just cut & paste it in.
This is not possible as the user is pasting himself/herself. An alternative is to use a multi-line Edit Box and displaying all the data into one line by managing the pasted data into OnChange function for your control (basically disregading new lines).