Pagination of VC ++ large documents

Source: Internet
Author: User


Pagination of VC ++ large documents
Keywords: large document paging display RichEdit
1. Question proposal
There are three methods to process large files: Memory ing, multipart read/write, and multi-thread read/write. This article provides an example of paging processing for large text documents. The solution is not found on the Internet on the page, and there is no relevant article about codeproject. I got a clue on the Internet and finally completed this function. Of course, there are still writing deficiencies, I will leave these shortcomings at the end of this article and hope experienced readers can provide me with some guidance.
2. Difficulties
(1) how to Paging
MFC does not provide a ready-made View class to support paging. Some people on the Internet say that the RichEdit control of a later version supports automatic paging, but I have not found it yet.
(2) how to read big document data
Reading and Writing large documents is very troublesome. If too few pages are read on each page, too many pages will cause resource waste. If too many pages are displayed on each page, a scroll bar will appear on each page, the reading performance of mainstream products such as Word wps pdf cannot be achieved, and the user experience is poor. Dynamic Calculation of the size of each page is a big problem. The general calculation method is always biased, and it is difficult to guarantee correctness.
(3) how to manage pages
With paging support, you must manage other user operations such as display, update, and scrolling of each page.
3. Problem Solving
(1) how to add a View class that supports pagination
To support paging scrolling, you must derive your own class. In this example, the custom cpagingdemoview class is derived from cscrollview.
(2) how to manage pages
Uses the Linked List data structure and adds them to the linked list for management based on each page generated by dynamic paging. Prior to the definition of the linked list, cobject must derive its own template class crichctrobj, this class provides support for each page display. The linked list is defined as follows:
Typedef ctypedptrlist <coblist, crichctrobj *> crichctrlist;
(3) how to construct each page
Each page displayed by PAGE must support dynamic creation, page display, header, border, and other operations. Therefore, a custom display control must be derived from the display control. In this example, cricheditctrlex is derived from cricheditctrl. These operations are supported. More importantly, after paging memory management, each page dynamically allocated must have good memory management; otherwise, the memory will be exhausted.
The design of the above three classes is shown in:

(4) how to read data
For large documents, a new thread must be enabled to read data. Otherwise, the user interface will not respond due to the long wait time for data processing, resulting in poor user experience. While reading data, each page is dynamically generated and filled with data. Because the interface control created in the main thread cannot be modified in the new thread (Experimental Proof), the message sending method is required. To complete these functions, You need to define some messages as follows:
# Define app_createlabel wm_user + 1 // create a page number for the cricheditctrlex object
# Define app_streamdata wm_user + 2 // cpagingdemoview enable the Data Reading thread
# Define app_createctrl wm_user + 3 // cpagingdemoview create the cricheditctrlex object on each page
# Define app_writedata wm_user + 4 // cpagingdemoview read data from each cricheditctrlex object
The Data Reading process is shown in:

(5) How to scroll the document
The scrolling is handled by the window. The scrolling messages of the cricheditctrlex object on each page are routed to the window for processing. The routing process is as follows:
Void cricheditctrlex: onmousehwheel (uint nflags, short zdelta, cpoint pt)
{
Int ndist = ABS (zdelta)/wheel_delta + 1;
While (ndist --)
{
// Window management scroll
Getparent ()-> postmessage (wm_vscroll, zdelta> 0? Sb_lineup: sb_linedown );
}
Cricheditctrl: onmousehwheel (nflags, zdelta, pt );
}
4. display running results by PAGE
Page 1:
Page 2:

5. Unresolved Issues
(1) The interface thread and background data thread are not properly designed, and the process of opening the document is slow.
(2) When the page scroll volume exceeds 32767, an exception occurs. Although some texts on the Internet are introduced, this problem has not been solved yet.
(3) page-based printing and preview are not complete yet.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.