{"id":28733,"date":"2006-12-13T10:00:00","date_gmt":"2006-12-13T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2006\/12\/13\/displaying-infotips-for-folded-and-unfolded-listview-items\/"},"modified":"2006-12-13T10:00:00","modified_gmt":"2006-12-13T10:00:00","slug":"displaying-infotips-for-folded-and-unfolded-listview-items","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20061213-00\/?p=28733","title":{"rendered":"Displaying infotips for folded and unfolded listview items"},"content":{"rendered":"<p>\nWhen displaying infotips for listview items,\nyou have to deal with both the folded and unfolded case.\n&#8220;Folded&#8221; is the term used to describe a listview item\nin large icon mode whose text has been truncated due to length.\nWhen the user selects the item, the full text is revealed,\na process known as &#8220;unfolding&#8221;.\n<\/p>\n<p>\nTake our\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2003\/07\/23\/54576.aspx\">\nscratch program<\/a>\nand make the following changes:\n<\/p>\n<pre>\n<font COLOR=\"blue\">#include &lt;strsafe.h&gt;<\/font>\nBOOL\nOnCreate(HWND hwnd, LPCREATESTRUCT lpcs)\n{\n  <font COLOR=\"blue\">g_hwndChild = CreateWindow(WC_LISTVIEW, NULL,\n                             WS_CHILD | WS_VISIBLE | LVS_ICON,\n                             0, 0, 0, 0,\n                             hwnd, (HMENU)1, g_hinst, 0);\n  if (!g_hwndChild) return FALSE;\n  ListView_SetExtendedListViewStyleEx(g_hwndChild,\n                             LVS_EX_INFOTIP,\n                             LVS_EX_INFOTIP);\n  LVITEM item;\n  item.iItem = 0; \/\/ added 9pm\n  item.iSubItem = 0;\n  item.mask = LVIF_TEXT;\n  item.pszText = TEXT(\"Item with a long name that will be truncated\");\n  if (ListView_InsertItem(g_hwndChild, &amp;item) &lt; 0)\n    return FALSE;<\/font>\n  return TRUE;\n}\n<font COLOR=\"blue\">void OnGetInfoTip(HWND hwnd, NMLVGETINFOTIP *pit)\n{\n if (!pit-&gt;cchTextMax) return;\n if (pit-&gt;dwFlags &amp; LVGIT_UNFOLDED) {\n  pit-&gt;pszText[0] = TEXT('\\0');\n } else {\n  StringCchCat(pit-&gt;pszText, pit-&gt;cchTextMax, TEXT(\"\\r\\n\"));\n }\n StringCchCat(pit-&gt;pszText, pit-&gt;cchTextMax, TEXT(\"Here is an infotip\"));\n}\nLRESULT OnNotify(HWND hwnd, int idCtrl, NMHDR *pnm)\n{\n if (idCtrl == 1) {\n  switch (pnm-&gt;code) {\n  case LVN_GETINFOTIP:\n   OnGetInfoTip(hwnd, (NMLVGETINFOTIP*)pnm);\n   break;\n  }\n }\n return 0;\n}\n  HANDLE_MSG(hwnd, WM_NOTIFY, OnNotify);<\/font>\n<\/pre>\n<p>\nWe create our listview, enable infotips, and add a single\nitem with a rather long name.\nWhen you run the program, observe that the item&#8217;s text\nis truncated at two lines if it is not selected,\nbut it expands to full size when you selected it.\n<\/p>\n<p>\nWhen the listview notifies us that it&#8217;s time to display the\ninfotip,\nwe check whether the item is folded or unfolded.\nIf it is unfolded, then we set the buffer to an empty string\nso that our <code>StringCchCat<\/code> at the end will merely\ncopy the infotip text into the buffer.\nOn the other hand, if the item is folded, then we append\na line terminator because we want the infotip to contain\nthe full text of the item, followed by the tip text.\n<\/p>\n<p>\nWhen you run this program, hover over the item both when it\nis folded and unfolded, and observe that the folded infotip\nincludes the name of the item.\nThis is a detail of infotips that is called out in the\ndocumentation but which many programs fail to observe.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When displaying infotips for listview items, you have to deal with both the folded and unfolded case. &#8220;Folded&#8221; is the term used to describe a listview item in large icon mode whose text has been truncated due to length. When the user selects the item, the full text is revealed, a process known as &#8220;unfolding&#8221;. [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-28733","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>When displaying infotips for listview items, you have to deal with both the folded and unfolded case. &#8220;Folded&#8221; is the term used to describe a listview item in large icon mode whose text has been truncated due to length. When the user selects the item, the full text is revealed, a process known as &#8220;unfolding&#8221;. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/28733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=28733"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/28733\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=28733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=28733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=28733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}