Link : http://www.codeguru.com/Cpp/controls/listview/gridlines/article.php/c963
[code]
void CListCtrlEx::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)
{
int i;
// Get the number of columns
CClientDC dc(this);
CPen myPen, *oldPen;
myPen.CreatePen(PS_SOLID, 1, RGB(226, 233, 245));
oldPen = dc.SelectObject(&myPen);
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(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, top);
dc.LineTo( borderx, rect.bottom );
}
// Draw the horizontal grid lines
int nNoneItem;
// First get the height
nNoneItem = GetItemRect(0, &rect, LVIR_BOUNDS);
int height = rect.bottom - rect.top;
GetClientRect(&rect);
int width = rect.right;
TRACE(L"none item : %d\n", nNoneItem);
if (!nNoneItem)
{
// 리스트 상에 내용이 없을 경우는...
// 이러는 수밖에 없지 머..
for(i = 1; i <= 50; i++)
{
dc.MoveTo(0, (top + 14*i)-1);
dc.LineTo(width, (top + 14*i)-1);
}
}
else
{
for(i = 1; i <= GetCountPerPage(); i++)
{
dc.MoveTo(0, (top + height*i)-1);
dc.LineTo(width, (top + height*i)-1);
}
}
dc.SelectObject(oldPen);
}
// Do not call CListCtrl::OnPaint() for painting messages
}[/code]
[code]
void CListCtrlEx::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)
{
int i;
// Get the number of columns
CClientDC dc(this);
CPen myPen, *oldPen;
myPen.CreatePen(PS_SOLID, 1, RGB(226, 233, 245));
oldPen = dc.SelectObject(&myPen);
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(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, top);
dc.LineTo( borderx, rect.bottom );
}
// Draw the horizontal grid lines
int nNoneItem;
// First get the height
nNoneItem = GetItemRect(0, &rect, LVIR_BOUNDS);
int height = rect.bottom - rect.top;
GetClientRect(&rect);
int width = rect.right;
TRACE(L"none item : %d\n", nNoneItem);
if (!nNoneItem)
{
// 리스트 상에 내용이 없을 경우는...
// 이러는 수밖에 없지 머..
for(i = 1; i <= 50; i++)
{
dc.MoveTo(0, (top + 14*i)-1);
dc.LineTo(width, (top + 14*i)-1);
}
}
else
{
for(i = 1; i <= GetCountPerPage(); i++)
{
dc.MoveTo(0, (top + height*i)-1);
dc.LineTo(width, (top + height*i)-1);
}
}
dc.SelectObject(oldPen);
}
// Do not call CListCtrl::OnPaint() for painting messages
}[/code]
'Windows > MFC' 카테고리의 다른 글
CComboBox Ownerdraw combobox(skin) (0) | 2013.10.02 |
---|---|
CHeaderCtrl Skin image (0) | 2013.10.02 |
CustomDraw ListView (0) | 2013.10.02 |
NM_CUSTOMDRAW (LISTCTRL) (0) | 2013.10.02 |
Visual Studio 언어 문제 (지역 문제) (0) | 2013.10.02 |