阅读:1684回复:0
我用如下代码操作TREEVIEW时,有问题,总是不能正确的加入节点[主要是case WM_NOTIFY:那里有问题]
int _stdcall dlgproc(HWND hdlg,UINT message,WPARAM wparam,LPARAM lparam)
{ HTREEITEM htreeitem; TVINSERTSTRUCT treeitem; TVHITTESTINFO tvhit; htreeitem=NULL; HWND treehwnd=::GetDlgItem(hdlg,IDC_TREE1); switch(message) { case WM_INITDIALOG: ::SetWindowText(hdlg,"the first dialog"); break; case WM_COMMAND: switch(LOWORD(wparam)) { case IDOK: treeitem.hInsertAfter=TVI_LAST; treeitem.hParent=TVI_ROOT; treeitem.item.mask =TVIF_TEXT|TVIF_CHILDREN|TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE; treeitem.item.cChildren =1; treeitem.item.cchTextMax = 6; treeitem.item.pszText="c"; treeitem.item.lParam = 0; htreeitem=(HTREEITEM)SendMessage( treehwnd, TVM_INSERTITEM, 0, (LPARAM)&treeitem); break; case IDCANCEL: ::EndDialog(hdlg,IDCANCEL); break; } break; case WM_NOTIFY: if (wparam==IDC_TREE1) { NMHDR* pheader=(NMHDR*)lparam; HWND htree=pheader->hwndFrom; if(pheader->code==TVN_ITEMEXPANDING) { DWORD dwpos = GetMessagePos(); tvhit.pt.x = GET_X_LPARAM(dwpos); tvhit.pt.y = GET_Y_LPARAM(dwpos); MapWindowPoints(HWND_DESKTOP,treehwnd, &tvhit.pt, 1); treeitem.hInsertAfter=TVI_LAST; treeitem.hParent=TreeView_HitTest(treehwnd, &tvhit); treeitem.item.mask = TVIF_TEXT|TVIF_CHILDREN|TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE; treeitem.item.cChildren =1; treeitem.item.cchTextMax = 10; treeitem.item.pszText="c_child1"; treeitem.item.lParam = 0; htreeitem=(HTREEITEM)SendMessage( treehwnd, TVM_INSERTITEM, 0, (LPARAM)&treeitem); } } break; } return 0; } |
|