重写CListCtrl更改行高,但出现内存泄露,请大家帮我看看代码

zhou1xp zhou1xp 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我的代码如下:
void newctrl::SetItemHeight(UINT nHeight)
{
m_nItemHeight = nHeight;
CRect rcWin;
GetWindowRect(&rcWin);
// GetClientRect(rcWin);
WINDOWPOS wp;
wp.hwnd = m_hWnd;
wp.cx = rcWin.Width();
wp.cy = rcWin.Height();
wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
SendMessage(WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp);
}

void newctrl::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->FillSolidRect(&lpDrawItemStruct->rcItem,RGB(38,123,165)) ;
pDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT)) ;
}

pDC->SelectObject(GetStockObject(SYSTEM_FONT));

UINT uFormat=DT_LEFT ;

::DrawText(lpDrawItemStruct->hDC, lpBuffer, wcslen(lpBuffer),
&lpDrawItemStruct->rcItem, uFormat) ;

pDC->SelectStockObject(SYSTEM_FONT) ;
}
}

void newctrl::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
if(m_nItemHeight>0)
lpMeasureItemStruct->itemHeight=m_nItemHeight;
}


每次我从数据库中加载数据后,会有20K的内存泄露
...全文
评论 6
收藏 已收藏
分享
返回顶部
zhou1xp
界面 15,976 成员 115,866 内容