Improve the ListView display effect with API

xiaoxiao2021-03-06  101

Listview Introduction ListView control is one of the very loved controls of VB developers. As a member of the Windows 95 public control group (COMCT L32.OCX), it often uses TreeView, Imagelist and other controls. Display a tree structure with TreeView, and use listView to display the record set of the selected node object, as shown below: Figure 1 This is a user interface of the author's "Document Management" module in the development financial software project. The left side of the screen is a TreeView control to display the category of the accounting credential; the right side is a listView to display the credential directory of the corresponding category; the top is a menu bar control (Menubar) and a toolbar control (Toolbar); one is one Status bar control (STAT USBAR) to display the number of credentials and the current date. The interface shown in the figure is very similar to the Window 95/98 resource browser. The interface style of Wi NDOWS has been accepted for the majority of users, and the main advantage of the Windows operating system is to provide all applications. Common interface. Master users who use Windows-based applications are easy to learn to use other applications. This method of using a combination of Windows 95 can reach consistency with the Windows interface, so it is often used in the development of the current VB5.0 application. Problems with a large number of result sets In practical application development, the contents of a database result set (Reco Rdset) are often populated with ListView. That is, first write a SQL query statement, generate a result set, and then fill in each record of the result set with the DO ... LOOP loop statement in the listView. However, when the result set is large (for example, there are more than 5,000 records), the time required for filling will be very long, the user has to wait for a long time to complete a query, so in the process of queries must be allowed to press the ESCAPE button to exit . The specific approach is to add a doevents function in the DO ... Loop cycle, and write a interrupt exit program code. The DOEvents function is: transfer control to allow the operating system to handle other events. This will exit the cyclic body if the user presses the ESCAPE button, and end the query process. However, this will lead another question: Since Doevents can make the operating system respond to other events, the process of populating each ListView project (ListItem) is also displayed, so the screen will keep the screen during the fill. This phenomenon certainly cannot be accepted by the user. How to solve this problem? Solution to solve this problem with the Windows API function. Here, first, a few of the A PI functions for use is explained and explained. 1. The functionality of the getClientRect lib "User32" (LPREC T as Rect) AS LO NG This function is to get a rectangular frame area (R ectangle) of the target window (Window). HWND is the handle of the specified object or form. LPRECT is the structure of the return rectault box (must be defined as a variable of the structural type). 2. ValidateRect LIB "User HWND As Long, LPRECT AS" The function of this function is to take effect to the specified rectangular area, notifying Windows without having to repeat the specified area (R Edraw). 3. INVALIDATERECT LIB "BYVAL HWND As Long, LPRE CT As Rect, BYVA L BERASE AS Long) The function of this function is to invalidate the specified rectangular area, inform Windows to redraw over the designated area. The specific implementation steps are as follows: 1. First obtain the ListView display area with the getClientRect function before the fill result set. 2. Place this area after adding a display item (ListItem) to use the ValidateRect function. Thus, Windows will not display each ListItem, and the phenomenon of screen flash will disappear. 3. After the fill result set, this area is invalid with the invalidaterect function.

转载请注明原文地址:https://www.9cbs.com/read-96900.html

New Post(0)