{"id":19566,"date":"2025-03-14T23:42:10","date_gmt":"2025-03-14T15:42:10","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=19566"},"modified":"2025-03-16T16:25:13","modified_gmt":"2025-03-16T08:25:13","slug":"mfc%ef%bc%9atab-control-%e6%a0%87%e7%ad%be%e6%8e%a7%e4%bb%b6%ef%bc%88%e7%bc%96%e8%be%91%e4%b8%ad%ef%bc%89","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=19566","title":{"rendered":"MFC\uff1aTab Control \u6807\u7b7e\u63a7\u4ef6"},"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=19566\/#%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=19566\/#%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>\u65b0\u5efa\u4e00\u4e2a MFC \u5e94\u7528 tabControlProject\uff0c\u57fa\u4e8e\u5bf9\u8bdd\u6846<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1741965033300.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1288px; --smush-placeholder-aspect-ratio: 1288\/796;\" \/><\/p>\n<p>\u5220\u9664\u9884\u7559\u63a7\u4ef6\uff0c\u62d6\u653e\u4e00\u4e2a Tab Control \u4e0a\u53bb<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1742109095004.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 704px; --smush-placeholder-aspect-ratio: 704\/510;\" \/><\/p>\n<p>\u5728\u63a7\u4ef6\u4e0a\u53f3\u952e\u6dfb\u52a0\u53d8\u91cf<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1741965186538.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 603px; --smush-placeholder-aspect-ratio: 603\/450;\" \/><\/p>\n<p>\u53d8\u91cf\u540d\uff1atabControl<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1741965233546.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>\u63d2\u5165\u4e00\u4e2a\u5bf9\u8bdd\u6846<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1742109203378.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 431px; --smush-placeholder-aspect-ratio: 431\/389;\" \/><\/p>\n<p>\u5c5e\u6027 ID \u8bbe\u4e3a <strong>MAIN_DIALOG<\/strong>\uff0c\u8fb9\u6846\u8bbe\u4e3a<strong>None<\/strong>\uff0c\u6837\u5f0f\u8bbe\u4e3a<strong>Child<\/strong><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1742109240092.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 387px; --smush-placeholder-aspect-ratio: 387\/950;\" \/><\/p>\n<p>\u754c\u9762\u4e0a\u653e\u70b9\u63a7\u4ef6<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1742109323075.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 581px; --smush-placeholder-aspect-ratio: 581\/399;\" \/><\/p>\n<p>\u5728\u5bf9\u8bdd\u6846\u7a7a\u767d\u5904\u53f3\u952e\u6dfb\u52a0\u7c7b MainDialog<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1742111385341.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 496px; --smush-placeholder-aspect-ratio: 496\/577;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1742111452199.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 587px; --smush-placeholder-aspect-ratio: 587\/437;\" \/><\/p>\n<p>\u540c\u6837\u65b9\u5f0f\u518d\u521b\u5efa\u4e00\u4e2a\u5bf9\u8bdd\u6846\uff0c\u5c5e\u6027 ID \u8bbe\u4e3a <strong>HELP_DIALOG<\/strong>\uff0c\u8fb9\u6846\u8bbe\u4e3a<strong>None<\/strong>\uff0c\u6837\u5f0f\u8bbe\u4e3a<strong>Child<\/strong>\uff0c\u754c\u9762\u4e0a \u653e\u70b9\u63a7\u4ef6<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1742111328787.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 892px; --smush-placeholder-aspect-ratio: 892\/962;\" \/><\/p>\n<p>\u540c\u6837\u4e3a\u8fd9\u4e2a\u5bf9\u8bdd\u6846\u6dfb\u52a0\u7c7b HelpDialog<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1742111496751.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 610px; --smush-placeholder-aspect-ratio: 610\/458;\" \/><\/p>\n<p>\u7f16\u8f91 CtabControlProjectDlg \u7c7b\u5934\u6587\u4ef6\uff0c\u5199\u5165<br \/>\n(\u6ce8\u610f\u5f15\u7528 MainDialog \u548c HelpDialog \u5934\u6587\u4ef6)<\/p>\n<pre><code class=\"language-cpp\">private:\n    MainDialog* mainDlg = nullptr;\n    HelpDialog* helpDlg = nullptr;<\/code><\/pre>\n<p>\u8fd9\u4e2a\u7528\u4e8e\u5b58\u50a8\u5b50\u5bf9\u8bdd\u6846\u7a97\u53e3<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1742111723849.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 869px; --smush-placeholder-aspect-ratio: 869\/508;\" \/><\/p>\n<p>\u7136\u540e\u518d\u7f16\u8f91\u5b83\u7684\u6e90\u6587\u4ef6\u4e2d\u7684 OnInitDialog \u65b9\u6cd5\uff0c\u6dfb\u52a0\u5728 TODO \u6ce8\u91ca\u7684\u4e0b\u9762<\/p>\n<pre><code class=\"language-cpp\">    \/\/ \u6dfb\u52a0\u6807\u7b7e\n    this-&gt;tabControl.InsertItem(0, L&quot;\u4e3b\u9875&quot;);\n    this-&gt;tabControl.InsertItem(1, L&quot;\u5e2e\u52a9&quot;);\n\n    \/\/ \u6807\u7b7e\u63a7\u4ef6\u94fa\u6ee1\u7a97\u53e3\n    CRect winRect;\n    GetClientRect(winRect);\n    this-&gt;tabControl.MoveWindow(winRect);\n\n    \/\/ \u521b\u5efa\u5b50\u5bf9\u8bdd\u6846\u5bf9\u8c61\n    this-&gt;mainDlg = new MainDialog();\n    this-&gt;helpDlg = new HelpDialog();\n\n    \/\/ \u521b\u5efa\u5b50\u5bf9\u8bdd\u6846\uff0c\u5e76\u4ee5\u6807\u7b7e\u9875\u4e3a\u7236\u7a97\u53e3\n    this-&gt;mainDlg-&gt;Create(MAIN_DIALOG, &amp;this-&gt;tabControl);\n    this-&gt;helpDlg-&gt;Create(HELP_DIALOG, &amp;this-&gt;tabControl);\n\n    \/\/ \u5b50\u5bf9\u8bdd\u6846\u94fa\u6ee1\u6807\u7b7e\u63a7\u4ef6\n    this-&gt;tabControl.AdjustRect(FALSE, winRect); \/\/ FALSE \u65f6\u5728\u4f20\u5165\u7684\u77e9\u5f62\u4e0a\u526a\u5207\u6389\u6807\u7b7e\u9875\u533a\u57df\n    this-&gt;mainDlg-&gt;MoveWindow(winRect);\n    this-&gt;helpDlg-&gt;MoveWindow(winRect);\n\n    \/\/ \u8bbe\u7f6e\u9ed8\u8ba4\u9009\u4e2d\u7b2c\u4e00\u4e2a\u6807\u7b7e\uff0c\u5e76\u663e\u793a\u5bf9\u5e94\u5b50\u7a97\u53e3\n    this-&gt;tabControl.SetCurSel(0);\n    this-&gt;mainDlg-&gt;ShowWindow(SW_SHOW);<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1742113027634.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 826px; --smush-placeholder-aspect-ratio: 826\/808;\" \/><\/p>\n<p>\u5728\u6807\u7b7e\u63a7\u4ef6\u4e0a\u53f3\u952e\u5c5e\u6027\uff0c\u70b9\u5f00\u26a1\u6807\u5fd7\uff0c\u6dfb\u52a0 TCN_SELCHANGE \u4e8b\u4ef6\u56de\u8c03<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1742113131520.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 859px; --smush-placeholder-aspect-ratio: 859\/433;\" \/><\/p>\n<p>\u5199\u5165<\/p>\n<pre><code class=\"language-cpp\">    \/\/ \u83b7\u53d6\u5f53\u524d\u9009\u4e2d\u9879\n    int sel = this-&gt;tabControl.GetCurSel();\n    switch (sel)\n    {\n        case 0:\n        {\n            \/\/ \u663e\u793a\u4e3b\u7a97\u53e3\uff0c\u9690\u85cf\u5e2e\u52a9\u7a97\u53e3\n            this-&gt;mainDlg-&gt;ShowWindow(SW_SHOW);\n            this-&gt;helpDlg-&gt;ShowWindow(SW_HIDE);\n            break;\n        }\n        case 1:\n        {\n            \/\/ \u9690\u85cf\u4e3b\u7a97\u53e3\uff0c\u663e\u793a\u5e2e\u52a9\u7a97\u53e3\n            this-&gt;mainDlg-&gt;ShowWindow(SW_HIDE);\n            this-&gt;helpDlg-&gt;ShowWindow(SW_SHOW);\n            break;\n        }\n    }<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u5b9e\u73b0\u4e86\u70b9\u51fb\u6807\u7b7e\u9875\u5207\u6362\u663e\u793a\u7684\u7a97\u53e3<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1742113368603.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 802px; --smush-placeholder-aspect-ratio: 802\/857;\" \/><\/p>\n<p>\u8c03\u8bd5\u8fd0\u884c\u6548\u679c<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1742113406748.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 569px; --smush-placeholder-aspect-ratio: 569\/385;\" \/><\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/03\/image-1742113414316.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 557px; --smush-placeholder-aspect-ratio: 557\/383;\" \/><\/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,594],"tags":[],"class_list":["post-19566","post","type-post","status-publish","format-standard","hentry","category-all","category-c-c","category-mfc","category-594"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/19566","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=19566"}],"version-history":[{"count":4,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/19566\/revisions"}],"predecessor-version":[{"id":19619,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/19566\/revisions\/19619"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}