{"id":1270,"date":"2012-04-06T15:45:55","date_gmt":"2012-04-06T13:45:55","guid":{"rendered":"http:\/\/mariusbancila.ro\/blog\/?p=1270"},"modified":"2012-04-06T15:45:55","modified_gmt":"2012-04-06T13:45:55","slug":"sorting-a-ctreectrl","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/","title":{"rendered":"Sorting a CTreeCtrl"},"content":{"rendered":"<p>The <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/8bkz91b4.aspx\">CTreeCtrl<\/a> supports several ways to sort its content:<\/p>\n<ul>\n<li><a href=\"msdn.microsoft.com\/en-us\/library\/ettyybhw.aspx\">InsertItem<\/a> allows to insert the child item alphabetically, when specifying TVI_SORT for <tt>hInsertAfter<\/tt><\/li>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dt51k7hx.aspx\">SortChildren<\/a> performs an alphabetical sorting of the child items of the given parent item in a tree<\/li>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/8b8aytc5.aspx\">SortChildrenCB<\/a> performs a sort with a user-defined callback (hence the CB suffix) of the children of the specified item<\/li>\n<\/ul>\n<p>Let&#8217;s consider this tree and investigate these two sorting methods.<br \/>\n<img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"\/blog\/wp-content\/uploads\/2012\/04\/sorttree1.png\" title=\"Unsorted tree\" class=\"alignnone\" width=\"444\" height=\"353\" \/><\/p>\n<p><strong>Alphabetical sorting<\/strong><br \/>\nSortChildren() does an alphabetical sorting. It is important to note that SortChildren() does not work recursively. It only sorts the children of the specified item. Therefore the following call would only sort the immediate children of the root item.<\/p>\n<pre name=\"code\" class=\"cpp\">\r\n  m_tree.SortChildren(TVI_ROOT);\r\n<\/pre>\n<p>To sort the entire tree one needs to traverse the tree and call SortChildren for every item that has children (actually only items with more than one child need sorting). The following method performs a depth-first traversal and sorts all nodes that have children.<\/p>\n<pre name=\"code\" class=\"cpp\">\r\nvoid CTreeSortDemoDlg::SortItem(HTREEITEM item)\r\n{\r\n   if(item != NULL)\r\n   {\r\n      if(item == TVI_ROOT || m_tree.ItemHasChildren(item))\r\n      {\r\n         HTREEITEM child = m_tree.GetChildItem(item);\r\n\r\n         while(child != NULL)\r\n         {\r\n            SortItem(child);\r\n            child = m_tree.GetNextItem(child, TVGN_NEXT);\r\n         }\r\n\r\n         m_tree.SortChildren(item);\r\n      }\r\n   }\r\n}\r\n\r\n\/\/ ...\r\nSortItem(TVI_ROOT);\r\n<\/pre>\n<p>The result for the given tree is<br \/>\n<img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"\/blog\/wp-content\/uploads\/2012\/04\/sorttree2.png\" title=\"Alphabetically sorted tree\" class=\"alignnone\" width=\"444\" height=\"353\" \/><\/p>\n<p><strong>User defined sorting<\/strong><br \/>\nSortChildrenCB() allows the user to set a callback functions that the framework calls each time it needs to compare two items to perform the sorting. This allows to customize the sorting. Just like SortChildren() this method only sorts the children of the specified item, and does not perform a recursive sorting of the entire sub-tree.<\/p>\n<p>This method has a single argument, a pointer to a <a href=\"msdn.microsoft.com\/en-us\/library\/bb773462.aspx\">TVSORTCB<\/a> structure, that is defined like this:<\/p>\n<pre name=\"code\" class=\"cpp\">\r\ntypedef struct tagTVSORTCB {\r\n  HTREEITEM    hParent;\r\n  PFNTVCOMPARE lpfnCompare;\r\n  LPARAM       lParam;\r\n} TVSORTCB, *LPTVSORTCB;\r\n<\/pre>\n<p>The fields have the following meaning:<\/p>\n<ul>\n<li>hParent: is the item whose children are to be sorted<\/li>\n<li>lpfnCompare: a pointer to the user-defined callback function that does the sorting<\/li>\n<li>lParam: is the value that is passed as to the 3rd parameter of the callback function, which looks like this:\n<pre name=\"code\" class=\"cpp\">\r\nint CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);\r\n<\/pre>\n<p>Usually, this parameter is a pointer to the tree itself, so that you can retrieve information about the items in the callback if necessary. However, it can be anything, including NULL.<\/p>\n<p>The lParam1 and lParam2 parameters correspond to the lParam member of the TVITEM structure for the two items being compared.<\/p>\n<p>The callback function must return a negative value if the first item should precede the second, a positive value if the first item should follow the second, or zero if the two items are equivalent.\n<\/li>\n<\/ul>\n<p>Suppose we set for each item a pointer to a structure that looks like this:<\/p>\n<pre name=\"code\" class=\"cpp\">\r\nstruct ItemData\r\n{\r\n   CString  Name;\r\n   int      Value;\r\n\r\n   CString ToString() const\r\n   {\r\n      CString str;\r\n      str.Format(_T(\"%s = %d\"), Name, Value);\r\n      return str;\r\n   }\r\n};\r\n\r\nItemData* data = MakeData(base, prefix);\r\nHTREEITEM item = m_tree.InsertItem(data->ToString(), parent);\r\nm_tree.SetItemData(item, (DWORD_PTR)data);\r\n<\/pre>\n<p>A user defined callback (a class method declared static) defines the precedence between two items based on the Value field.<\/p>\n<pre name=\"code\" class=\"cpp\">\r\nint CALLBACK CTreeSortDemoDlg::CustomCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)\r\n{\r\n   ItemData* data1 = reinterpret_cast&lt;ItemData*&gt;(lParam1);\r\n   ItemData* data2 = reinterpret_cast&lt;ItemData*&gt;(lParam2);\r\n\r\n   return (data1 != NULL &amp;&amp; data2 != NULL) ? (data1->Value > data2->Value) : 0;\r\n}\r\n<\/pre>\n<p>Sorting the entire tree with this callback is similar with the previous recursive method. The call to SortChildren() is replaced with a call to SortChildrenCB().<\/p>\n<pre name=\"code\" class=\"cpp\">\r\nvoid CTreeSortDemoDlg::CustomSortItem(HTREEITEM item)\r\n{\r\n   if(item != NULL)\r\n   {\r\n      if(item == TVI_ROOT || m_tree.ItemHasChildren(item))\r\n      {\r\n         HTREEITEM child = m_tree.GetChildItem(item);\r\n\r\n         while(child != NULL)\r\n         {\r\n            CustomSortItem(child);\r\n            child = m_tree.GetNextItem(child, TVGN_NEXT);\r\n         }\r\n\r\n         TVSORTCB tvs;\r\n         tvs.hParent = item;\r\n         tvs.lpfnCompare = &amp;CTreeSortDemoDlg::CustomCompare;\r\n         tvs.lParam = reinterpret_cast&lt;LPARAM&gt;(&amp;m_tree);\r\n\r\n         m_tree.SortChildrenCB(&amp;tvs);\r\n      }\r\n   }\r\n}\r\n\r\n\/\/ ...\r\nCustomSortItem(TVI_ROOT);\r\n<\/pre>\n<p>The result on the given example is:<br \/>\n<img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"\/blog\/wp-content\/uploads\/2012\/04\/sorttree3.png\" title=\"Custom-defined sorted tree\" class=\"alignnone\" width=\"444\" height=\"353\" \/><\/p>\n<p>For a full sample see <div class=\"wp-block-button\">\n<a  data-e-Disable-Page-Transition=\"true\" class=\"dlm-download-link dlm-download-default wp-block-button__link wp-element-button\" title=\"Version 1.0\" href=\"https:\/\/mariusbancila.ro\/blog\/download\/3495\/?tmstv=1792703062\" rel=\"nofollow\" id=\"download-link-3495\" data-redirect=\"false\" >\n\tTreeSortDemo\t(<span class=\"dlm-download-count-value\">7515 downloads<\/span>\n\t)\n<\/a>\n<\/div>\n.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The CTreeCtrl supports several ways to sort its content: InsertItem allows to insert the child item alphabetically, when specifying TVI_SORT for hInsertAfter SortChildren performs an alphabetical sorting of the child items of the given parent item in a tree SortChildrenCB performs a sort with a user-defined callback (hence the CB suffix) of the children of &#8230; <a title=\"Sorting a CTreeCtrl\" class=\"read-more\" href=\"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/\" aria-label=\"Read more about Sorting a CTreeCtrl\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[7,12],"tags":[451,314,453,315,62],"class_list":["post-1270","post","type-post","status-publish","format-standard","hentry","category-c","category-mfc","tag-c","tag-ctreectrl","tag-mfc","tag-sort","tag-tree"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.3 - aioseo.com -->\n\t<meta name=\"description\" content=\"Learn how to sort a CTreeCtrl with SortChildren and SortChildrenCB.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marius Bancila\"\/>\n\t<meta name=\"keywords\" content=\"c++,mfc,tree,ctreectrl,sort\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.3\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Marius Bancila&#039;s Blog | About code. Mostly on C++\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Sorting a CTreeCtrl\" \/>\n\t\t<meta property=\"og:description\" content=\"Learn how to sort a CTreeCtrl with SortChildren and SortChildrenCB.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2012-04-06T13:45:55+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2012-04-06T13:45:55+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Sorting a CTreeCtrl\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Learn how to sort a CTreeCtrl with SortChildren and SortChildrenCB.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2012\\\/04\\\/06\\\/sorting-a-ctreectrl\\\/#article\",\"name\":\"Sorting a CTreeCtrl\",\"headline\":\"Sorting a CTreeCtrl\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"\\\/blog\\\/wp-content\\\/uploads\\\/2012\\\/04\\\/sorttree1.png\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2012\\\/04\\\/06\\\/sorting-a-ctreectrl\\\/#articleImage\"},\"datePublished\":\"2012-04-06T15:45:55+02:00\",\"dateModified\":\"2012-04-06T15:45:55+02:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2012\\\/04\\\/06\\\/sorting-a-ctreectrl\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2012\\\/04\\\/06\\\/sorting-a-ctreectrl\\\/#webpage\"},\"articleSection\":\"C++, MFC, C++, CTreeCtrl, MFC, sort, tree\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2012\\\/04\\\/06\\\/sorting-a-ctreectrl\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"position\":2,\"name\":\"IT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"position\":3,\"name\":\"Software\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"position\":4,\"name\":\"C++\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/mfc\\\/#listItem\",\"name\":\"MFC\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/mfc\\\/#listItem\",\"position\":5,\"name\":\"MFC\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/mfc\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2012\\\/04\\\/06\\\/sorting-a-ctreectrl\\\/#listItem\",\"name\":\"Sorting a CTreeCtrl\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2012\\\/04\\\/06\\\/sorting-a-ctreectrl\\\/#listItem\",\"position\":6,\"name\":\"Sorting a CTreeCtrl\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/mfc\\\/#listItem\",\"name\":\"MFC\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Marius Bancila\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2012\\\/04\\\/06\\\/sorting-a-ctreectrl\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marius Bancila\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2012\\\/04\\\/06\\\/sorting-a-ctreectrl\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2012\\\/04\\\/06\\\/sorting-a-ctreectrl\\\/\",\"name\":\"Sorting a CTreeCtrl\",\"description\":\"Learn how to sort a CTreeCtrl with SortChildren and SortChildrenCB.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2012\\\/04\\\/06\\\/sorting-a-ctreectrl\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2012-04-06T15:45:55+02:00\",\"dateModified\":\"2012-04-06T15:45:55+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Sorting a CTreeCtrl","description":"Learn how to sort a CTreeCtrl with SortChildren and SortChildrenCB.","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/","robots":"max-image-preview:large","keywords":"c++,mfc,tree,ctreectrl,sort","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/#article","name":"Sorting a CTreeCtrl","headline":"Sorting a CTreeCtrl","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"image":{"@type":"ImageObject","url":"\/blog\/wp-content\/uploads\/2012\/04\/sorttree1.png","@id":"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/#articleImage"},"datePublished":"2012-04-06T15:45:55+02:00","dateModified":"2012-04-06T15:45:55+02:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/#webpage"},"articleSection":"C++, MFC, C++, CTreeCtrl, MFC, sort, tree"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/mariusbancila.ro\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","position":2,"name":"IT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","position":3,"name":"Software","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","position":4,"name":"C++","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/mfc\/#listItem","name":"MFC"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/mfc\/#listItem","position":5,"name":"MFC","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/mfc\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/#listItem","name":"Sorting a CTreeCtrl"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/#listItem","position":6,"name":"Sorting a CTreeCtrl","previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/mfc\/#listItem","name":"MFC"}}]},{"@type":"Organization","@id":"https:\/\/mariusbancila.ro\/blog\/#organization","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","url":"https:\/\/mariusbancila.ro\/blog\/"},{"@type":"Person","@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author","url":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/","name":"Marius Bancila","image":{"@type":"ImageObject","@id":"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marius Bancila"}},{"@type":"WebPage","@id":"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/","name":"Sorting a CTreeCtrl","description":"Learn how to sort a CTreeCtrl with SortChildren and SortChildrenCB.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2012-04-06T15:45:55+02:00","dateModified":"2012-04-06T15:45:55+02:00"},{"@type":"WebSite","@id":"https:\/\/mariusbancila.ro\/blog\/#website","url":"https:\/\/mariusbancila.ro\/blog\/","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","inLanguage":"en-US","publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Marius Bancila's Blog | About code. Mostly on C++","og:type":"article","og:title":"Sorting a CTreeCtrl","og:description":"Learn how to sort a CTreeCtrl with SortChildren and SortChildrenCB.","og:url":"https:\/\/mariusbancila.ro\/blog\/2012\/04\/06\/sorting-a-ctreectrl\/","article:published_time":"2012-04-06T13:45:55+00:00","article:modified_time":"2012-04-06T13:45:55+00:00","twitter:card":"summary","twitter:title":"Sorting a CTreeCtrl","twitter:description":"Learn how to sort a CTreeCtrl with SortChildren and SortChildrenCB."},"aioseo_meta_data":{"post_id":"1270","title":"Sorting a CTreeCtrl","description":"Learn how to sort a CTreeCtrl with SortChildren and SortChildrenCB.","keywords":[{"label":"C++","value":"C++"},{"label":"MFC","value":"MFC"},{"label":"tree","value":"tree"},{"label":"CTreeCtrl","value":"CTreeCtrl"},{"label":"sort","value":"sort"}],"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-03-18 21:13:02","updated":"2025-12-12 07:37:23","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"author_meta":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"featured_img":null,"jetpack_publicize_connections":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"The CTreeCtrl supports several ways to sort its content: InsertItem allows to insert the child item alphabetically, when specifying TVI_SORT for hInsertAfter SortChildren performs an alphabetical sorting of the child items of the given parent item in a tree SortChildrenCB performs a sort with a user-defined callback (hence the CB suffix) of the children of&hellip;","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/mfc\/\" class=\"advgb-post-tax-term\">MFC<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">MFC<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/mfc\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/mfc\/\" class=\"advgb-post-tax-term\">CTreeCtrl<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/mfc\/\" class=\"advgb-post-tax-term\">MFC<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/mfc\/\" class=\"advgb-post-tax-term\">sort<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/mfc\/\" class=\"advgb-post-tax-term\">tree<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">CTreeCtrl<\/span>","<span class=\"advgb-post-tax-term\">MFC<\/span>","<span class=\"advgb-post-tax-term\">sort<\/span>","<span class=\"advgb-post-tax-term\">tree<\/span>"]}},"comment_count":"0","relative_dates":{"created":"Posted 15 years ago","modified":"Updated 15 years ago"},"absolute_dates":{"created":"Posted on April 6, 2012","modified":"Updated on April 6, 2012"},"absolute_dates_time":{"created":"Posted on April 6, 2012 3:45 pm","modified":"Updated on April 6, 2012 3:45 pm"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-ku","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/1270","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/comments?post=1270"}],"version-history":[{"count":11,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/1270\/revisions"}],"predecessor-version":[{"id":1281,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/1270\/revisions\/1281"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=1270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=1270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=1270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}