CDDS_ITEMPREPAINT GetItem return false for child

93 Views Asked by At

I am reading tv.pszText of child items in CDDS_ITEMPREPAINT but its returning garbage value every time i ran this code. But it works fine for Parent nodes

   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;
                                    }
                               }
                                  }
                                }
                              }

Its ruuning fine for level==0 which is parent node but for level==1 which are child nodes its getting garbage value. Help is appreciated!

0

There are 0 best solutions below