{"id":81,"date":"2017-07-29T23:53:53","date_gmt":"2017-07-29T17:53:53","guid":{"rendered":"https:\/\/qtvz.com\/?p=81"},"modified":"2017-09-11T21:31:18","modified_gmt":"2017-09-11T15:31:18","slug":"%e7%94%a8mfc%e5%88%b6%e4%bd%9c%e7%a8%8b%e5%ba%8f%e5%90%af%e5%8a%a8logo","status":"publish","type":"post","link":"https:\/\/qtvz.com\/81.html","title":{"rendered":"\u7528MFC\u5236\u4f5c\u7a0b\u5e8f\u542f\u52a8LOGO"},"content":{"rendered":"<!--wp-compress-html--><!--wp-compress-html no compression--><p>\u6536\u85cf\uff01<\/p>\n<p>\u65b0\u5efamfc\u5de5\u7a0b\uff0c\u628a\u5236\u4f5c\u597d\u7684logo\u4f4d\u56fe\u6dfb\u52a0\u7684\u8d44\u6e90\u4e2d\u53bb\uff0c\u8d44\u6e90ID\u53f7\u8bbe\u7f6e\u4e3aIDB_SPLASH\u3002<\/p>\n<p>\u65b0\u5efa\u7c7bCSplashWnd\uff0c<\/p>\n<pre class=\"lang:default decode:true \">#pragma once\r\n#include \"afxwin.h\"\r\n\r\nclass CSplashWnd :\r\n\tpublic CWnd\r\n{\r\npublic:\r\n\tCSplashWnd(void);\r\n\t~CSplashWnd(void);\r\n\tCBitmap m_bitmap;\r\n\tstatic void ShowSplashScreen(CWnd* pParentWnd = NULL);\r\nprotected:\r\n\tBOOL Create(CWnd* pParentWnd = NULL);\t\r\n\tstatic CSplashWnd* c_pSplashWnd;\r\npublic:\r\n\tDECLARE_MESSAGE_MAP()\r\n\tafx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);\r\n\tafx_msg void OnPaint();\r\n\tafx_msg void OnTimer(UINT_PTR nIDEvent);\r\n};\r\n<\/pre>\n<p>\u4e3a\u5404\u6210\u5458\u51fd\u6570\u6dfb\u52a0\u4ee3\u7801\uff1a<\/p>\n<pre class=\"lang:default decode:true \">#include \"StdAfx.h\"\r\n#include \"SplashWnd.h\"\r\n#include \"resource.h\"\r\n\r\nCSplashWnd* CSplashWnd::c_pSplashWnd;\r\n\r\nBEGIN_MESSAGE_MAP(CSplashWnd, CWnd)\r\n\tON_WM_CREATE()\r\n\tON_WM_PAINT()\r\n\tON_WM_TIMER()\r\nEND_MESSAGE_MAP()\r\n\r\nCSplashWnd::CSplashWnd(void)\r\n\/*: c_pSplashWnd(NULL)*\/\r\n{\r\n}\r\n\r\nCSplashWnd::~CSplashWnd(void)\r\n{\r\n}\r\n\r\nvoid CSplashWnd::ShowSplashScreen(CWnd* pParentWnd)\r\n{\r\n\tc_pSplashWnd = new CSplashWnd;\r\n\tif (!c_pSplashWnd-&gt;Create(pParentWnd))\r\n\t\tdelete c_pSplashWnd;\r\n\telse\r\n\t\tc_pSplashWnd-&gt;UpdateWindow();\r\n}\r\n\r\nBOOL CSplashWnd::Create(CWnd* pParentWnd)\r\n{\r\n\tif (!m_bitmap.LoadBitmap(IDB_SPLASH))\t\/*\u52a0\u8f7d\u4f4d\u56fe\u8d44\u6e90\uff0c\u9700\u5728\u8d44\u6e90\u6587\u4ef6\u4e2d\u6dfb\u52a0*\/\r\n\t\treturn FALSE;\r\n\r\n\tBITMAP bm;\r\n\tm_bitmap.GetBitmap(&amp;bm);\r\n\r\n\treturn CreateEx(0,\r\n\t\tAfxRegisterWndClass(0, AfxGetApp()-&gt;LoadStandardCursor(IDC_ARROW)),\r\n\t\tNULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd-&gt;GetSafeHwnd(), NULL);\r\n\treturn 0;\r\n}\r\n\r\nint CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)\r\n{\r\n\tif (CWnd::OnCreate(lpCreateStruct) == -1)\r\n\t\treturn -1;\r\n\r\n\t\/\/ TODO:  \u5728\u6b64\u6dfb\u52a0\u60a8\u4e13\u7528\u7684\u521b\u5efa\u4ee3\u7801\r\n\t\/\/ Center the window.\r\n\tCenterWindow();\r\n\r\n\t\/\/ Set a timer to destroy the splash screen.\r\n\tSetTimer(1, 1000, NULL);\t\t\t\t\/*\u8bbe\u7f6e\u6d88\u9690\u65f6\u95f4*\/\r\n\r\n\treturn 0;\r\n}\r\n\r\nvoid CSplashWnd::OnPaint()\r\n{\r\n\tCPaintDC dc(this); \/\/ device context for painting\r\n\t\/\/ TODO: \u5728\u6b64\u5904\u6dfb\u52a0\u6d88\u606f\u5904\u7406\u7a0b\u5e8f\u4ee3\u7801\r\n\t\/\/ \u4e0d\u4e3a\u7ed8\u56fe\u6d88\u606f\u8c03\u7528 CWnd::OnPaint()\r\n\tCDC dcImage;\r\n\tif (!dcImage.CreateCompatibleDC(&amp;dc))\r\n\t\treturn;\r\n\r\n\tBITMAP bm;\r\n\tm_bitmap.GetBitmap(&amp;bm);\r\n\r\n\t\/\/ Paint the image.\r\n\tCBitmap* pOldBitmap = dcImage.SelectObject(&amp;m_bitmap);\r\n\tdc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &amp;dcImage, 0, 0, SRCCOPY);\r\n\tdcImage.SelectObject(pOldBitmap);\r\n}\r\n\r\nvoid CSplashWnd::OnTimer(UINT_PTR nIDEvent)\r\n{\r\n\t\/\/ TODO: \u5728\u6b64\u6dfb\u52a0\u6d88\u606f\u5904\u7406\u7a0b\u5e8f\u4ee3\u7801\u548c\/\u6216\u8c03\u7528\u9ed8\u8ba4\u503c\r\n\tDestroyWindow();\r\n\tAfxGetMainWnd()-&gt;UpdateWindow();\r\n\r\n\tCWnd::OnTimer(nIDEvent);\r\n}<\/pre>\n<p>\u5176\u4e2d\u6d88\u9690\u65f6\u95f4\u7684\u8bbe\u7f6e\u4e3a\u4f60\u559c\u6b22\u7684\u6570\u503c\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u53ea\u9700\u5728<a href=\"https:\/\/qtvz.com\/tag\/mfc\" class=\"tag-tooltip\" data-toggle=\"tooltip\" title=\"\u67e5\u770b\u66f4\u591a\u5173\u4e8e MFC \u7684\u6587\u7ae0\" target=\"_blank\">MFC<\/a>\u5de5\u7a0b\u4e2d\u7684CMainFrame\u7c7b\u4e2d\u6dfb\u52a0\u51fd\u6570OnCreate\uff0c\u5e76\u5728\u51fd\u6570\u5b9a\u4e49\u4e2d\u6dfb\u52a0\u8bed\u53e5CSplashWnd::ShowSplashScreen(this);<\/p>\n<pre class=\"lang:default decode:true\">int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)\r\n{\r\n\tif (CFrameWnd::OnCreate(lpCreateStruct) == -1)\r\n\t\treturn -1;\r\n\r\n\t\/\/ TODO:  \u5728\u6b64\u6dfb\u52a0\u60a8\u4e13\u7528\u7684\u521b\u5efa\u4ee3\u7801\r\n\tCSplashWnd::ShowSplashScreen(this);\r\n\r\n\treturn 0;\r\n}<\/pre>\n<p>\u539f\u6587\uff1a<a href=\"http:\/\/blog.csdn.net\/yang_xian521\/article\/details\/7322619#\">http:\/\/blog.csdn.net\/yang_xian521\/article\/details\/7322619#<\/a><\/p>\n<!--wp-compress-html no compression--><!--wp-compress-html-->","protected":false},"excerpt":{"rendered":"\u6536\u85cf\uff01 \u65b0\u5efamfc\u5de5\u7a0b\uff0c\u628a\u5236\u4f5c\u597d\u7684logo\u4f4d\u56fe\u6dfb\u52a0\u7684\u8d44\u6e90\u4e2d\u53bb\uff0c\u8d44\u6e90ID\u53f7\u8bbe\u7f6e\u4e3aIDB_SPLASH\u3002 \u65b0\u5efa\u7c7bCSplashWnd\uff0c #pragma once #include &#8220;afxwin.h&#8221; c \u00b7\u00b7\u00b7","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12],"tags":[29,26],"views":10882,"_links":{"self":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts\/81"}],"collection":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/comments?post=81"}],"version-history":[{"count":1,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts\/81\/revisions"}],"predecessor-version":[{"id":82,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts\/81\/revisions\/82"}],"wp:attachment":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/media?parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/categories?post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/tags?post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}