1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
void CListCtrlEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
TCHAR lpBuffer[256];
LV_ITEM lvi;
lvi.mask = LVIF_TEXT | LVIF_PARAM ;
lvi.iItem = lpDrawItemStruct->itemID ;
lvi.iSubItem = 0;
lvi.pszText = lpBuffer ;
lvi.cchTextMax = sizeof(lpBuffer);
VERIFY(GetItem(&lvi));
LV_COLUMN lvc, lvcprev ;
::ZeroMemory(&lvc, sizeof(lvc));
::ZeroMemory(&lvcprev, sizeof(lvcprev));
lvc.mask = LVCF_WIDTH | LVCF_FMT;
lvcprev.mask = LVCF_WIDTH | LVCF_FMT;
for ( int nCol=0; GetColumn(nCol, &lvc); nCol++)
{
if ( nCol > 0 )
{
// Get Previous Column Width in order to move the next display item
GetColumn(nCol-1, &lvcprev) ;
lpDrawItemStruct->rcItem.left += lvcprev.cx ;
lpDrawItemStruct->rcItem.right += lpDrawItemStruct->rcItem.left ;
}
// Get the text
::ZeroMemory(&lvi, sizeof(lvi));
lvi.iItem = lpDrawItemStruct->itemID;
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.iSubItem = nCol;
lvi.pszText = lpBuffer;
lvi.cchTextMax = sizeof(lpBuffer);
VERIFY(GetItem(&lvi));
CDC* pDC;
pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
if ( lpDrawItemStruct->itemState & ODS_SELECTED )
{
pDC->FillSolidRect(&lpDrawItemStruct->rcItem, GetSysColor(COLOR_HIGHLIGHT)) ;
pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT)) ;
}
else
{
pDC->FillSolidRect(&lpDrawItemStruct->rcItem, GetSysColor(COLOR_WINDOW)) ;
pDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT)) ;
}
pDC->SelectObject(GetStockObject(DEFAULT_GUI_FONT));
UINT uFormat = DT_LEFT ;
::DrawText(lpDrawItemStruct->hDC, lpBuffer, strlen(lpBuffer),
&lpDrawItemStruct->rcItem,uFormat) ;
pDC->SelectStockObject(SYSTEM_FONT) ;
}
}
LRESULT CListCtrlEx::OnSetFont(WPARAM wParam, LPARAM lParam)
{
CRect rc;
GetWindowRect(&rc);
WINDOWPOS wp;
wp.hwnd = this->m_hWnd;
wp.cx = rc.Width() ;
wp.cy = rc.Height() ;
wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
LRESULT lrReturn(Default());
SendMessage(WM_WINDOWPOSCHANGED, 0, reinterpret_cast<LPARAM> (&wp));
return lrReturn;
}
void CListCtrlEx::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
// Get the LOGFONT for the current font.
LOGFONT lf;
::ZeroMemory(&lf, sizeof(lf));
CFont* pFont = GetFont();
ASSERT_VALID(pFont);
if (pFont)
VERIFY(pFont->GetLogFont(&lf));
int nAdj(4) ;
m_nLinesPerRow = max(m_nLinesPerRow, 1);
if (lf.lfHeight < 0)
lpMeasureItemStruct->itemHeight = ((-lf.lfHeight+nAdj) * (m_nLinesPerRow));
else
lpMeasureItemStruct->itemHeight = ((lf.lfHeight+nAdj) * (m_nLinesPerRow));
}
void CListCtrlEx::OnInitialUpdate()
{
int i, j ;
LV_COLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
// Insert Header columns
for(i = 0; i<m_nColumns; i++)
{
lvc.iSubItem = i;
lvc.pszText = _gszColumnLabel[i];
lvc.cx = _gnColumnWidth[i];
lvc.fmt = _gnColumnFmt[i];
InsertColumn(i,&lvc);
}
// Insert First Column items for every row
LV_ITEM lvi;
lvi.mask = LVIF_TEXT | LVIF_STATE ;
char buf[51] ;
for(i=0; i<m_nRows; i++)
{
sprintf(buf, "Line 1 text \n lots a a \n more text") ;
lvi.iItem = i;
lvi.iSubItem = 0;
lvi.state = LVIS_SELECTED | LVIS_FOCUSED ;
lvi.stateMask = LVIS_SELECTED | LVIS_FOCUSED ;
lvi.pszText = buf ;
InsertItem(&lvi);
if (i == 0) m_nLinesPerRow = 3;
else m_nLinesPerRow = 5;
for(j = 1; j<m_nColumns; j++)
{
SetItemText(i,j,_gszItem[i][j]);
}
}
// if ( m_nLinesPerRow > 1 )
// {
m_NewListFont.CreatePointFont(180,"MS Serif");
SetFont(&m_NewListFont);
// }
CHeaderCtrl* pHeader = NULL;
pHeader=GetHeaderCtrl();
if(pHeader==NULL)
return;
VERIFY(m_HeaderCtrl.SubclassWindow(pHeader->m_hWnd));
HDITEM hdItem;
hdItem.mask = HDI_FORMAT;
for(i=0; i<m_HeaderCtrl.GetItemCount(); i++)
{
m_HeaderCtrl.GetItem(i,&hdItem);
hdItem.fmt|= HDF_OWNERDRAW;
m_HeaderCtrl.SetItem(i,&hdItem);
}
}
void CListCtrlEx::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
CListCtrl::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
} |
Partager