{"id":26094,"date":"2024-07-04T15:40:32","date_gmt":"2024-07-04T07:40:32","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=26094"},"modified":"2024-07-04T15:40:32","modified_gmt":"2024-07-04T07:40:32","slug":"%e4%bd%bf%e7%94%a8mfc%e5%bc%80%e5%8f%91%e5%ba%94%e7%94%a8%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/26094\/","title":{"rendered":"\u4f7f\u7528mfc\u5f00\u53d1\u5e94\u7528\u5982\u4f55\u5b9e\u73b0?"},"content":{"rendered":"

MFC\u662fMicrosoft Foundation Classes\u7684\u7f29\u5199\uff0c\u662f\u4e00\u7ec4C++\u7c7b\u5e93\uff0c\u7528\u4e8e\u5f00\u53d1Windows\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002MFC\u63d0\u4f9b\u4e86\u4e00\u79cd\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u6cd5\uff0c\u4f7f\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u521b\u5efaWindows\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

MFC\u63d0\u4f9b\u4e86\u8bb8\u591a\u7c7b\uff0c\u7528\u4e8e\u5904\u7406Windows GUI\uff0c\u5305\u62ec\u7a97\u53e3jlink\u751f\u6210exe<\/a>\u3001\u6309\u94ae\u3001\u5217\u8868\u6846\u3001\u5bf9\u8bdd\u6846\u7b49\u3002MFC\u8fd8\u63d0\u4f9b\u4e86\u8bb8\u591a\u7c7b\uff0c\u7528\u4e8e\u5904\u7406Windows\u6d88\u606f\uff0c\u4f8b\u5982\u9f20\u6807\u70b9\u51fb\u3001\u952e\u76d8\u8f93\u5165\u3001\u5b9a\u65f6\u5668\u7b49\u3002MFC\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e9b\u7c7b\uff0c\u7528\u4e8e\u5904\u7406\u6587\u4ef6\u64cd\u4f5c\u3001\u6570\u636e\u5e93\u8bbf\u95ee\u3001\u7f51\u7edc\u7f16\u7a0b\u7b49\u3002<\/p>\n

MFC\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u7ed3\u6784\u662f\u4e00\u4e2aWin32\u5e94\u7528\u7a0b\u5e8f\uff0c\u5305\u542b\u4e00\u4e2aWinMain\u51fd\u6570\u3001\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u7c7b\u548c\u4e00\u4e2a\u4e3b\u7a97\u53e3\u7c7b\u3002\u5e94\u7528\u7a0b\u5e8f\u7c7b\u6d3e\u751f\u81eaCWinApp\uff0c\u4e3b\u7a97\u53e3\u7c7b\u6d3e\u751f\u81eaCFrameWnd\u3002<\/p>\n

\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684MFC\u5e94\u7528\u7a0b\u5e8f\u7684\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n

“`<\/p>\n

#include <\/p>\n

class CMyApp : public CWinApp<\/p>\n

{<\/p>\n

public:<\/p>\n

virtual BOOL InitInstance();<\/p>\n

};<\/p>\n

class CMyFrameWnd : p\u7f51\u5740\u751f\u6210exe\u8f6f\u4ef6\u5f00\u53d1<\/a>ublic CFrameWnd<\/p>\n

{<\/p>\n

public:<\/p>\n

CMyFrameWnd()<\/p>\n

{<\/p>\n

Create(NULL, _T(“My MFC App”));<\/p>\n

}<\/p>\n

};<\/p>\n

BOOL CMyApp::InitInstance()<\/p>\n

{<\/p>\n

CMyFrameWnd* pFrameWnd = new CMyFrameWnd();<\/p>\n

m_pMainWnd = pFrameWnd;<\/p>\n

pFrameWnd->ShowWindow(SW_SHOW);<\/p>\n

pFrameWnd->UpdateWindow();<\/p>\n

return TRUE;<\/p>\n

}<\/p>\n

CMyApp theApp;<\/p>\n

“`<\/p>\n

\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0cCMyApp\u7c7b\u6d3e\u751f\u81eaCWinApp\uff0c\u8986\u76d6\u4e86InitInstance\u51fd\u6570\uff0c\u521b\u5efa\u4e86\u4e00\u4e2aCMyFr<\/p>\n

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

ameWnd\u5bf9\u8c61\uff0c\u5e76\u5c06\u5176\u663e\u793a\u5728\u5c4f\u5e55\u4e0a\u3002CMyFrameWnd\u7c7b\u6d3e\u751f\u81eaCFrameWnd\uff0c\u521b\u5efa\u4e86\u4e00\u4e2a\u7a97\u53e3\uff0c\u5e76\u5728\u7a97\u53e3\u6807\u9898\u680f\u4e0a\u663e\u793a\u4e86”My MFC App”\u3002<\/p>\n

MFC\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u8fc7\u7a0b\u901a\u5e38\u5305\u62ec\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n

1.\u521b\u5efa\u4e00\u4e2aMFC\u5e94\u7528\u7a0b\u5e8f\u9879\u76ee\u3002\u53ef\u4ee5\u4f7f\u7528Visual Studio\u521b\u5efa\u4e00\u4e2aMFC\u5e94\u7528\u7a0b\u5e8f\u9879\u76ee\uff0c\u9009\u62e9\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u7c7b\u578b\uff08\u4f8b\u5982\u5355\u6587\u6863\u5e94\u7528\u7a0b\u5e8f\u6216\u591a\u6587\u6863\u5e94\u7528\u7a0b\u5e8f\uff09\uff0c\u7136\u540e\u6839\u636e\u9700\u8981\u9009\u62e9\u5176\u4ed6\u9009\u9879\u3002<\/p>\n

2.\u8bbe\u8ba1\u5e94\u7528\u7a0b\u5e8f\u754c\u9762\u3002\u53ef\u4ee5\u4f7f\u7528Visual Studio\u7684\u53ef\u89c6\u5316\u8bbe\u8ba1\u5668\u6765\u8bbe\u8ba1\u5e94\u7528\u7a0b\u5e8f\u754c\u9762\uff0c\u4f8b\u5982\u6dfb\u52a0\u7a97\u53e3\u3001\u6309\u94ae\u3001\u5217\u8868\u6846\u7b49\u63a7\u4ef6\uff0c\u5e76\u8bbe\u7f6e\u5b83\u4eec\u7684\u5c5e\u6027\u3002<\/p>\n

3.\u7f16\u5199\u5e94\u7528\u7a0b\u5e8f\u4ee3\u7801\u3002\u53ef\u4ee5\u4f7f\u7528Visual Studio\u7684\u4ee3\u7801\u7f16\u8f91\u5668\u7f16\u5199\u5e94\u7528\u7a0b\u5e8f\u4ee3\u7801\uff0c\u5305\u62ec\u5904\u7406Windows\u6d88\u606f\u3001\u5904\u7406\u63a7\u4ef6\u4e8b\u4ef6\u3001\u5904\u7406\u6587\u4ef6\u64cd\u4f5c\u3001\u6570\u636e\u5e93\u8bbf\u95ee\u7b49\u3002<\/p>\n

4.\u8c03\u8bd5\u548c\u6d4b\u8bd5\u5e94\u7528\u7a0b\u5e8f\u3002\u53ef\u4ee5\u4f7f\u7528Visual Studio\u7684\u8c03\u8bd5\u5de5\u5177\u6765\u8c03\u8bd5\u548c\u6d4b\u8bd5\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f8b\u5982\u65ad\u70b9\u3001\u53d8\u91cf\u76d1\u89c6\u5668\u3001\u8c03\u7528\u5806\u6808\u7b49\u3002<\/p>\n

5.\u53d1\u5e03\u5e94\u7528\u7a0b\u5e8f\u3002\u53ef\u4ee5\u4f7f\u7528Visual Studio\u7684\u53d1\u5e03\u5411\u5bfc\u6765\u53d1\u5e03\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f8b\u5982\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3001\u521b\u5efa\u5b89\u88c5\u7a0b\u5e8f\u7b49\u3002<\/p>\n

\u603b\u4e4b\uff0c\u4f7f\u7528MFC\u5f00\u53d1\u5e94\u7528\u7a0b\u5e8f\u662f\u4e00\u79cd\u5feb\u901f\u3001\u9ad8\u6548\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u4f7f\u5f00\u53d1\u4eba\u5458\u66f4\u5bb9\u6613\u5730\u521b\u5efaWindows\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002MFC\u63d0\u4f9b\u4e86\u8bb8\u591a\u7c7b\u548c\u51fd\u6570\uff0c\u53ef\u4ee5\u5927\u5927\u7b80\u5316\u5f00\u53d1\u8fc7\u7a0b\uff0c\u5e76\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u53ef\u9760\u6027\u548c\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

MFC\u662fMicrosoft Foundation Classes\u7684\u7f29\u5199\uff0c\u662f\u4e00\u7ec4C++\u7c7b\u5e93\uff0c\u7528\u4e8e\u5f00\u53d1Windows\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002MFC\u63d0\u4f9b\u4e86\u4e00\u79cd\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u6cd5\uff0c\u4f7f\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u521b\u5efaWindows<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[25720,366,25719,12,2095],"topic":[],"class_list":["post-26094","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-phpexe","tag-366","tag-htmlexe","tag-12","tag-2095"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/26094","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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=26094"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/26094\/revisions"}],"predecessor-version":[{"id":26155,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/26094\/revisions\/26155"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=26094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=26094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=26094"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=26094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}