{"id":19,"date":"2016-07-18T23:33:01","date_gmt":"2016-07-18T15:33:01","guid":{"rendered":"http:\/\/kogasa.moe\/?p=19"},"modified":"2025-05-25T01:44:34","modified_gmt":"2025-05-24T17:44:34","slug":"%e8%99%9a%e6%8b%9f%e5%88%97%e8%a1%a8%e7%9a%84%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/flandre-scarlet.moe\/blog\/19\/","title":{"rendered":"\u865a\u62df\u5217\u8868\u7684\u4f7f\u7528"},"content":{"rendered":"<p>ListView\u63a7\u4ef6\u5728\u6dfb\u52a0\u5927\u91cf\u6570\u636e\u65f6\u901f\u5ea6\u5f88\u6162\u800c\u4e14\u4f1a\u9891\u7e41\u5237\u65b0\u4ee5\u81f3\u4e8e\u7a97\u53e3\u4e0d\u65ad\u95ea\u70c1\uff0c\u603b\u4e4b\u662f\u6ca1\u6cd5\u7528\u5566\uff0c\u8fd9\u79cd\u60c5\u51b5\u628a\u63a7\u4ef6\u6539\u6210\u865a\u62df\u5217\u8868\u7684\u5f62\u5f0f\u5c31\u80fd\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<p>\u865a\u62df\u5217\u8868\u4e0d\u5728\u63a7\u4ef6\u4e2d\u5b58\u50a8\u6570\u636e\uff0c\u800c\u662f\u5411\u5916\u90e8\u201c\u7d22\u8981\u201d\u6570\u636e\uff0c\u5373\u6570\u636e\u662f\u7531\u6211\u4eec\u81ea\u5df1\u7ef4\u62a4\u7684\uff0c\u5b83\u552f\u4e00\u4fdd\u5b58\u7684\u6570\u636e\u662f\u63a7\u4ef6\u4e2d\u9879\u76ee\u7684\u6570\u91cf\u3002\u865a\u62df\u5217\u8868\u901a\u8fc7\u00a0LVN_GETDISPINFO\u3001LVN_ODFINDITEM\u548cLVN_ODCACHEHINT\u8fd9\u4e09\u4e2a\u6d88\u606f\u4e0e\u5916\u754c\u4ea4\u4e92\u3002<\/p>\n<h1>\u521b\u5efa\u865a\u62df\u5217\u8868\u63a7\u4ef6<\/h1>\n<p>\u4f7f\u7528CreateWindows(Ex)\u521b\u5efa\u63a7\u4ef6\u65f6\u52a0\u4e0a LVS_OWNERDATA \u6837\u5f0f\uff0c\u8fd9\u6837\u521b\u5efa\u7684\u5c31\u662f\u4e00\u4e2a\u865a\u62df\u5217\u8868\u4e86\u3002\u6ce8\u610f\uff0c\u865a\u62df\u5217\u8868\u6837\u5f0f\u53ea\u80fd\u5728\u521b\u5efa\u65f6\u6307\u5b9a\u800c\u65e0\u6cd5\u5728\u521b\u5efa\u540e\u6dfb\u52a0\u6216\u79fb\u9664\u3002<br \/>\n<!--more--><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">hList = CreateWindowEx(0, WC_LISTVIEW, NULL,\r\n    LVS_REPORT | WS_CHILD | WS_VISIBLE | WS_BORDER | LVS_ALIGNTOP | LVS_OWNERDATA,\r\n    0, 0, CW_USEDEFAULT, CW_USEDEFAULT,\r\n    hDlg, (HMENU)ID_LISTVIEW, (HINSTANCE)GetWindowLong(hDlg, GWL_HINSTANCE), NULL);<\/pre>\n<h1>\u5411\u865a\u62df\u5217\u8868\u6dfb\u52a0\u6570\u636e<\/h1>\n<p>\u4f7f\u7528\u7684\u65f6\u5019\u5148\u51c6\u5907\u597d\u8868\u4e2d\u7684\u6570\u636e\uff0c\u540c\u65f6\u8bbe\u7f6e\u597d\u8868\u9879\u7684\u6570\u91cf\uff08 \u4f7f\u7528<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb775095(v=vs.85).aspx\" target=\"_blank\" rel=\"noopener\">ListView_SetItemCountEx<\/a>\u6216\u76f4\u63a5\u53d1<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb761188(v=vs.85).aspx\" target=\"_blank\" rel=\"noopener\">LVM_SETITEMCOUNT<\/a>\u6d88\u606f\u7ed9\u63a7\u4ef6\uff09\uff0c\u8fd9\u6837\u5c31\u5b8c\u6210\u6570\u636e\u7684\u6dfb\u52a0\u4e86\u3002<\/p>\n<h1>\u5904\u7406\u63a7\u4ef6\u7684\u901a\u77e5\u6d88\u606f<\/h1>\n<h1>\u00b7LVN_GETDISPINFO<\/h1>\n<p>ListView\u63a7\u4ef6\u663e\u793a\u4fe1\u606f\u65f6\u5411\u7236\u7a97\u53e3\u53d1\u9001<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb774818(v=vs.85).aspx\" target=\"_blank\" rel=\"noopener\">LVN_GETDISPINFO<\/a>\u6d88\u606f\u6765\u83b7\u53d6\u6570\u636e\u3002\u56e0\u6b64\u7236\u7a97\u53e3\u8981\u5904\u7406 WM_NOTIFY \u6d88\u606f\u3002\u800c\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u6211\u4eec\u53ea\u8981\u5904\u7406\u4e86\u8fd9\u4e2a\u6d88\u606f\u5c31\u53ef\u4ee5\u4eab\u53d7\u5230\u865a\u62df\u5217\u8868\u7684\u9ad8\u901f\u663e\u793a\u4e86\uff0c\u5269\u4e0b\u4e24\u4e2a\u4e0d\u7528\u7ba1(&#8216;\u2200`)<br \/>\nLVN_GETDISPINFO\u6d88\u606f\u7684\u5904\u7406\u5dee\u4e0d\u591a\u662f\u8fd9\u4e2a\u6837\u5b50\uff1a<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\ncase WM_NOTIFY:\r\n    if (((NMHDR*)lParam)-&gt;idFrom == ID_LISTVIEW)\r\n    {\r\n        switch (((NMHDR*)lParam)-&gt;code)\r\n        {\r\n            case LVN_GETDISPINFO:\r\n            {\r\n                NMLVDISPINFO *pdi = reinterpret_cast&lt;NMLVDISPINFO*&gt;(lParam);\r\n                LVITEMW *pItem = &amp;pdi-&gt;item;\r\n                \r\n                \/\/ \u8981\u83b7\u53d6\u7b2c\u51e0\u884c\u7684\u6570\u636e\r\n                int itemid = pItem-&gt;iItem;\r\n                \r\n                \/\/ \u4ece\u5916\u90e8\u4f20\u9012\u6570\u636e\r\n                Information *pi = g_Data&#x5B;itemid];\r\n                if (pItem-&gt;mask &amp; LVIF_TEXT)\r\n                {\r\n                    switch (pItem-&gt;iSubItem)\r\n                    {\r\n                    case 0: \/\/ \u83b7\u53d6\u7b2c\u4e00\u5217\u7684\u6570\u636e\r\n                        wcscpy_s(pItem-&gt;pszText,\r\n                            pItem-&gt;cchTextMax,\r\n                            pi-&gt;firstcolumn\r\n                            );\r\n                        break;\r\n\r\n                    case 1:\r\n                        wcscpy_s(pItem-&gt;pszText,\r\n                            pItem-&gt;cchTextMax,\r\n                            pi-&gt;secondcolumn\r\n                            );\r\n                        break;\r\n                    \/\/ ...\r\n                    }\r\n                }\r\n                break;\r\n            }\r\n            \/\/ ...\r\n        }\r\n    }\r\n<\/pre>\n<h1>\u00b7LVN_ODFINDITEM<\/h1>\n<p>LVN_ODFINDITEM\u6d88\u606f\u7528\u4e8e\u5904\u7406\u67e5\u627e\u7279\u5b9a\u7684\u9879\uff0c\u5c31\u50cf\u6211\u4eec\u5728\u8d44\u6e90\u7ba1\u7406\u5668\u4e2d\u8f93\u5165exp\u6765\u641c\u7d22exp\u5f00\u5934\u7684\u6587\u4ef6\uff08\u5939\uff09\u4e00\u6837\uff0c\u8fd9\u4e2a\u6d88\u606f\u5c31\u662f\u7528\u4e8e\u652f\u6301\u8fd9\u9879\u529f\u80fd\u7684\u3002\u5f53\u63a7\u4ef6\u63a5\u53d7\u5230\u952e\u76d8\u6309\u952e\u6d88\u606f\u6216LVM_FINDITEM\u6d88\u606f\u65f6\u4f1a\u5411\u7236\u63a7\u4ef6\u53d1\u9001\u6b64\u6d88\u606f\u3002\u6b64\u65f6\u7684 lParam \u6307\u5411\u4e00\u4e2a<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb774784(v=vs.85).aspx\" target=\"_blank\" rel=\"noopener\">NMLVFINDITEM<\/a>\u7ed3\u6784\u3002NMLVFINDITEM\u5305\u542b\u4e00\u4e2a<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb774745(v=vs.85).aspx\" target=\"_blank\" rel=\"noopener\">LVFINDINFO<\/a>\u7ed3\u6784\u7684\u6210\u5458\u53d8\u91cf\u3002<br \/>\nNMLVFINDITEM\u4e2d\u7684iStart\u6307\u793a\u641c\u7d22\u7684\u5f00\u59cb\u4f4d\u7f6e\uff08\u4ece0\u5f00\u59cb\uff09\uff0cLVFINDINFO\u4e2d\u7684psz\u5219\u50a8\u5b58\u4e86\u8981\u641c\u7d22\u7684\u5b57\u7b26\u4e32\uff08\u540c\u65f6flags\u6210\u5458\u4e2d\u5e94\u5305\u542bLVFI_STRING\uff09\uff0c\u6709\u4e86\u8fd9\u4e9b\u6d88\u606f\u5c31\u53ef\u4ee5\u81ea\u5df1\u641c\u7d22\u5339\u914d\u7684\u9879\u4e86\uff0c\u7136\u540e\u627e\u5230\u4e86\u5219\u8fd4\u56de\u9879\u7684\u504f\u79fb\uff0c\u627e\u4e0d\u5230\u8fd4\u56de-1\u3002<\/p>\n<h1>\u00b7LVN_ODCACHEHINT<\/h1>\n<p>\u6700\u540e\u4e00\u4e2a\u5904\u7406\u7f13\u5b58\u7684\u6d88\u606f\u3002\u5c06\u7ecf\u5e38\u4f1a\u88ab\u663e\u793a\u7684\u9879\u7f13\u5b58\u8d77\u6765\u4ee5\u63d0\u9ad8\u663e\u793a\u6548\u7387\u3002\u6b64\u65f6lParam\u6307\u5411<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb774775(v=vs.85).aspx\" target=\"_blank\" rel=\"noopener\">NMLVCACHEHINT<\/a>\u7ed3\u6784\u3002\u8fd9\u4e2a\u7ed3\u6784\u4e2d\u7684iFrom\u548ciTo\u6307\u793a\u4e86\u663e\u793a\u8303\u56f4\u3002<br \/>\n\u5f53ListView\u7684\u663e\u793a\u6539\u53d8\uff08\u6bd4\u5982\u6eda\u52a8\u9f20\u6807\u6eda\u8f6e\uff09\u65f6\u5c06\u4f1a\u53d1\u9001\u6b64\u6d88\u606f\uff0c\u6b64\u65f6\u5e94\u7528\u7a0b\u5e8f\u4fbf\u53ef\u4ee5\u51b3\u5b9a\u662f\u5426\u7f13\u5b58\u76ee\u6807\u8303\u56f4\u5185\u7684\u6570\u636e\uff0c\u7136\u540e\u7b49\u5f85LVN_GETDISPINFO\u6d88\u606f\u7684\u5230\u6765\u3002<br \/>\n\u6bd4\u5982\u628a\u5927\u91cf\u6570\u636e\u5b58\u5728\u786c\u76d8\uff0c\u7136\u540e\u7f13\u5b58\u4e00\u90e8\u5206\u5230\u5185\u5b58\u91cc\uff0c\u6536\u5230\u6d88\u606f\u65f6\u4fbf\u53ef\u5f02\u6b65\u8bfb\u53d6\u6570\u636e\u5230\u5185\u5b58\uff0c\u7136\u540e\u5728LVN_GETDISPINFO\u4e2d\u63d0\u4ea4\u7ed9\u63a7\u4ef6\u663e\u793a(&#8216;\u2200`)\u3002<br \/>\n\u8fd9\u4e2a\u6d88\u606f\u5fc5\u987b\u8fd4\u56de0\u3002<\/p>\n<h1>\u590d\u9009\u6846(checkbox)\u7684\u5904\u7406<\/h1>\n<p>Checkbox\u8fd8\u662f\u4e2a\u633a\u6709\u7528\u7684\u4e1c\u897f\u3002<\/p>\n<p>\u9996\u5148\u521b\u5efa\u63a7\u4ef6\u65f6\u8bbe\u7f6e\u6269\u5c55\u98ce\u683cLVS_EX_CHECKBOXES\uff0c\u8fd9\u4e2a\u4e0d\u7ba1\u662f\u4e0d\u662f\u865a\u62df\u5217\u8868\u90fd\u8981\u5904\u7406\u7684\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nListView_SetExtendedListViewStyleEx(\r\n    hList, 0, LVS_EX_GRIDLINES | LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT);\r\n<\/pre>\n<p>\u975e\u865a\u62df\u5217\u8868\u7684\u8bdd\u5c31\u4e0d\u7528\u5904\u7406\u5176\u4ed6\u7684\u76f4\u63a5\u80fd\u770b\u5230\u6548\u679c\u4e86\u3002\u56e0\u4e3a\u865a\u62df\u5217\u8868\u4e0d\u5b58\u50a8\u6761\u76ee\u6570\u91cf\u4ee5\u5916\u7684\u6570\u636e\uff0c\u6240\u4ee5\u6211\u4eec\u8fd8\u5f97\u7ee7\u7eed\u505a\u70b9\u5904\u7406\u3002\u4e00\u4e2a\u662f\u8981\u7ef4\u62a4\u4e00\u4e2a\u5217\u8868\u4e2d\u9879\u76ee\u7684\u9009\u4e2d\u72b6\u6001\uff0c\u7136\u540e\u5c31\u662f\u5f53\u6709\u9009\u4e2d\u72b6\u6001\u53d8\u6362\u65f6\u53ca\u65f6\u5237\u65b0\u5230\u754c\u9762\u4e0a\u3002\u6bd4\u5982\u4f7f\u7528\u7a7a\u683c\u952e\u5207\u6362checkbox\u7684\u9009\u4e2d\u72b6\u6001\uff1a<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\ncase WM_NOTIFY:\r\n    if (((NMHDR*)lParam)-&gt;idFrom == ID_LISTVIEW)\r\n    {\r\n        switch (((NMHDR*)lParam)-&gt;code)\r\n        {\r\n        case VK_SPACE:\r\n            iClickItem = ListView_GetSelectionMark(hList);\r\n            g_Data&#x5B;iClickItem].checkstate ^= 0x3;\r\n            SendMessage(hList, LVM_REDRAWITEMS, iClickItem, iClickItem);\r\n            break;\r\n        }\r\n    }\r\n<\/pre>\n<p>\u5176\u4e2d checkstate==1 \u65f6\u4ee3\u8868\u672a\u9009\u4e2d\uff0c2\u4ee3\u8868\u9009\u4e2d\u3002\u66f4\u65b0\u4e86\u9009\u4e2d\u72b6\u6001\u540e\u53d1\u9001<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb761145(v=vs.85).aspx\" target=\"_blank\" rel=\"noopener\">LVM_REDRAWITEMS<\/a>\u6d88\u606f\u5237\u65b0\u663e\u793a\u3002\u56e0\u4e3a\u662f\u865a\u62df\u5217\u8868\uff0c\u91cd\u5237\u5f53\u7136\u8fd8\u662f\u5728LVN_GETDISPINFO\u91cc\u5904\u7406\u3002<br \/>\n\u56e0\u6b64\u5904\u7406checkbox\u65f6\u8fd8\u8981\u5728LVN_GETDISPINFO\u4e2d\u8bbe\u7f6e\u4ee5\u4e0b\u5b57\u6bb5\u7684\u503c\uff1a<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\ncase LVN_GETDISPINFO:\r\n{\r\n    NMLVDISPINFO *pdi = reinterpret_cast&lt;NMLVDISPINFO*&gt;(lParam);\r\n    LVITEMW *pItem = &amp;pdi-&gt;item;                \r\n    int itemid = pItem-&gt;iItem;\r\n    pdi-&gt;item.state = INDEXTOSTATEIMAGEMASK(g_Data&#x5B;itemid].checkstate);\r\n    pdi-&gt;item.stateMask = LVIS_STATEIMAGEMASK;\r\n\r\n    \/\/ \u5904\u7406item\u5185\u5bb9\r\n}\r\n<\/pre>\n<p>state\u5b57\u6bb5\u768412~15\u4f4d\u8868\u793aitem\u7684\u72b6\u6001\u56fe\u7247\uff0c\u5373checkbox\u7684\u56fe\u7247\uff0c0\u4ee3\u8868\u4e0d\u663e\u793a\u3002\u53ef\u7528\u5b8fINDEXTOSTATEIMAGEMASK(sta)\u8bbe\u7f6e\u72b6\u6001\uff0c\u8fd9\u4e2a\u5b8f\u5c31\u662f\u5c06sta\u5de6\u79fb12\u4f4d<br \/>\n\u540c\u65f6\u8fd8\u8981\u8bbe\u7f6estateMask\uff0c\u4f7fstate\u4e2d\u7684\u8bbe\u7f6e\u751f\u6548\uff0c\u72b6\u6001\u56fe\u7247\u5bf9\u5e94\u7684\u662fLVIS_STATEIMAGEMASK\u3002\u8fd9\u6837\u5c31\u80fd\u5c06checkbox\u7684\u72b6\u6001\u5237\u65b0\u4e0a\u53bb\u4e86\u3002\u5176\u4ed6\u7684\u5c5e\u6027\u53c2\u8003<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb774760(v=vs.85).aspx\" target=\"_blank\" rel=\"noopener\">LVITEM<\/a>\u3002<\/p>\n<p>\u66f4\u591a\u5185\u5bb9\u8bf7\u53c2\u8003<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb774735(v=vs.85).aspx#Virtual_ListView_Style\" target=\"_blank\" rel=\"noopener\">Virtual List-View Style<\/a>\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ListView\u63a7\u4ef6\u5728\u6dfb\u52a0\u5927\u91cf\u6570\u636e\u65f6\u901f\u5ea6\u5f88\u6162\u800c\u4e14\u4f1a\u9891\u7e41\u5237\u65b0\u4ee5\u81f3\u4e8e\u7a97\u53e3\u4e0d\u65ad\u95ea\u70c1\uff0c\u603b\u4e4b\u662f\u6ca1\u6cd5\u7528\u5566\uff0c\u8fd9\u79cd\u60c5\u51b5\u628a\u63a7\u4ef6\u6539&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/flandre-scarlet.moe\/blog\/19\/\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85],"tags":[],"class_list":["post-19","post","type-post","status-publish","format-standard","hentry","category-programs"],"_links":{"self":[{"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/posts\/19","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/comments?post=19"}],"version-history":[{"count":1,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/posts\/19\/revisions"}],"predecessor-version":[{"id":2177,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/posts\/19\/revisions\/2177"}],"wp:attachment":[{"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/media?parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/categories?post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/tags?post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}