C++ Win32: fast word processing-style text rendering under Windows 7 - c++

At user request, my (for now C#) application reads big chunks of rich text (for now, in .NET FlowDocument XAML format) from a SQL Server database, and displays it.
I use a C# RichTextBox for that, it works but the whole thing is much too slow (the whole application is not very responsive). I want to remake everything in native C++.
What is the best way to get fast rich text rendering in Windows 7?
I would welcome suggestions
1) on the text API to use (Direct2D/DirectWrite or GDI or something else? use glyphs or higher level functions?),
2) also on how to store the rich text in memory to accomodate scrolling up and down the flow of text, insertion in the middle of the text etc.
Thanks.

Related

How to split c++ console screen into parts?

I'm making a c++ console application, I want to split the console screen into parts and every part will print an individual output, to be more clear the console screen should be close to the design of Far Manger console app screen, but I have no idea how to start and what libraries should I use to do so. Sorry if it's a naive question but I seriously have no idea and couldn't find what I want when I made a search.
If you want control of console text, such as positioning, or representation in a windowed fashion, have a look at ncurses.
Your target system may support escape sequences (see the wiki ANSI Escape Codes), or have particular API (as mentioned in the above comments) to implement console manipulation.

Localisation not working in static control [duplicate]

This question already has answers here:
Get text width in MFC
(4 answers)
Closed 8 years ago.
I am developing one Window based application, As it is window based desktop application I need to support multiple languages from Chinese to french and from Hindi(Indian) to Portuguese(Brazil) now thinks work great still there same size of text for display.But for following example,
If my one static control contain following text
Select Output Range |_Text Box__|
As i am developing it in English so size of static is considered according to English text size. Thinks work great.
Now same text i converted into Chinese view of above static control is like follow,
选择输出范围 |_Text Box__|
I am happy as size of Chinese is less than size of English but when i convert same text from English to french following is size of static control,
Sélectionnez Plage de sortie|_Text Box__|
My bad size of text is increased by some worlds as we have big text on less size text, View of text will clipped like following way,
Select Output Range |_Text Box__|
Sélectionnez Plage |_Text Box__|
In french size of text is increase ,So how to handled mismatch of text size pro-grammatically?
There are different ways to handle this problem. The answer depends on the way you handle the localisation in your code.
Note that some locals need the display to be inverted from left to right -> right to left (arabic...)
In this case you will have to handle cases where:
Select Output Range |_Text Box__|
must become:
|_Text Box__| <translated text into arabic or hebrew>
So you must be aware that translating a dialogbox is not just translating the labels. You have started noticing that because label lengthes are not the same.
If you choose to have a very simple localisation mecanism, like having a text file (containing the list of all labels) for each language, then you cannot do much more than trying to size your labels with a one-size-fits-all-languages. Dialogboxes won't look very nice in some languages. And you won't be able to use right-to-left languages. This is the quick and dirty way.
If you want to go further, the most common way is to have a resource file for each language. When your program is almost done, you have to duplicate the resource file. You have a copy for each language. You localize the whole dialogboxes, menus, etc. When you localize a dialogbox in French, you can make the label fields larger. And smaller for chinese. You can also change the dialogbox layout for arabic if you want.
Of course you have to build a version of your software for each language.
Your post has the MFC tag, so I suppose you might be interested in the MFC extension DLLs. This is the standard way for an MFC app to handle localisation. You create a DLL that only contains a resource file. If you support 10 languages, you duplicate and translate 10 resource files, and you create 10 extension DLLs. The MFC automatically load the right DLL depending on the current Windows locale. See for exemple a sample on CodeProject
I would not advise you to write some code that would automatically move and resize the controls when the dialogbox is created, because this is not as easy as it seems. Unless your app is quite simple.

What function to use to select text?

I search a lot of on internet but didn't find some good copy-paste manager for windows 7. I want to make something to easy copying multiple texts. So my question is what function to use in c++ to select some text that will be copy. The plan is that every time when is pressed CTRL+C selected text copy to some txt file, and when is pressed CTRL+V application show you what is in that file, and you can use what text you need. The main question is how to select text, what function to use? Platform win 7.
You should read up a bit on how the Windows clip board works. Every application in the system can place objects of different formats (including text) on the clip board. The easiest way to grab the content out of any applications is probably to somehow monitor the clip board and get the data from there.
For the pasting part, if I remember correctly, there is a special kind of "owner-handled" data on the clip board. Using that, the data isn't actually published on the clip board, only a reference to the application currently having the clip board data. Whenever the data is pasted the application gets notified that it should send the data to the recipient. It should be possible to exploit that functionality to get your application to pop up a windows where the user can select what data to paste.
Please see my articles on clipboard viewer implementation, including common pitfalls:
http://www.clipboardextender.com/developing-clipboard-aware-programs-for-windows/6
http://www.clipboardextender.com/developing-clipboard-aware-programs-for-windows/common-general-clipboard-mistakes

Windows C++ Hex Viewer GUI component

I'm looking for a Windows C++ (or a Embarcadero Delphi/C++ Builder VCL component) GUI component for a professional looking Hex Viewer/Editor. While pretty easy to build up a rudimentary one I require a polished modern looking component. (Can handle arbitrary amounts of data, loading from some sort of stream as needed. Colors/Fonts customizable. Highlight byte selections/individual bytes)
2 of the more usable hex viewer/editor components from applications I've seen in action are below:
http://niiconsulting.com/checkmate/wp-content/uploads/2009/10/fileinsight-2.jpg
http://www.the-interweb.com/bdump/hexer/hexer-linux.png
Can anybody recommend anything?
Thanks in advance.
After a quick search on the interwebs, I found the following component for Delphi:
http://www.tkweb.eu/en/delphicomp/khexeditor.html
QHexEdit2 is now able to edit large files (> 2 GBytes) and is available for Qt4, Qt5, PyQt4, PyQt5. It is now hosted on Github
https://github.com/Simsys/qhexedit2
You didn't mention Qt as an option as a C++ library to use. But it sounds like your circumstance may be flexible. So if you're able to use it there are a couple of options I noticed.
There's a hex component that you can drop in as a replacement for QPlainTextEdit or whatever:
https://github.com/Simsys/qhexedit2
The webpage for that says that the size of data has in general to be below 10 megabytes. A heavier-weight paging solution exists as a program called LFhex (source in the download)
http://stoopidsimple.com/lfhex

Printing PDF to HDC (MFC device context)

I'm modifying a C++ application and I'd like to add the ability to print and existing PDF using the MFC printing logic (OnPrint...)
Is there any method to print a PDF into the MFC? Now I'm converting the PDF to a BMP but sometimes the quality is not so great.
Unless something's changed recently you need a 3rd party library to print PDF files. One direction you can take is to convert to PS and then use ghostscript to translate to printer speak. Ghostscript also has the power to convert PDF to PS.
I don't think MFC's own printing logic will work.
Adobe distributes a PDF ActiveX control (primarily for viewing PDFs in IE) that can also be hosted in an MFC application. It includes the following methods: Print, PrintAll, PrintAllFit, PrintPages, PrintPagesFit and PrintWithDialog.