我正在读CDDS_ITEMPREPAINT中的子项的tv.pszText,但每次运行此代码时它都会返回垃圾值。但它适用于父节点
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
char achBuf[100];
case WM_NOTIFY:
{
LPNMTREEVIEW pnm = (LPNMTREEVIEW)lParam;
if (pnm->hdr.code == NM_CUSTOMDRAW)
{
LPNMTVCUSTOMDRAW lplvcd = (LPNMTVCUSTOMDRAW)lParam;
switch (lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT :
return CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
hwndTree = GetDlgItem(hWnd,ID_TREEVIEW);
if(lplvcd->iLevel==0)
{
lplvcd->clrText = RGB(0, 255,0);
ZeroMemory(&tv, sizeof(TVITEM));
tv.hItem=(HTREEITEM)lplvcd->nmcd.dwItemSpec;
tv.mask=TVIF_TEXT|TVIF_HANDLE;
tv.cchTextMax=100;
tv.pszText=(LPWSTR)achBuf;
if(TreeView_GetItem(hwndTree,&tv))
{
achBuf;
}
}
if(lplvcd->iLevel==1)
{
ZeroMemory(&tv, sizeof(TVITEM));
tv.hItem=(HTREEITEM)lplvcd->nmcd.dwItemSpec;
tv.mask=TVIF_TEXT|TVIF_HANDLE;
tv.cchTextMax=100;
tv.pszText=(LPWSTR)achBuf;
if(TreeView_GetItem(hwndTree,&tv))
{
achBuf;
}
}
}
}
}
它对于水平== 0的运行很好,它是父节点,但对于水平== 1,它们是子节点,它获得垃圾值。感谢帮助!