{"id":35740,"date":"2025-06-27T15:40:13","date_gmt":"2025-06-27T07:40:13","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=35740"},"modified":"2025-06-27T15:40:13","modified_gmt":"2025-06-27T07:40:13","slug":"%e5%88%b6%e4%bd%9cexe%e5%bc%b9%e7%aa%97%e8%a6%81%e6%b3%a8%e6%84%8f%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/35740\/","title":{"rendered":"\u5236\u4f5cexe\u5f39\u7a97\u8981\u6ce8\u610f\u4ec0\u4e48\uff1f"},"content":{"rendered":"

\u5236\u4f5cexe\u5f39\u7a97\uff0c\u662f\u6307\u901a\u8fc7\u7f16\u5199\u7a0b\u5e8f\uff0c\u5236\u4f5c\u51fa\u4e00\u4e2a\u5f39\u7a97\u7a97\u53e3\uff0c\u7528\u4e8e\u5728Windows\u7cfb\u7edf\u4e0a\u663e\u793a\u4e00\u4e9b\u4fe1\u606f\u6216\u8005\u63d0\u793a\u7528\u6237\u8fdb\u884c\u67d0\u4e9b\u64cd\u4f5c\u3002\u4e0b\u9762\u5c06\u4e3a\u5927\u5bb6\u4ecb\u7ecd\u5236\u4f5cexe\u5f39\u7a97\u7684\u539f\u7406\u548c\u8be6\u7ec6\u6b65\u9aa4\u3002<\/p>\n

\u4e00\u3001\u539f\u7406<\/p>\n

\u5236\u4f5cexe\u5f39\u7a97\u7684\u539f\u7406\u662f\u4f7f\u7528Windows API\u6765\u521b\u5efa\u4e00\u4e2a\u7a97\u53e3\uff0c\u5e76\u5728\u7a97\u53e3\u4e2d\u663e\u793a\u4e00\u4e9b\u4fe1\u606f\u3002Windows API\u662fWindows\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\u4e00\u7ec4\u53ef\u7f16\u7a0b\u63a5\u53e3\uff0c\u53ef\u4ee5\u8ba9\u5f00\u53d1\u8005\u901a\u8fc7\u7f16\u5199\u7a0b\u5e8f\u6765\u8bbf\u95ee\u64cd\u4f5c\u7cfb\u7edf\u7684\u5e95\u5c42\u529f\u80fd\uff0c\u4ece\u800c\u5b9e\u73b0\u5404\u79cd\u529f\u80fd\u3002<\/p>\n

\u5728\u5236\u4f5cexe\u5f39\u7a97\u65f6\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528Windows API\u4e2d\u7684CreateWindow\u51fd\u6570\u6765\u521b\u5efa\u4e00\u4e2a\u7a97\u53e3\uff0c\u5e76\u4f7f\u7528MessageBox\u51fd\u6570\u6765\u5728\u7a97\u53e3\u4e2d\u663e\u793a\u4fe1\u606f\u3002CreateWindow\u51fd\u6570\u53ef\u4ee5\u521b\u5efa\u5404\u79cd\u7c7b\u578b\u7684\u7a97\u53e3\uff0c\u5305\u62ec\u5f39\u7a97\u7a97\u53e3\uff0c\u800cMessageBox\u51fd\u6570\u5219\u53ef\u4ee5\u5728\u7a97\u53e3\u4e2d\u663e\u793a\u4e00\u4e9b\u63d0\u793a\u4fe1\u606f\u6216\u8005\u8b66\u544a\u4fe1\u606f\u3002<\/p>\n

\u4e8c\u3001\u6b65\u9aa4<\/p>\n

\u4ee5\u4e0b\u662f\u5236\u4f5cexe\u5f39\u7a97\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n

1. \u7f16\u5199\u4ee3\u7801<\/p>\n

\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u4ee3\u7801\u7f16\u8f91\u5668\u6765\u7f16\u5199\u4e00\u4e2aC\u6216C++\u7a0b\u5e8f\uff0c\u8be5\u7a0b\u5e8f\u4f7f\u7528Windows API\u6765\u521b\u5efa\u4e00\u4e2a\u7a97\u53e3\uff0c\u5e76\u5728\u7a97\u53e3\u4e2d\u663e\u793a\u4e00\u4e9b\u4fe1\u606f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u7a0b\u5e8f\uff1a<\/p>\n

“`c<\/p>\n

#include <\/p>\n

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, <\/p>\n

LPSTR lpCmdLine, int nCmdShow)<\/p>\n

{<\/p>\n

MessageBox(NULL, “Hello, World!”, “My App”, MB_OK);<\/p>\n

\u8f6f\u4ef6\u5c01\u88c5\u5de5\u5177<\/a><\/p>\n

return 0;<\/p>\n

}<\/p>\n

“`<\/p>\n

\u8be5\u7a0b\u5e8f\u4f7f\u7528\u4e86Windows API\u4e2d\u7684<\/p>\n

<\/figure>\n<\/p>\n

MessageBox\u51fd\u6570\u6765\u5728\u7a97\u53e3\u4e2d\u663e\u793a\u4e00\u6761\u6d88\u606f\u3002MessageBox\u51fd\u6570\u6709\u56db\u4e2a\u53c2\u6570\uff1a\u7b2c\u4e00\u4e2a\u53c2\u6570\u6307\u5b9a\u4e86\u7a97\u53e3\u7684\u53e5\u67c4\uff0c\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528NULL\u8868\u793a\u6ca1\u6709\u7236\u7a97\u53e3\uff1b\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u8981\u663e\u793a\u7684\u6d88\u606f\u5185\u5bb9\uff1b\u7b2c\u4e09\u4e2a\u53c2\u6570\u662f\u7a97\u53e3\u7684\u6807\u9898\uff1b\u7b2c\u56db\u4e2a\u53c2\u6570\u662f\u6d88\u606f\u6846\u7684\u7c7b\u578b\uff0c\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528\u4e86MB_OK\u8868\u793a\u53ea\u6709\u4e00\u4e2a\u201c\u786e\u5b9a\u201d\u6309\u94ae\u7684\u6d88\u606f\u6846\u3002<\/p>\n

2. \u7f16\u8bd1\u7a0b\u5e8f<\/p>\n

\u7f16\u5199\u5b8c\u7a0b\u5e8f\u540e\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u7f16\u8bd1\u5668\u5c06\u7a0b\u5e8f\u7f16\u8bd1\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u5e38\u7528\u7684\u7f16\u8bd1\u5668\u6709Visual Studio\u548cMinGW\u7b49\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528MinGW\u7f16\u8bd1\u7a0b\u5e8f\u7684\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

gcc -o myapp.exe myapp.c -mwindows<\/p>\n

“`<\/p>\n

\u8be5\u547d\u4ee4\u5c06myapp.c\u6587\u4ef6\u7f16\u8bd1\u6210myapp.exe\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5e76\u4f7f\u7528-mwindows\u53c2\u6570\u6765\u6307\u5b9a\u7a0b\u5e8f\u5e94\u8be5\u4ee5Windows\u5b50\u7cfb\u7edf\u8fd0\u884c\u3002<\/p>\n

3. \u8fd0\u884c\u7a0b\u5e8f<\/p>\n

\u7f16\u8bd1\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5728Windows\u7cfb\u7edf\u4e0a\u8fd0\u884cmyapp.exe\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u6b64\u65f6\u5c31\u4f1a\u5f39\u51fa\u4e00\u4e2a\u7a97windowsbootstrap\u6253\u5305<\/a>\u53e3\uff0c\u663e\u793a\u4e00\u6761\u6d88\u606f\u3002<\/p>\n

\u4e09\u3001\u6ce8\u610f\u4e8b\u9879<\/p>\n

\u5728\u5236\u4f5cexe\u5f39\u7a97\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n

1. \u7a97\u53e3\u7684\u5927\u5c0f\u548c\u4f4d\u7f6e\u53ef\u4ee5\u4f7f\u7528CreateWindow\u51fd\u6570\u7684\u53c2\u6570\u6765\u6307\u5b9a\u3002<\/p>\n

2. \u6d88\u606f\u6846\u7684\u7c7b\u578b\u53ef\u4ee5\u4f7f\u7528MessageBox\u51fd\u6570\u7684\u53c2\u6570\u6765\u6307\u5b9a\uff0c\u5e38\u7528\u7684\u7c7b\u578b\u6709MB_OK\u3001MB_YESNO\u3001MB_ICONWARNING\u7b49\u3002<\/p>\n

3. \u7a0b\u5e8f\u9700\u8981\u4ee5Windows\u5b50\u7cfb\u7edf\u8fd0\u884c\uff0c\u5426\u5219\u65e0\u6cd5\u4f7f\u7528Windows API\u6765\u521b\u5efa\u7a97\u53e3\u3002<\/p>\n

4. \u7a0b\u5e8f\u9700\u8981\u5305\u542bWindows.h\u5934\u6587\u4ef6\uff0c\u5426\u5219\u65e0\u6cd5\u4f7f\u7528Windows API\u7684\u51fd\u6570\u3002<\/p>\n

\u603b\u4e4b\uff0c\u5236\u4f5cexe\u5f39\u7a97\u9700\u8981\u4f7f\u7528Windows API\u6765\u521b\u5efa\u7a97\u53e3\uff0c\u5e76\u5728\u7a97\u53e3\u4e2d\u663e\u793a\u4e00\u4e9b\u4fe1\u606f\u3002\u901a\u8fc7\u7f16\u5199\u7a0b\u5e8f\uff0c\u5e76\u4f7f\u7528\u7f16\u8bd1\u5668\u5c06\u7a0b\u5e8f\u7f16\u8bd1\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5c31\u53ef\u4ee5\u5728Windows\u7cfb\u7edf\u4e0a\u8fd0\u884c\u8be5\u7a0b\u5e8f\uff0c\u4ece\u800c\u5b9e\u73b0\u5f39\u7a97\u7684\u6548\u679c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5236\u4f5cexe\u5f39\u7a97\uff0c\u662f\u6307\u901a\u8fc7\u7f16\u5199\u7a0b\u5e8f\uff0c\u5236\u4f5c\u51fa\u4e00\u4e2a\u5f39\u7a97\u7a97\u53e3\uff0c\u7528\u4e8e\u5728Windows\u7cfb\u7edf\u4e0a\u663e\u793a\u4e00\u4e9b\u4fe1\u606f\u6216\u8005\u63d0\u793a\u7528\u6237\u8fdb\u884c\u67d0\u4e9b\u64cd\u4f5c\u3002\u4e0b\u9762\u5c06\u4e3a\u5927\u5bb6\u4ecb\u7ecd\u5236\u4f5cexe\u5f39\u7a97\u7684\u539f\u7406\u548c\u8be6\u7ec6\u6b65\u9aa4\u3002\u4e00\u3001\u539f\u7406\u5236\u4f5cexe\u5f39\u7a97\u7684\u539f\u7406\u662f\u4f7f<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[29010,3515,29011,89,2095],"topic":[],"class_list":["post-35740","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-apkexe","tag-3515","tag-exe","tag-89","tag-2095"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/35740","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=35740"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/35740\/revisions"}],"predecessor-version":[{"id":35778,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/35740\/revisions\/35778"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=35740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=35740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=35740"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=35740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}