{"id":19101,"date":"2025-03-04T21:22:17","date_gmt":"2025-03-04T13:22:17","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=19101"},"modified":"2025-03-11T19:48:33","modified_gmt":"2025-03-11T11:48:33","slug":"mfc%ef%bc%9acombo-box-%e7%bb%84%e5%90%88%e6%a1%86","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=19101","title":{"rendered":"MFC\uff1aCombo Box \u7ec4\u5408\u6846"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title ez-toc-toggle\" style=\"cursor:pointer\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.iyatt.com\/?p=19101\/#%E6%B5%8B%E8%AF%95%E7%8E%AF%E5%A2%83\" >\u6d4b\u8bd5\u73af\u5883<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.iyatt.com\/?p=19101\/#%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B\" >\u4f7f\u7528\u793a\u4f8b<\/a><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E6%B5%8B%E8%AF%95%E7%8E%AF%E5%A2%83\"><\/span>\u6d4b\u8bd5\u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<ul>\n<li>Windows 11 \u4e13\u4e1a\u7248<\/li>\n<li>Visual Studio 2022\uff08ISO C++14\uff09<\/li>\n<li>\u8be6\u7ec6\uff1a<a href=\"https:\/\/blog.iyatt.com\/?p=18843#%E7%8E%AF%E5%A2%83\">https:\/\/blog.iyatt.com\/?p=18843#%E7%8E%AF%E5%A2%83<\/a><\/li>\n<\/ul>\n<h1><span class=\"ez-toc-section\" id=\"%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B\"><\/span>\u4f7f\u7528\u793a\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u521b\u5efa\u4e00\u4e2a\u57fa\u4e8e\u5bf9\u8bdd\u6846\u7684\u65b0\u9879\u76ee comboBoxProject<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1741014138247.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1077px; --smush-placeholder-aspect-ratio: 1077\/711;\" \/><\/p>\n<p>\u5220\u9664\u6240\u6709\u9ed8\u8ba4\u7684\u63a7\u4ef6\uff0c\u6dfb\u52a0\u4e00\u4e2a <strong>Combo Box<\/strong><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1741014310899.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1017px; --smush-placeholder-aspect-ratio: 1017\/552;\" \/><\/p>\n<p>\u5728<strong>Combo Box<\/strong>\u4e0a\u53f3\u952e<strong>\u6dfb\u52a0\u53d8\u91cf<\/strong>\uff0c\u521b\u5efa\u4e00\u4e2a private \u53d8\u91cf comboBoxControl<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1741093262526.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 737px; --smush-placeholder-aspect-ratio: 737\/536;\" \/><\/p>\n<p>\u5728\u9879\u76ee Dlg \u7c7b\u7684 OnInitDialog \u65b9\u6cd5\u4e2d\u6dfb\u52a0\u7528\u4e8e\u521d\u59cb\u5316\u5bf9\u8bdd\u6846\u7684\u4ee3\u7801<\/p>\n<pre><code class=\"language-cpp\">    \/\/ \u6dfb\u52a0\u9879\u76ee\n    this-&gt;comboBoxControl.AddString(L&quot;\u82f9\u679c&quot;);\n    this-&gt;comboBoxControl.AddString(L&quot;\u9999\u8549&quot;);\n\n    \/\/ \u8bbe\u7f6e\u9ed8\u8ba4\u9009\u9879\n    this-&gt;comboBoxControl.SetCurSel(0);\n\n    \/\/ \u5728\u6307\u5b9a\u7d22\u5f15\u4f4d\u7f6e\u63d2\u5165\n    this-&gt;comboBoxControl.InsertString(1, L&quot;\u6a59\u5b50&quot;);\n\n    \/\/ \u5220\u9664\u6307\u5b9a\u7d22\u5f15\u4f4d\u7f6e\u7684\u9009\u9879\n    this-&gt;comboBoxControl.DeleteString(2);\n\n    \/\/ \u83b7\u53d6\u6307\u5b9a\u7d22\u5f15\u7684\u9009\u9879\n    CString itemString;\n    this-&gt;comboBoxControl.GetLBText(1, itemString);\n    MessageBox(itemString);<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1741093997668.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 919px; --smush-placeholder-aspect-ratio: 919\/1101;\" \/><\/p>\n<p>\u8fd0\u884c<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1741094059571.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 151px; --smush-placeholder-aspect-ratio: 151\/156;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1741094090696.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 567px; --smush-placeholder-aspect-ratio: 567\/381;\" \/><\/p>\n<p>\u5c5e\u6027\uff0c\u6dfb\u52a0\u4e00\u4e2a\u4e8b\u4ef6\u56de\u8c03\uff0c\u8fd9\u4e2a\u4e8b\u4ef6\u5728\u9009\u4e2d\u9009\u53d1\u751f\u4fee\u6539\u65f6\u89e6\u53d1<\/p>\n<pre><code class=\"language-cpp\">    \/\/ \u83b7\u53d6\u5f53\u524d\u9009\u9879\u7684\u7d22\u5f15\n    int idx = this-&gt;comboBoxControl.GetCurSel();\n\n    CString currentItemString;\n    this-&gt;comboBoxControl.GetLBText(idx, currentItemString);\n    MessageBox(currentItemString);<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1741094575782.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 955px; --smush-placeholder-aspect-ratio: 955\/1056;\" \/><\/p>\n<p>\u8fd9\u6837\u4fee\u6539\u9009\u4e2d\u9879\u7684\u65f6\u5019\u5c31\u4f1a\u5f39\u51fa\u65b0\u7684\u9009\u4e2d\u9879<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1741094414885.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 561px; --smush-placeholder-aspect-ratio: 561\/382;\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6d4b\u8bd5\u73af\u5883 Windows 11 \u4e13\u4e1a\u7248 Visual Studio 2022\uff08ISO C++14\uff09 \u8be6\u7ec6\uff1aht [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"_lmt_disableupdate":"no","_lmt_disable":"no","footnotes":""},"categories":[1,589,640,611],"tags":[],"class_list":["post-19101","post","type-post","status-publish","format-standard","hentry","category-all","category-c-c","category-mfc","category-windows"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/19101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=19101"}],"version-history":[{"count":7,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/19101\/revisions"}],"predecessor-version":[{"id":19560,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/19101\/revisions\/19560"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}