{"id":8578,"date":"2023-01-28T23:53:18","date_gmt":"2023-01-28T15:53:18","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=8578"},"modified":"2024-05-05T14:18:33","modified_gmt":"2024-05-05T06:18:33","slug":"%e6%a1%8c%e9%9d%a2%e7%a8%8b%e5%ba%8f%e6%b7%bb%e5%8a%a0%e8%8f%9c%e5%8d%95-windows-api-%e4%bd%bf%e7%94%a8%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=8578","title":{"rendered":"\u684c\u9762\u7a0b\u5e8f\u6dfb\u52a0\u83dc\u5355\uff08\u8d44\u6e90\uff09 \u2013 Windows API"},"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-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.iyatt.com\/?p=8578\/#%E7%8E%AF%E5%A2%83\" >\u73af\u5883<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.iyatt.com\/?p=8578\/#%E7%BB%98%E5%88%B6%E8%8F%9C%E5%8D%95\" >\u7ed8\u5236\u83dc\u5355<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.iyatt.com\/?p=8578\/#%E6%B7%BB%E5%8A%A0%E6%96%B9%E5%BC%8F%E4%B8%80\" >\u6dfb\u52a0\u65b9\u5f0f\u4e00<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.iyatt.com\/?p=8578\/#%E6%B7%BB%E5%8A%A0%E6%96%B9%E5%BC%8F%E4%BA%8C\" >\u6dfb\u52a0\u65b9\u5f0f\u4e8c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.iyatt.com\/?p=8578\/#%E6%B7%BB%E5%8A%A0%E6%96%B9%E5%BC%8F%E4%B8%89\" >\u6dfb\u52a0\u65b9\u5f0f\u4e09<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.iyatt.com\/?p=8578\/#%E5%91%BD%E4%BB%A4%E6%B6%88%E6%81%AF%E5%A4%84%E7%90%86\" >\u547d\u4ee4\u6d88\u606f\u5904\u7406<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.iyatt.com\/?p=8578\/#%E4%B8%8A%E4%B8%8B%E6%96%87%E8%8F%9C%E5%8D%95\" >\u4e0a\u4e0b\u6587\u83dc\u5355<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.iyatt.com\/?p=8578\/#%E5%85%B6%E5%AE%83%E8%B5%84%E6%BA%90\" >\u5176\u5b83\u8d44\u6e90<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blog.iyatt.com\/?p=8578\/#%E5%9B%BE%E6%A0%87%E8%B5%84%E6%BA%90\" >\u56fe\u6807\u8d44\u6e90<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blog.iyatt.com\/?p=8578\/#%E5%85%89%E6%A0%87%E8%B5%84%E6%BA%90\" >\u5149\u6807\u8d44\u6e90<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/blog.iyatt.com\/?p=8578\/#%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%B5%84%E6%BA%90\" >\u5b57\u7b26\u4e32\u8d44\u6e90<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/blog.iyatt.com\/?p=8578\/#%E5%8A%A0%E9%80%9F%E9%94%AE%E8%B5%84%E6%BA%90\" >\u52a0\u901f\u952e\u8d44\u6e90<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"%E7%8E%AF%E5%A2%83\"><\/span>\u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Windows 11 \u4e13\u4e1a\u5de5\u4f5c\u7ad9\u7248 22H2<br \/>\nVisual Studio 2022 \u4e13\u4e1a\u7248<\/p>\n<p>Unicode \u5b57\u7b26\u96c6\uff0cC17 \u6807\u51c6\u7f16\u8bd1\uff0c64 \u4f4d\u7f16\u8bd1<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E7%BB%98%E5%88%B6%E8%8F%9C%E5%8D%95\"><\/span>\u7ed8\u5236\u83dc\u5355<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u6dfb\u52a0 Windows \u684c\u9762\u5411\u5bfc\uff0c\u521b\u5efa\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u7a7a\u9879\u76ee\uff0c\u53f3\u4fa7\u201c\u8d44\u6e90\u6587\u4ef6\u201d\u4e0a\u53f3\u952e\uff0c\u65b0\u5efa\u9879<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674917342802.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 469px; --smush-placeholder-aspect-ratio: 469\/377;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674915182934.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 705px; --smush-placeholder-aspect-ratio: 705\/220;\" \/><\/p>\n<p>\u5de6\u4fa7\u9009\u62e9\u201c\u8d44\u6e90\u201d\uff0c\u53f3\u8fb9\u9009\u201c\u8d44\u6e90\u6587\u4ef6\u201d\uff0c\u6587\u4ef6\u540d\u5b57\u8fd9\u91cc\u6211\u8bbe\u4e3a\u201cmenu.rc\u201d<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674915226554.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 782px; --smush-placeholder-aspect-ratio: 782\/646;\" \/><\/p>\n<p>\u4e0b\u9762\u5207\u6362\u5230\u201c\u8d44\u6e90\u89c6\u56fe\u201d<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674915329223.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 289px; --smush-placeholder-aspect-ratio: 289\/301;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674915343465.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 273px; --smush-placeholder-aspect-ratio: 273\/467;\" \/><\/p>\n<p>\u5728\u521b\u5efa\u7684\u8d44\u6e90\u6587\u4ef6\u4e0a\u53f3\u952e\u70b9\u201c\u6dfb\u52a0\u8d44\u6e90\u201d<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674915381558.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 350px; --smush-placeholder-aspect-ratio: 350\/299;\" \/><\/p>\n<p>\u9009 Menu\uff0c\u7136\u540e\u65b0\u5efa<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674915403354.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 434px; --smush-placeholder-aspect-ratio: 434\/356;\" \/><\/p>\n<p>\u7136\u540e\u5c31\u53ef\u4ee5\u7f16\u8f91\u83dc\u5355\u8d44\u6e90\uff0c\u7f16\u8f91\u5b8c\u6210\u540e\u6309 Ctrl+S \u4fdd\u5b58\u4e00\u4e0b<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674915446533.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 390px; --smush-placeholder-aspect-ratio: 390\/215;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/createMenuDemo.gif\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 352px; --smush-placeholder-aspect-ratio: 352\/496;\" \/><\/p>\n<p>\u6ce8\u610f\u4e0d\u7ba1\u54ea\u79cd\u5c06\u83dc\u5355\u8d44\u6e90\u6587\u4ef6\u6dfb\u52a0\u5230\u4ee3\u7801\u91cc\u7684\u65b9\u5f0f\uff0c\u90fd\u9700\u8981\u5f15\u7528\u4e00\u4e0b\u521b\u5efa\u8d44\u6e90\u6587\u4ef6\u65f6\u751f\u6210\u7684\u5934\u6587\u4ef6 \u201cresource.h\u201d<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E6%B7%BB%E5%8A%A0%E6%96%B9%E5%BC%8F%E4%B8%80\"><\/span>\u6dfb\u52a0\u65b9\u5f0f\u4e00<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u53ef\u4ee5\u5728\u8d44\u6e90\u89c6\u56fe\u67e5\u770b\uff0c\u8fd9\u91cc\u521b\u5efa\u7684\u83dc\u5355\u88ab\u547d\u540d\u4e3a\u4e86 IDR_MENU1<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674920470042.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 250px; --smush-placeholder-aspect-ratio: 250\/110;\" \/><\/p>\n<p>\u4e8e\u662f\u53ef\u4ee5\u5728\u6ce8\u518c\u7a97\u53e3\u7c7b\u7684\u65f6\u5019\u5c06\u83dc\u5355\u6dfb\u52a0\u8fdb\u53bb<\/p>\n<pre><code class=\"language-c\">#include &lt;Windows.h&gt;\n#include &quot;resource.h&quot; \/\/ \u83dc\u5355\u8d44\u6e90\u6587\u4ef6\u5f15\u5165\n\nLRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)\n{\n    switch (msg)\n    {\n        case WM_PAINT:\n        {\n            PAINTSTRUCT ps = {0};\n            HDC hdc = BeginPaint(hWnd, &amp;ps);\n            TextOut(hdc, 10, 10, L&quot;\u4f60\u597d\uff0c\u4e16\u754c\uff01&quot;, wcslen(L&quot;\u4f60\u597d\uff0c\u4e16\u754c\uff01&quot;));\n            EndPaint(hWnd, &amp;ps);\n            break;\n        }\n        case WM_CLOSE:\n        {\n            DestroyWindow(hWnd);\n            break;\n        }\n        case WM_DESTROY:\n        {\n            PostQuitMessage(0);\n            break;\n        }\n        default:\n        {\n            return DefWindowProc(hWnd, msg, wParam, lParam);\n        }\n    }\n    return 0;\n}\n\nint WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPreHinstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)\n{\n    PCWSTR window_class_name = L&quot;Desktop&quot;;\n    WNDCLASSEX wc = {0};\n    wc.cbSize = sizeof(WNDCLASSEX);\n    wc.hInstance = hInstance;\n    wc.lpfnWndProc = WndProc;\n    wc.lpszClassName = window_class_name;\n    wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1); \/\/ \u5c06\u83dc\u5355\u8d44\u6e90\u540d\u5b57\u6dfb\u52a0\u8fdb\u53bb\uff0c\u5e76\u4e14\u8981\u5c06\u6570\u636e\u7c7b\u578b\u8f6c\u4e3a\u5bbd\u5b57\u7b26\u6307\u9488\uff08\u5bbd\u5b57\u7b26\u5b57\u7b26\u4e32 PWSTR = WCHAR * = wchar_t *\uff09\n\n    if (!RegisterClassEx(&amp;wc))\n    {\n        MessageBox(NULL, L&quot;\u6ce8\u518c\u7a97\u53e3\u7c7b\u5931\u8d25\uff01&quot;, L&quot;\u9519\u8bef&quot;, MB_OK);\n        return 1;\n    }\n\n    HWND hWnd = CreateWindowEx(0, window_class_name, L&quot;\u7b80\u5355\u7a97\u53e3\u7a0b\u5e8f&quot;, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 260, 120, NULL, NULL, hInstance, NULL);\n    if (!hWnd)\n    {\n        MessageBox(NULL, L&quot;\u521b\u5efa\u7a97\u53e3\u5931\u8d25\uff01&quot;, L&quot;\u9519\u8bef&quot;, MB_OK);\n        return 1;\n    }\n\n    ShowWindow(hWnd, nCmdShow);\n    UpdateWindow(hWnd);\n\n    MSG msg = {0};\n    while (GetMessage(&amp;msg, NULL, 0, 0))\n    {\n        TranslateMessage(&amp;msg);\n        DispatchMessage(&amp;msg);\n    }\n    return (int)msg.wParam;\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674921163572.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 246px; --smush-placeholder-aspect-ratio: 246\/113;\" \/><br \/>\n\u540e\u9762\u4e24\u79cd\u6dfb\u52a0\u83dc\u5355\u540e\u754c\u9762\u90fd\u4e00\u6837\uff0c\u6211\u5c31\u4e0d\u8d34\u56fe\u4e86<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E6%B7%BB%E5%8A%A0%E6%96%B9%E5%BC%8F%E4%BA%8C\"><\/span>\u6dfb\u52a0\u65b9\u5f0f\u4e8c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u5728\u521b\u5efa\u7a97\u53e3\u7684\u65f6\u5019\uff0c\u901a\u8fc7\u7a97\u53e3\u521b\u5efa\u51fd\u6570\u53c2\u6570\u6dfb\u52a0\u83dc\u5355\u8d44\u6e90<\/p>\n<pre><code class=\"language-c\">#include &lt;Windows.h&gt;\n#include &quot;resource.h&quot; \/\/ \u83dc\u5355\u8d44\u6e90\u6587\u4ef6\u5f15\u5165\n\nLRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)\n{\n    switch (msg)\n    {\n        case WM_PAINT:\n        {\n            PAINTSTRUCT ps = {0};\n            HDC hdc = BeginPaint(hWnd, &amp;ps);\n            TextOut(hdc, 10, 10, L&quot;\u4f60\u597d\uff0c\u4e16\u754c\uff01&quot;, wcslen(L&quot;\u4f60\u597d\uff0c\u4e16\u754c\uff01&quot;));\n            EndPaint(hWnd, &amp;ps);\n            break;\n        }\n        case WM_CLOSE:\n        {\n            DestroyWindow(hWnd);\n            break;\n        }\n        case WM_DESTROY:\n        {\n            PostQuitMessage(0);\n            break;\n        }\n        default:\n        {\n            return DefWindowProc(hWnd, msg, wParam, lParam);\n        }\n    }\n    return 0;\n}\n\nint WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPreHinstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)\n{\n    PCWSTR window_class_name = L&quot;Desktop&quot;;\n    WNDCLASSEX wc = {0};\n    wc.cbSize = sizeof(WNDCLASSEX);\n    wc.hInstance = hInstance;\n    wc.lpfnWndProc = WndProc;\n    wc.lpszClassName = window_class_name;\n\n    if (!RegisterClassEx(&amp;wc))\n    {\n        MessageBox(NULL, L&quot;\u6ce8\u518c\u7a97\u53e3\u7c7b\u5931\u8d25\uff01&quot;, L&quot;\u9519\u8bef&quot;, MB_OK);\n        return 1;\n    }\n\n    HMENU hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); \/\/ \u52a0\u8f7d\u83dc\u5355\u8d44\u6e90\n    HWND hWnd = CreateWindowEx(0, window_class_name, L&quot;\u7b80\u5355\u7a97\u53e3\u7a0b\u5e8f&quot;, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 260, 120, NULL, hMenu, hInstance, NULL); \/\/ \u7b2c\u5341\u4e2a\u53c2\u6570\u4f20\u5165\u83dc\u5355\n    if (!hWnd)\n    {\n        MessageBox(NULL, L&quot;\u521b\u5efa\u7a97\u53e3\u5931\u8d25\uff01&quot;, L&quot;\u9519\u8bef&quot;, MB_OK);\n        return 1;\n    }\n\n    ShowWindow(hWnd, nCmdShow);\n    UpdateWindow(hWnd);\n\n    MSG msg = {0};\n    while (GetMessage(&amp;msg, NULL, 0, 0))\n    {\n        TranslateMessage(&amp;msg);\n        DispatchMessage(&amp;msg);\n    }\n    return (int)msg.wParam;\n}<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"%E6%B7%BB%E5%8A%A0%E6%96%B9%E5%BC%8F%E4%B8%89\"><\/span>\u6dfb\u52a0\u65b9\u5f0f\u4e09<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u5728\u521b\u5efa\u7a97\u53e3\u540e\uff0c\u663e\u793a\u7a97\u53e3\u524d\uff0c\u53d1\u9001 WM_CREATE \u6d88\u606f\u65f6\u8bbe\u7f6e\u83dc\u5355<\/p>\n<pre><code class=\"language-c\">#include &lt;Windows.h&gt;\n#include &quot;resource.h&quot; \/\/ \u83dc\u5355\u8d44\u6e90\u6587\u4ef6\u5f15\u5165\n\nLRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)\n{\n    switch (msg)\n    {\n        case WM_CREATE:\n        {\n            \/\/ \u901a\u8fc7\u7a97\u53e3\u521b\u5efa\u51fd\u6570\u4f20\u5165\u52a0\u8f7d\u597d\u7684\u83dc\u5355\u8d44\u6e90\n            CREATESTRUCT *pCreate = (CREATESTRUCT *)lParam;\n            HMENU hMenu = *(HMENU *)(pCreate-&gt;lpCreateParams);\n            \/\/ \u8bbe\u7f6e\u83dc\u5355\n            SetMenu(hWnd, hMenu);\n        }\n        case WM_PAINT:\n        {\n            PAINTSTRUCT ps = {0};\n            HDC hdc = BeginPaint(hWnd, &amp;ps);\n            TextOut(hdc, 10, 10, L&quot;\u4f60\u597d\uff0c\u4e16\u754c\uff01&quot;, wcslen(L&quot;\u4f60\u597d\uff0c\u4e16\u754c\uff01&quot;));\n            EndPaint(hWnd, &amp;ps);\n            break;\n        }\n        case WM_CLOSE:\n        {\n            DestroyWindow(hWnd);\n            break;\n        }\n        case WM_DESTROY:\n        {\n            PostQuitMessage(0);\n            break;\n        }\n        default:\n        {\n            return DefWindowProc(hWnd, msg, wParam, lParam);\n        }\n    }\n    return 0;\n}\n\nint WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPreHinstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)\n{\n    PCWSTR window_class_name = L&quot;Desktop&quot;;\n    WNDCLASSEX wc = {0};\n    wc.cbSize = sizeof(WNDCLASSEX);\n    wc.hInstance = hInstance;\n    wc.lpfnWndProc = WndProc;\n    wc.lpszClassName = window_class_name;\n\n    if (!RegisterClassEx(&amp;wc))\n    {\n        MessageBox(NULL, L&quot;\u6ce8\u518c\u7a97\u53e3\u7c7b\u5931\u8d25\uff01&quot;, L&quot;\u9519\u8bef&quot;, MB_OK);\n        return 1;\n    }\n\n    HMENU hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); \/\/ \u52a0\u8f7d\u83dc\u5355\u8d44\u6e90\n    HWND hWnd = CreateWindowEx(0, window_class_name, L&quot;\u7b80\u5355\u7a97\u53e3\u7a0b\u5e8f&quot;, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 260, 120, NULL, NULL, hInstance, &amp;hMenu); \/\/ \u53ef\u4ee5\u4f7f\u7528\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u4f20\u5165\u6570\u636e\n    if (!hWnd)\n    {\n        MessageBox(NULL, L&quot;\u521b\u5efa\u7a97\u53e3\u5931\u8d25\uff01&quot;, L&quot;\u9519\u8bef&quot;, MB_OK);\n        return 1;\n    }\n\n    ShowWindow(hWnd, nCmdShow);\n    UpdateWindow(hWnd);\n\n    MSG msg = {0};\n    while (GetMessage(&amp;msg, NULL, 0, 0))\n    {\n        TranslateMessage(&amp;msg);\n        DispatchMessage(&amp;msg);\n    }\n    return (int)msg.wParam;\n}<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"%E5%91%BD%E4%BB%A4%E6%B6%88%E6%81%AF%E5%A4%84%E7%90%86\"><\/span>\u547d\u4ee4\u6d88\u606f\u5904\u7406<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u524d\u9762\u53ea\u662f\u5c06\u83dc\u5355\u7ed8\u5236\u5230\u7a97\u53e3\u91cc\u4e86\uff0c\u4f46\u662f\u70b9\u51fb\u83dc\u5355\u9879\u5e76\u6ca1\u6709\u4efb\u4f55\u53cd\u5e94\uff0c\u56e0\u6b64\u8fd8\u9700\u8981\u4e3a\u83dc\u5355\u9879\u70b9\u51fb\u547d\u4ee4\u8bbe\u7f6e\u884c\u4e3a\uff0c\u5373\u83dc\u5355\u547d\u4ee4\u7684\u6d88\u606f\u5904\u7406\u3002<\/p>\n<pre><code class=\"language-c\">#include &lt;Windows.h&gt;\n#include &quot;resource.h&quot; \/\/ \u83dc\u5355\u8d44\u6e90\u6587\u4ef6\u5f15\u5165\n\nLRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)\n{\n    switch (msg)\n    {\n        case WM_COMMAND: \/\/ \u70b9\u51fb\u83dc\u5355\u9879\u4f1a\u6536\u5230\u8be5\u6d88\u606f\n        {\n            switch (LOWORD(wParam)) \/\/ \u5339\u914d\u5bf9\u5e94\u7684\u83dc\u5355\u9879 ID\uff0c\u8bbe\u8ba1\u83dc\u5355\u754c\u9762\u7684\u65f6\u5019\u5728\u83dc\u5355\u9879\u53f3\u952e\u5c5e\u6027\u4e5f\u53ef\u4ee5\u4fee\u6539 ID \u503c\uff0c\u8fd9\u91cc\u662f\u9ed8\u8ba4\u7684\n            {\n                case ID_40001:\n                {\n                    MessageBox(NULL, L&quot;\u70b9\u51fb\u65b0\u5efa&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                    break;\n                }\n                case ID_40002:\n                {\n                    MessageBox(NULL, L&quot;\u70b9\u51fb\u9000\u51fa&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                    break;\n                }\n                case ID_40003:\n                {\n                    MessageBox(NULL, L&quot;\u70b9\u51fb\u5173\u4e8e&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                    break;\n                }\n                default:\n                {\n                    break;\n                }\n            }\n            break;\n        }\n        case WM_PAINT:\n        {\n            PAINTSTRUCT ps = {0};\n            HDC hdc = BeginPaint(hWnd, &amp;ps);\n            TextOut(hdc, 10, 10, L&quot;\u4f60\u597d\uff0c\u4e16\u754c\uff01&quot;, wcslen(L&quot;\u4f60\u597d\uff0c\u4e16\u754c\uff01&quot;));\n            EndPaint(hWnd, &amp;ps);\n            break;\n        }\n        case WM_CLOSE:\n        {\n            DestroyWindow(hWnd);\n            break;\n        }\n        case WM_DESTROY:\n        {\n            PostQuitMessage(0);\n            break;\n        }\n        default:\n        {\n            return DefWindowProc(hWnd, msg, wParam, lParam);\n        }\n    }\n    return 0;\n}\n\nint WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPreHinstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)\n{\n    PCWSTR window_class_name = L&quot;Desktop&quot;;\n    WNDCLASSEX wc = {0};\n    wc.cbSize = sizeof(WNDCLASSEX);\n    wc.hInstance = hInstance;\n    wc.lpfnWndProc = WndProc;\n    wc.lpszClassName = window_class_name;\n    wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);\n\n    if (!RegisterClassEx(&amp;wc))\n    {\n        MessageBox(NULL, L&quot;\u6ce8\u518c\u7a97\u53e3\u7c7b\u5931\u8d25\uff01&quot;, L&quot;\u9519\u8bef&quot;, MB_OK);\n        return 1;\n    }\n\n    HWND hWnd = CreateWindowEx(0, window_class_name, L&quot;\u7b80\u5355\u7a97\u53e3\u7a0b\u5e8f&quot;, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 260, 120, NULL, NULL, hInstance, NULL);\n    if (!hWnd)\n    {\n        MessageBox(NULL, L&quot;\u521b\u5efa\u7a97\u53e3\u5931\u8d25\uff01&quot;, L&quot;\u9519\u8bef&quot;, MB_OK);\n        return 1;\n    }\n\n    ShowWindow(hWnd, nCmdShow);\n    UpdateWindow(hWnd);\n\n    MSG msg = {0};\n    while (GetMessage(&amp;msg, NULL, 0, 0))\n    {\n        TranslateMessage(&amp;msg);\n        DispatchMessage(&amp;msg);\n    }\n    return (int)msg.wParam;\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674955687040.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 248px; --smush-placeholder-aspect-ratio: 248\/285;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674955703380.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 265px; --smush-placeholder-aspect-ratio: 265\/277;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674955720553.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 242px; --smush-placeholder-aspect-ratio: 242\/259;\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E4%B8%8A%E4%B8%8B%E6%96%87%E8%8F%9C%E5%8D%95\"><\/span>\u4e0a\u4e0b\u6587\u83dc\u5355<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u8fd9\u4e2a\u83dc\u5355\u5c31\u662f\u4e00\u822c\u8bf4\u7684\u53f3\u952e\u83dc\u5355\uff0c\u53f3\u952e\u83dc\u5355\u4f7f\u7528\u7684\u83dc\u5355\u9879\u5185\u5bb9\u8fd8\u662f\u524d\u9762\u7ed8\u5236\u7684\u83dc\u5355\u8d44\u6e90\u3002<br \/>\n\u6b64\u5904\u5728\u524d\u9762\u7684\u57fa\u7840\u4e0a\u518d\u6dfb\u52a0\u4e00\u4e2a\u9876\u5c42\u83dc\u5355\u9879\uff0c\u4e13\u7528\u4e8e\u4e0a\u4e0b\u6587\u83dc\u5355\u4f7f\u7528\u3002<\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674956339273.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 306px; --smush-placeholder-aspect-ratio: 306\/161;\" \/><\/p>\n<pre><code class=\"language-c\">#include &lt;Windows.h&gt;\n#include &quot;resource.h&quot; \/\/ \u83dc\u5355\u8d44\u6e90\u6587\u4ef6\u5f15\u5165\n\nHMENU g_popup = {0}; \/\/ \u7528\u4e8e\u5b58\u50a8\u4e0a\u4e0b\u6587\u83dc\u5355\n\nLRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)\n{\n    switch (msg)\n    {\n        case WM_CONTEXTMENU: \/\/ \u4e13\u7528\u4e8e\u53f3\u952e\u83dc\u5355\u7684\uff0c\u5728\u53f3\u952e\u653e\u5f00\u6d88\u606f\u540e\u4ea7\u751f\n        {\n            \/\/ \u6dfb\u52a0\u4e0a\u4e0b\u6587\u83dc\u5355\n            \/\/ \u8981\u6dfb\u52a0\u7684\u83dc\u5355\u7684\u53e5\u67c4\n            \/\/ \u83dc\u5355\u5f39\u51fa\u4f4d\u7f6e\uff0c\u4e0b\u9762\u7684\u662f\u8bbe\u7f6e\u7684\u5f39\u51fa\u83dc\u5355\u7684\u5de6\u4e0a\u65b9\u8d34\u9760\u6307\u5b9a\u5750\u6807\n            \/\/ \u63a5\u7740\u4e24\u4e2a\u53c2\u6570\u5206\u522b\u4f20\u6a2a\u7eb5\u5750\u6807\uff0c\u8fd9\u91cc\u6d88\u606f\u9644\u5e26\u7684\u662f\u5f53\u524d\u9f20\u6807\u4f4d\u7f6e\u7684\u5c4f\u5e55\u5750\u6807\n            \/\/ \u4fdd\u7559\u53c2\u6570\uff0c\u5199 0\n            \/\/ \u7a97\u53e3\u53e5\u67c4\n            \/\/ \u4e0d\u5e38\u7528\u7684\u53c2\u6570\uff0c\u4f20 NULL\n            TrackPopupMenu(g_popup, TPM_LEFTALIGN | TPM_TOPALIGN, LOWORD(lParam), HIWORD(lParam), 0, hWnd, NULL);\n            break;\n        }\n        case WM_COMMAND: \/\/ \u70b9\u51fb\u83dc\u5355\u9879\u4f1a\u6536\u5230\u8be5\u6d88\u606f\n        {\n            switch (LOWORD(wParam)) \/\/ \u5339\u914d\u5bf9\u5e94\u7684\u83dc\u5355\u9879 ID\uff0c\u8bbe\u8ba1\u83dc\u5355\u754c\u9762\u7684\u65f6\u5019\u5728\u83dc\u5355\u9879\u53f3\u952e\u5c5e\u6027\u4e5f\u53ef\u4ee5\u4fee\u6539 ID \u503c\uff0c\u8fd9\u91cc\u662f\u9ed8\u8ba4\u7684\n            {\n                case ID_40001:\n                {\n                    MessageBox(NULL, L&quot;\u70b9\u51fb\u65b0\u5efa&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                    break;\n                }\n                case ID_40002:\n                {\n                    MessageBox(NULL, L&quot;\u70b9\u51fb\u9000\u51fa&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                    break;\n                }\n                case ID_40003:\n                {\n                    MessageBox(NULL, L&quot;\u70b9\u51fb\u5173\u4e8e&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                    break;\n                }\n                case ID_40004:\n                {\n                    MessageBox(NULL, L&quot;\u70b9\u51fb\u83dc\u5355\u98791&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                    break;\n                }\n                case ID_40005:\n                {\n                    MessageBox(NULL, L&quot;\u70b9\u51fb\u83dc\u5355\u98792&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                    break;\n                }\n                case ID_40006:\n                {\n                    MessageBox(NULL, L&quot;\u70b9\u51fb\u83dc\u5355\u98793&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                    break;\n                }\n                default:\n                {\n                    break;\n                }\n            }\n            break;\n        }\n        case WM_PAINT:\n        {\n            PAINTSTRUCT ps = {0};\n            HDC hdc = BeginPaint(hWnd, &amp;ps);\n            TextOut(hdc, 10, 10, L&quot;\u4f60\u597d\uff0c\u4e16\u754c\uff01&quot;, wcslen(L&quot;\u4f60\u597d\uff0c\u4e16\u754c\uff01&quot;));\n            EndPaint(hWnd, &amp;ps);\n            break;\n        }\n        case WM_CLOSE:\n        {\n            DestroyWindow(hWnd);\n            break;\n        }\n        case WM_DESTROY:\n        {\n            PostQuitMessage(0);\n            break;\n        }\n        default:\n        {\n            return DefWindowProc(hWnd, msg, wParam, lParam);\n        }\n    }\n    return 0;\n}\n\nint WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPreHinstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)\n{\n    PCWSTR window_class_name = L&quot;Desktop&quot;;\n    WNDCLASSEX wc = {0};\n    wc.cbSize = sizeof(WNDCLASSEX);\n    wc.hInstance = hInstance;\n    wc.lpfnWndProc = WndProc;\n    wc.lpszClassName = window_class_name;\n\n    if (!RegisterClassEx(&amp;wc))\n    {\n        MessageBox(NULL, L&quot;\u6ce8\u518c\u7a97\u53e3\u7c7b\u5931\u8d25\uff01&quot;, L&quot;\u9519\u8bef&quot;, MB_OK);\n        return 1;\n    }\n\n    HMENU hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); \/\/ \u52a0\u8f7d\u83dc\u5355\u8d44\u6e90\n    g_popup = GetSubMenu(hMenu, 2); \/\/ \u83b7\u53d6\u5b50\u83dc\u5355\uff0c\u8bbe\u8ba1\u7684\u83dc\u5355\u5728\u7b2c\u4e09\u4e2a\uff0c\u4ece 0 \u5f00\u59cb\u7d22\u5f15\u4e3a 2\n\n    HWND hWnd = CreateWindowEx(0, window_class_name, L&quot;\u7b80\u5355\u7a97\u53e3\u7a0b\u5e8f&quot;, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 200, NULL, hMenu, hInstance, NULL);\n    if (!hWnd)\n    {\n        MessageBox(NULL, L&quot;\u521b\u5efa\u7a97\u53e3\u5931\u8d25\uff01&quot;, L&quot;\u9519\u8bef&quot;, MB_OK);\n        return 1;\n    }\n\n    ShowWindow(hWnd, nCmdShow);\n    UpdateWindow(hWnd);\n\n    MSG msg = {0};\n    while (GetMessage(&amp;msg, NULL, 0, 0))\n    {\n        TranslateMessage(&amp;msg);\n        DispatchMessage(&amp;msg);\n    }\n    return (int)msg.wParam;\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674957810121.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 297px; --smush-placeholder-aspect-ratio: 297\/210;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674957823474.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 236px; --smush-placeholder-aspect-ratio: 236\/151;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674957837860.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 306px; --smush-placeholder-aspect-ratio: 306\/197;\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E5%85%B6%E5%AE%83%E8%B5%84%E6%BA%90\"><\/span>\u5176\u5b83\u8d44\u6e90<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u521b\u5efa\u5176\u5b83\u8d44\u6e90\u6587\u4ef6\u64cd\u4f5c\u548c\u4e0a\u9762\u7c7b\u4f3c\uff0c\u521b\u5efa\u7684\u65f6\u5019\u9009\u597d\u7c7b\u578b\u6216\u8005\u6dfb\u52a0\u6307\u5b9a\u7c7b\u578b\u7684\u8d44\u6e90<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674989110507.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 938px; --smush-placeholder-aspect-ratio: 938\/649;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1674997834772.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 415px; --smush-placeholder-aspect-ratio: 415\/280;\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E5%9B%BE%E6%A0%87%E8%B5%84%E6%BA%90\"><\/span>\u56fe\u6807\u8d44\u6e90<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u6ce8\u518c\u7a97\u53e3\u7c7b\u7684\u65f6\u5019\uff0cWNDCLASSEX \u6709\u4e00\u4e2a\u6210\u5458 hIcon \u5c31\u662f\u8bbe\u7f6e\u56fe\u6807\u8d44\u6e90\u53e5\u67c4\u7684\u3002<br \/>\n\u9700\u8981\u4f7f\u7528 LoadIcon \u52a0\u8f7d\u56fe\u6807\u8d44\u6e90\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u5c31\u662f\u5f53\u524d\u5b9e\u4f8b\u53e5\u67c4\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4f20\u56fe\u6807\u8d44\u6e90\u7684\u540d\u5b57\uff0c\u548c\u4e0a\u9762\u7684\u83dc\u5355\u8d44\u6e90\u52a0\u8f7d\u65b9\u6cd5\u7c7b\u4f3c\u3002<br \/>\n\u8f6f\u4ef6\u6807\u9898\u6846\u7684\u56fe\u6807\u8fd9\u4e9b\u90fd\u662f\u4f7f\u7528\u7684\u56fe\u6807\u8d44\u6e90\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E5%85%89%E6%A0%87%E8%B5%84%E6%BA%90\"><\/span>\u5149\u6807\u8d44\u6e90<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u6709\u4e24\u79cd\u65b9\u6cd5\u4f7f\u7528\uff0c\u4e00\u79cd\u4e5f\u662f\u5728\u6ce8\u518c\u7a97\u53e3\u7684\u65f6\u5019\u8bbe\u7f6e\uff0c\u5c06\u5149\u6807\u8d44\u6e90\u53e5\u67c4\u8bbe\u7ed9 hCursor\u3002<br \/>\n\u52a0\u8f7d\u5149\u6807\u8d44\u6e90\u4f7f\u7528 LoadCursor\uff0c\u53c2\u6570\u4e5f\u7c7b\u4f3c\u4e0a\u9762\u3002<br \/>\n\u5149\u6807\u8d44\u6e90\u5c31\u662f\u5149\u6807\u7684\u56fe\u5f62\uff0c\u4e00\u822c\u662f\u663e\u793a\u7684\u7bad\u5934\uff0c\u53ef\u4ee5\u81ea\u5df1\u753b\u6210\u5176\u5b83\u5f62\u72b6\u7684\uff0c\u6bd4\u5982\u5fd9\u788c\u65f6\u9f20\u6807\u663e\u793a\u5708\uff0c\u6709\u4e9b\u60c5\u51b5\u663e\u793a\u5341\u5b57\u7b49\u7b49\u3002<br \/>\n\u4e0a\u9762\u7684\u8bbe\u7f6e\u65b9\u6cd5\u53ea\u80fd\u5728\u6ce8\u518c\u7a97\u53e3\u7684\u65f6\u5019\u4f7f\u7528\uff0c\u4f46\u662f\u5c31\u65e0\u6cd5\u5728\u7a0b\u5e8f\u8fd0\u884c\u4e2d\u9014\u8fdb\u884c\u53d8\u5316\uff0c\u6240\u4ee5\u8fd8\u6709\u4e00\u79cd\u65b9\u6cd5\uff0c\u4f7f\u7528 SetCursor\uff0c\u53c2\u6570\u4e3a\u5f53\u524d\u6b63\u5728\u4f7f\u7528\u7684\u5149\u6807\u7684\u53e5\u67c4\uff08\u540e\u9762\u7684\u6d88\u606f\u4f1a\u9644\u5e26\u4f20\u5165\u8fd9\u4e2a\u53c2\u6570\uff09\u3002\u4e0d\u8fc7\u6ce8\u610f\u8fd9\u4e2a\u51fd\u6570\u8981\u653e\u5230 WM_SETCUSOR \u6d88\u606f\u7684\u5904\u7406\u4e2d\uff08\u5149\u6807\u79fb\u52a8\u5c31\u4f1a\u4ea7\u751f\u8fd9\u4e2a\u6d88\u606f\uff09\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%B5%84%E6%BA%90\"><\/span>\u5b57\u7b26\u4e32\u8d44\u6e90<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u5b57\u7b26\u4e32\u8d44\u6e90\u6587\u4ef6\u53ef\u4ee5\u7528\u4e8e\u4e13\u95e8\u5b58\u50a8\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u5230\u7684\u5b57\u7b26\u4e32\uff0c\u6bcf\u4e2a\u5b57\u7b26\u4e32\u6709\u4e13\u95e8\u7684\u7d22\u5f15 ID\uff0c\u7a0b\u5e8f\u4e2d\u901a\u8fc7 LoadString \u53bb\u53d6\u6307\u5b9a ID \u5bf9\u5e94\u7684\u5b57\u7b26\u4e32\u3002<br \/>\n\u5b83\u7684\u610f\u4e49\u7684\u8bdd\uff0c\u6211\u60f3\u5230\u7684\u662f\u5bf9\u4e8e\u591a\u8bed\u8a00\u7684\u652f\u6301\u3002\u5b57\u7b26\u4e32\u8d44\u6e90\u6587\u4ef6\u5206\u522b\u5236\u4f5c\u4e0d\u540c\u8bed\u8a00\u7684\u7248\u672c\uff0c\u8981\u7528\u54ea\u79cd\u8bed\u8a00\u5c31\u5c06\u5bf9\u5e94\u7684\u5b57\u7b26\u4e32\u8d44\u6e90\u6587\u4ef6\u653e\u8fdb\u53bb\uff0c\u5728\u4e0d\u4fee\u6539\u7a0b\u5e8f\u7684\u60c5\u51b5\u4e0b\u53ef\u4ee5\u505a\u5230\u7a0b\u5e8f\u5185\u8bed\u8a00\u7684\u4fee\u6539\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E5%8A%A0%E9%80%9F%E9%94%AE%E8%B5%84%E6%BA%90\"><\/span>\u52a0\u901f\u952e\u8d44\u6e90<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u8fd9\u4e2a\u52a0\u901f\u952e\u5c31\u662f\u4e00\u822c\u8bf4\u7684\u5feb\u6377\u952e\uff0c\u52a0\u901f\u952e\u8981\u548c\u5177\u4f53\u7684\u64cd\u4f5c\u7ed1\u5b9a\u8d77\u6765\uff0c\u6240\u4ee5\u8fd9\u91cc\u6cbf\u7528\u524d\u9762\u201c\u4e0a\u4e0b\u6587\u83dc\u5355\u201d\u7684\u6e90\u7801\u548c\u83dc\u5355\u8d44\u6e90\u6587\u4ef6\uff0c\u5728\u4e0a\u9762\u4e3a\u90e8\u5206\u83dc\u5355\u9879\u6dfb\u52a0\u52a0\u901f\u952e\u3002<\/p>\n<p>\u8fd9\u91cc\u8981\u7528\u5230\u52a0\u901f\u952e\u8d44\u6e90\uff0c\u5c31\u5728 menu.rc \u91cc\u7ee7\u7eed\u6dfb\u52a0<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1675008680231.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 294px; --smush-placeholder-aspect-ratio: 294\/272;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1675006758789.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 412px; --smush-placeholder-aspect-ratio: 412\/332;\" \/><\/p>\n<p>\u6211\u7ed9\u4e0a\u4e0b\u6587\u83dc\u5355\u7684\u90a3\u4e09\u4e2a\u83dc\u5355\u9879\u6dfb\u52a0\u52a0\u901f\u952e\uff0c\u6ce8\u610f\u4ed6\u4eec\u5404\u81ea\u7684 ID<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1675006837203.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 432px; --smush-placeholder-aspect-ratio: 432\/245;\" \/><br \/>\n\u8bbe\u7f6e\u52a0\u901f\u952e\u8d44\u6e90\uff0c\u5c06 ID \u5bf9\u5e94\u8981\u8bbe\u7f6e\u52a0\u901f\u952e\u7684\u83dc\u5355\u9879\uff0c\u540e\u9762\u8bbe\u7f6e\u6309\u952e\u3002\u8bbe\u7f6e\u5b8c\u6210\u540e\u8bb0\u5f97\u6309\u4e0b Ctrl+S \u4fdd\u5b58\u3002<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1675009839282.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 531px; --smush-placeholder-aspect-ratio: 531\/108;\" \/><\/p>\n<p>\u5177\u4f53\u5b9e\u73b0\u770b\u4e0b\u9762\u4ee3\u7801<\/p>\n<pre><code class=\"language-c\">#include &lt;Windows.h&gt;\n#include &quot;resource.h&quot; \/\/ \u8d44\u6e90\u6587\u4ef6\u5f15\u5165\n\nHMENU g_popup = {0};\n\nLRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)\n{\n    switch (msg)\n    {\n        case WM_CONTEXTMENU:\n        {\n            TrackPopupMenu(g_popup, TPM_LEFTALIGN | TPM_TOPALIGN, LOWORD(lParam), HIWORD(lParam), 0, hWnd, NULL);\n            break;\n        }\n        case WM_COMMAND: \/\/ \u70b9\u51fb\u83dc\u5355\u9879\u4f1a\u6536\u5230\u8be5\u6d88\u606f \/\/ \u52a0\u901f\u952e\u6309\u4e0b\u4e5f\u662f\u8fd9\u4e2a\u6d88\u606f\u4ee3\u7801\n        {\n            if (HIWORD(wParam)) \/\/ \u52a0\u901f\u952e\u6d88\u606f - \u8fd9\u4e00\u6b65\u5176\u5b9e\u4e0d\u662f\u5f88\u6709\u5fc5\u8981\uff0c\u73b0\u5b9e\u4f7f\u7528\u4e2d\u4e00\u822c\u4e5f\u4e0d\u4f1a\u53bb\u533a\u5206\u662f\u76f4\u63a5\u70b9\u51fb\u7684\u83dc\u5355\u8fd8\u662f\u6309\u7684\u52a0\u901f\u952e\uff0c\u8fd9\u91cc\u53ea\u662f\u6f14\u793a\u8fd9\u4e2a\u529f\u80fd\n            {\n                switch (LOWORD(wParam))\n                {\n                    case ID_40004:\n                    {\n                        MessageBox(NULL, L&quot;\u52a0\u901f\u952e\u89e6\u53d1\u83dc\u5355\u98791&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                        break;\n                    }\n                    case ID_40005:\n                    {\n                        MessageBox(NULL, L&quot;\u52a0\u901f\u952e\u89e6\u53d1\u83dc\u5355\u98792&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                        break;\n                    }\n                    case ID_40006:\n                    {\n                        MessageBox(NULL, L&quot;\u52a0\u901f\u952e\u89e6\u53d1\u83dc\u5355\u98793&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                        break;\n                    }\n                    default:\n                    {\n                        break;\n                    }\n                }\n                break;\n            }\n\n            switch (LOWORD(wParam))\n            {\n                case ID_40001:\n                {\n                    MessageBox(NULL, L&quot;\u70b9\u51fb\u65b0\u5efa&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                    break;\n                }\n                case ID_40002:\n                {\n                    MessageBox(NULL, L&quot;\u70b9\u51fb\u9000\u51fa&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                    break;\n                }\n                case ID_40003:\n                {\n                    MessageBox(NULL, L&quot;\u70b9\u51fb\u5173\u4e8e&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                    break;\n                }\n                case ID_40004:\n                {\n                    MessageBox(NULL, L&quot;\u70b9\u51fb\u83dc\u5355\u98791&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                    break;\n                }\n                case ID_40005:\n                {\n                    MessageBox(NULL, L&quot;\u70b9\u51fb\u83dc\u5355\u98792&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                    break;\n                }\n                case ID_40006:\n                {\n                    MessageBox(NULL, L&quot;\u70b9\u51fb\u83dc\u5355\u98793&quot;, L&quot;\u6d88\u606f&quot;, MB_OK);\n                    break;\n                }\n                default:\n                {\n                    break;\n                }\n            }\n            break;\n        }\n        case WM_PAINT:\n        {\n            PAINTSTRUCT ps = {0};\n            HDC hdc = BeginPaint(hWnd, &amp;ps);\n            TextOut(hdc, 10, 10, L&quot;\u4f60\u597d\uff0c\u4e16\u754c\uff01&quot;, wcslen(L&quot;\u4f60\u597d\uff0c\u4e16\u754c\uff01&quot;));\n            EndPaint(hWnd, &amp;ps);\n            break;\n        }\n        case WM_CLOSE:\n        {\n            DestroyWindow(hWnd);\n            break;\n        }\n        case WM_DESTROY:\n        {\n            PostQuitMessage(0);\n            break;\n        }\n        default:\n        {\n            return DefWindowProc(hWnd, msg, wParam, lParam);\n        }\n    }\n    return 0;\n}\n\nint WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPreHinstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)\n{\n    PCWSTR window_class_name = L&quot;Desktop&quot;;\n    WNDCLASSEX wc = {0};\n    wc.cbSize = sizeof(WNDCLASSEX);\n    wc.hInstance = hInstance;\n    wc.lpfnWndProc = WndProc;\n    wc.lpszClassName = window_class_name;\n\n    if (!RegisterClassEx(&amp;wc))\n    {\n        MessageBox(NULL, L&quot;\u6ce8\u518c\u7a97\u53e3\u7c7b\u5931\u8d25\uff01&quot;, L&quot;\u9519\u8bef&quot;, MB_OK);\n        return 1;\n    }\n\n    HMENU hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));\n    g_popup = GetSubMenu(hMenu, 2);\n\n    HWND hWnd = CreateWindowEx(0, window_class_name, L&quot;\u7b80\u5355\u7a97\u53e3\u7a0b\u5e8f&quot;, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 200, NULL, hMenu, hInstance, NULL);\n    if (!hWnd)\n    {\n        MessageBox(NULL, L&quot;\u521b\u5efa\u7a97\u53e3\u5931\u8d25\uff01&quot;, L&quot;\u9519\u8bef&quot;, MB_OK);\n        return 1;\n    }\n\n    ShowWindow(hWnd, nCmdShow);\n    UpdateWindow(hWnd);\n\n    HACCEL hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR1)); \/\/ \u52a0\u8f7d\u52a0\u901f\u952e\u8d44\u6e90\u6587\u4ef6\n    MSG msg = {0};\n    while (GetMessage(&amp;msg, NULL, 0, 0))\n    {\n        TranslateAccelerator(hWnd, hAccel, &amp;msg); \/\/ \u7ffb\u8bd1\u52a0\u901f\u952e\n        TranslateMessage(&amp;msg);\n        DispatchMessage(&amp;msg);\n    }\n    return (int)msg.wParam;\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1675009869771.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 301px; --smush-placeholder-aspect-ratio: 301\/224;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1675009882558.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 300px; --smush-placeholder-aspect-ratio: 300\/239;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1675009910943.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 297px; --smush-placeholder-aspect-ratio: 297\/216;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/01\/image-1675009924616.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 310px; --smush-placeholder-aspect-ratio: 310\/215;\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73af\u5883 Windows 11 \u4e13\u4e1a\u5de5\u4f5c\u7ad9\u7248 22H2 Visual Studio 2022 \u4e13\u4e1a\u7248 Unicod [&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":"","_lmt_disable":"","footnotes":""},"categories":[1,593],"tags":[],"class_list":["post-8578","post","type-post","status-publish","format-standard","hentry","category-all","category-windows-api"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/8578","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=8578"}],"version-history":[{"count":0,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/8578\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}