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

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

Related

how to add tab character into test string section of regex101.com

I am using regex101.com to learn regex.
There will be cases where I want to insert a Tab character within the TEST STRING field of regex101.com.
However, when I have the TEST STRING field selected and press the tab key on my keyboard, it doesn't enter the tab character within the TEST STRING field, but rather it just moves me on to the next selectable feature within the browser page.
I note I have done a bit of googling but so far haven't been able to find the answer to how to add a tab character within the TEST STRING field. Although I know for sure it is possible to do this given that I have seen a few videos where the presenter successfully adds a tab character into the field.
I note that I am using Windows 10 and my browser is Google Chrome.
Would greatly appreciate if anyone could provide an answer to this.
Appears regex101 can enable the tab key to be translated by the editors
instead of being pass-through to the system where it changes focus to the
next control in the tab order.
Just uncheck the box in Settings .
Apparently preference gets saved in your browser session cookies.
Typing a Tab into a text editor and copy-pasting (Ctrl + c / Ctrl + v) it into the browser form is an easy solution. Just make sure your editor is not configured to auto-replace tabs with spaces.
Another way would be using a keyboard combination to enter the ASCII or Unicode character code (see this superuser post). For Windows, that should be Alt+ 0 + 9 (Note: apparently the numbers need to be entered on the numpad).
Finally, depending on the browser you use, there might be browser extensions that facilitate what you want. There used to be one called Tabinta for Firefox and one for Chrome called chrome-textarea-formatter, but I believe neither of them is still maintained.

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.

QTextEdit: typing in HTML/richttext

I have a QTextEdit and want the user to be able to type rich text which will then automatically be (correctly) shown in the widget (so: formatted).
It works fine when setting the text programmatically (using setText()), but not when manually typed. See picture below.. "Input" is set using setText, the following line is manually typed. I would like this line to automatically be formatted a
What's the (easiest) way to do this? The only way I can think about it to manually catch key events and explicitly set the text as HTML.. But I'm sure there's a better way.
Manual typed html gets escaped, the < will become a < etc . .
You wouldn't be able to edit it if that would not be the case, for obvious reasons.
You could try adding a [render] button or something like that to render the entered text to html. Trying to render on keypress is very dangerous because it makes it terribly inconvenient and counter-intuitive to type something and then have it magically change the output. Also un-finished markup will probably throw a stick in your wheel.
Also pasting from a rich text source (for example a webpage) keeps the formatting.
As "the JinX" already said it will not be so intuitive if you try to capture every key event and then try to change the text to render in HTML.
Though you can use some special key sequences, say "shift+return key" to change the text of current line/entire textedit to to html formatted one.
This is just a suggestion.
In this case more than implementation it is also about what a user will expect.
Changing the text of 1 line/entire textedit from plain to HTML would be easy to achieve as well.

Recommend me a solution for generating print preview and printing

INTRODUCTION AND RELEVANT INFORMATION:
I am maintaining an old application and I need to implement feature that generates reports based on data calculated from a database. User must also have an additional option of printing the file ( user must be able to choose printer, and must be able to see print preview ).
To improve my chances of getting satisfactory answer, allow me to additionally clarify matters with a small "example":
User presses a button -> application calculates data; // Done
Application creates file and populates it with the result; // Done
User gets informed that report is generated; // Done
User presses another button that is charged for printing; // Stuck here!
Print preview pops up and an option to run print dialog. // Stuck here
User starts the print dialog, chooses the printer and application prints the file;
The application is coded in C++ using raw WinAPI ( no MFC ). I am working on Windows XP.
PROBLEM:
I was able to successfully use OLE Automation to generate/save Word and Excel reports but I can not create print preview that matches exactly the print preview Word would create.
If I use OLE Automation to show Excel's print dialog/print preview, there is a following problem that might occur :
User can simply click "Close Print Preview", or can simply close print property sheet ( please see picture below ) and return to the document which might compromise document's data.
My employers do not like this ( they have no software engineering / developing background, so no matter what I say it will end up as an "echo in the wind"... ) and they wish that my print preview matches exactly the print preview Word generates.
Therefore, I need a solution for generating a print preview for the user, in a way that matches exactly print preview Word would create. Furthermore, user should be able only to see how this looks like, but not to be able to open the file from my application. User should be able to choose the printer that will print the file.
An implementation similar to the one from the picture would be fine.
QUESTION:
INTRODUCTORY NOTES:
The question is too broad to be answered in one post so I must limit myself only for seeking advice / general concept / pointing in the right direction.
THE ACTUAL QUESTIONS :
I did the best I could with the OLE Automation and Excel / Word files, but as you can see there are problems with generating a print preview, hence the following questions :
Since this is my first time to tackle this kind of task, can you recommend me the proper way to handle it ( general concepts of course )?
Is there a chance that there is a workaround for my printing problem ( like sending WM_PRINTCLIENT message to the Word / Excel or something like that )?
REMARKS :
Again, I realize the question is too broad so just give me general concepts / pointers, so I could post separate questions if I get stuck somewhere in the way.
I do not need to use Word / Excel and OLE Automation, it was my choice at the moment.
If you can recommend better solution I will gladly accept. I do not wish to use libraries.
If additional information is required, ask and I will edit my post.
You would need to bring up a dialog box when the user clicks the print button, the dialog box would contain a control that shows the preview for the default printer and three buttons to select another printer, print and exit.
The preview control could be a static control where the WM_PAINT handler would draw the preview (alternatives: a Web Browser control which is fed html text or a RichText control which is fed RTF text, but then you are constrained by the functionality of these controls).
Quote: Print preview
isn't that special. It just means that you have to render to screen
(or bitmap) what you'd otherwise would render to the printer DC. This
primarly means using the page size, and providing a UI control for the
prev/next page.
This SO Answer describes in detail the work you need to do to paint the preview.
This CodeProject article has some simple code for print-preview; it's in simple MFC which should not be too difficult to translate to plain C++/WinAPI.

Multi-line control in VCL forms

I am using C++ Builder to create a VCL forms application and am wanting a multiline editbox.
Am I correct in saying that I have to use a TRichEdit control to accomplish this?
If so, (and I have added one just to try out), how do I set the text in the control? There seems to be no .text or .caption property.
I can get the contents of the TRichEdit by the ->text property, but how do I 'set' the text?
Thanks
The Text property is read/write:
String s = RichEdit1->Text;
RichEdit1->Text = ...;
It is just declared as __published so you will not see it in the Object Inspector at design time. If you want to see the text at design time, you have to use the Lines property instead.
BTW, TRichEdit is not the only multi-line edit control. TMemo is another one. The main difference between them is that TRichEdit supports more formatting options than TMemo does. Think of them as the VCL equivalents of the MSWord and Notepad apps, respectively.