Drawing horizontal and vertical gridlines for CListCtrl
来源:互联网 发布:unity3d 5.x视频教程 编辑:程序博客网 时间:2024/05/01 08:16
Rating: none
Zafir Anjum (view profile)
August 6, 1998
The vertical grid line is actually drawn one pixel left of the column border. This aligns it better with the column header. It also introduces a bug. When you increase a column width, the column area below the last visible item is not updated, thus leaving traces of the previous line. There are two approaches you can take to resolve this. First, draw the line exactly on the column border (e.i. do not subtract 1 from borderx). The second approach is to handle the HDN_TRACK notification from the header control and invalidate the exposed area so that it gets redrawn. BTW, Paul Gerhart has also implemented this using an owner-drawn CListCtrl. He has made the source code available with a sample app. You can find it at http://www.voicenet.com/~pgerhart/_shware.html
To draw horizontal and vertical gridlines we essentially use the same method used for the vertical gridline or column border used in the previous section. After drawing the vertical lines, we use GetItemRect() to get the item height and then we draw the horizontal grid lines based on this height. One implication of using GetItemRect() is that it fails when the list does not have any items in it and no horizontal line is drawn. Here is the complete code of the overridden OnPaint() function. Also note that the next version of the list view control will support the LVS_EX_GRIDLINES style and should make our code redundant.
(continued) void CMyListCtrl::OnPaint() { // First let the control do its default drawing. const MSG *msg = GetCurrentMessage(); DefWindowProc( msg->message, msg->wParam, msg->lParam ); // Draw the lines only for LVS_REPORT mode if( (GetStyle() & LVS_TYPEMASK) == LVS_REPORT ) { // Get the number of columns CClientDC dc(this ); CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); int nColumnCount = pHeader->GetItemCount(); // The bottom of the header corresponds to the top of the line RECT rect; pHeader->GetClientRect( &rect ); int top = rect.bottom; // Now get the client rect so we know the line length and // when to stop GetClientRect( &rect ); // The border of the column is offset by the horz scroll int borderx = 0 - GetScrollPos( SB_HORZ ); for( int i = 0; i < nColumnCount; i++ ) { // Get the next border borderx += GetColumnWidth( i ); // if next border is outside client area, break out if( borderx >= rect.right ) break; // Draw the line. dc.MoveTo( borderx-1, top); dc.LineTo( borderx-1, rect.bottom ); } // Draw the horizontal grid lines // First get the height if( !GetItemRect( 0, &rect, LVIR_BOUNDS )) return; int height = rect.bottom - rect.top; GetClientRect( &rect ); int width = rect.right; for( i = 1; i <= GetCountPerPage(); i++ ) { dc.MoveTo( 0, top + height*i); dc.LineTo( width, top + height*i ); } } // Do not call CListCtrl::OnPaint() for painting messages }
- Drawing horizontal and vertical gridlines for CListCtrl
- Horizontal and vertical center alignment
- Horizontal and Vertical Reflection of Images
- 3.2 Defining Horizontal and Vertical Constraints with the Visual Format Language
- Android之vertical和horizontal的区别
- android中horizontal和vertical的区别
- QT 中Vertical Layout 和 Horizontal Layout
- 10 Best HTML5 Sketching and Drawing Tools for Designers
- Combining Sketch and Tone for Pencil Drawing Production
- Combining sketch and tone for pencil drawing production简述
- Qt设置horizontal line 和vertical line 的颜色
- Qt设置horizontal line 和vertical line 的颜色
- Horizontal Decoupling of Cloud Orchestration for Stabilizing Cloud Operation and Maintenance
- codeforces Bear and Drawing
- Skia is a complete 2D graphic library for drawing Text, Geometries, and Images.
- Combining Sketch and Tone for Pencil Drawing Production的优化过程
- 基于《Combining Sketch and Tone for Pencil Drawing Production》的图像铅笔画算法的实现
- 素描效果实现Combining Sketch and Tone for Pencil Drawing Production笔录
- 美人如诗
- 经典的大学四年心得【我不是原创,但是我举双脚同意】
- QQ聊天對話...
- 什么是流媒体?
- about aop
- Drawing horizontal and vertical gridlines for CListCtrl
- 关于黄家驹的一点想法
- 瓦^_^
- 动态编程语言介绍
- 天籁
- 学习DotNet经典网站
- 期末考试终于完成
- 获得web.config文件中appsettings中的字段值
- oracle是如何工作的