MFC search tree view based on label (name)
So I recently came across a need to use a tree view in an MFC based application. I also found I needed to search that tree based on the label (text displayed to the user). After some research I found an old link here at MSDN . However the article is almost 6 years old. MFC has changed a bit since then. So I had to change the code a bit to use all the new MFC macros for tree view usage. All these macros are also defined as functions on the CTreeCtrl class but doing it this way allows you to traverse any tree you want instead of being tied to a single instance. You can read more about the macros and treeviews here . All items are passed in except for MAXTEXTLEN which needs to be defined somewhere and included for reference. Mine is set to 100 since we can get fairly long long names in our application. The function: HTREEITEM GetItemByName( HWND hWnd, HTREEITEM hItem, LPCTSTR szItemName ) { try { // If hItem is NULL, start search...