{"id":140,"date":"2008-06-26T09:24:14","date_gmt":"2008-06-26T01:24:14","guid":{"rendered":"\/wp\/post\/140.html"},"modified":"2008-06-26T09:24:14","modified_gmt":"2008-06-26T01:24:14","slug":"vc%e4%b8%adpicture-control%e9%80%8f%e6%98%8e%e8%83%8c%e6%99%af%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/lordong.xyz\/wp\/post\/140.html","title":{"rendered":"VC\u4e2dPicture Control\u900f\u660e\u80cc\u666f\u5b9e\u73b0"},"content":{"rendered":"<p>\u5728VC\u4e2d\u4f7f\u7528Picture Control\u6765\u653e\u7f6e\u56fe\u7247\u65f6\u60f3\u505a\u6210\u900f\u660e\u80cc\u666f\u7684\uff0c\u9009\u62e9Bitmap\u7c7b\u578b\u65f6\u662f\u56fe\u7247\u539f\u6837\u663e\u793a\u51fa\u6765\u7684\uff0c\u60f3\u505a\u6210\u900f\u660e\u7684Icon\u7136\u540e\u5728Picture Control\u4e2d\u9009\u62e9Icon\u7c7b\u578b\uff0c\u53ef\u662f\u63a7\u4ef6\u7f29\u6210\u4e86\u4e00\u4e2a\u56fe\u6807\u3002\u6700\u540e\u53ea\u80fd\u9009\u62e9Bitmap\u7c7b\u578b\uff0c\u56e0\u4e3a\u7528\u8fd9\u79cd\u6a21\u5f0f\u53ef\u4ee5\u628a\u5f88\u591a\u56fe\u7247\u4f7f\u7528\u591a\u4e2aPicture Control\u7ec4\u5408\u8d77\u6765\u3002<\/p>\n<p>\u5728\u7f51\u4e0a\u627e\u4e86\u4e00\u4e9b\u8d44\u6599\uff0c\u7ecf\u8fc7\u81ea\u5df1\u591a\u65b9\u7684\u5b9e\u9a8c\uff0c\u7ec8\u4e8e\u53ef\u4ee5\u641e\u5b9a\u3002<\/p>\n<p>\u539f\u7406\u662f\u91cd\u8f7dPicture Control\uff0c\u5728\u7a97\u4f53\u521d\u59cb\u5316\u65f6\u7ed9\u63a7\u4ef6\u8bbe\u7f6e\u56fe\u7247ID\uff0c\u5e76\u53bb\u6389\u63a7\u4ef6\u7684Bitmap\u7c7b\u578b\uff0c\u5373\u8bbe\u7f6e\u6210&ldquo;\u65e0&rdquo;\u7c7b\u578b\uff0c\u7136\u540e\u5728OnPaint\u65b9\u6cd5\u4e2d\u91cd\u753b\u56fe\u7247\u3002<\/p>\n<p>\u5904\u7406\u6b65\u9aa4\u662f\uff1a<br \/>1. Picture Control\u4ecd\u4f7f\u7528Bitmap\u7c7b\u578b\uff0c\u9009\u62e9\u6b63\u786e\u7684\u56fe\u7247\u5e76\u5e03\u5c40\u597d\u3002<br \/>2. \u5728\u7a97\u4f53\u521d\u59cb\u5316\u65f6\u7ed9\u63a7\u4ef6\u8bbe\u7f6e\u5177\u4f53\u7684\u56fe\u7247ID\u3002<\/p>\n<p>\u91cd\u8f7d\u7684\u7c7b\u6e90\u7801<font size=\"3\"><strong>.h\u6587\u4ef6\uff1a<\/strong><\/font><br \/>#pragma once<\/p>\n<p>class CTransparentPic : public CStatic<br \/>{<br \/>&nbsp;DECLARE_DYNAMIC(CTransparentPic)<\/p>\n<p>public:<br \/>&nbsp;CTransparentPic();<br \/>&nbsp;virtual ~CTransparentPic();<\/p>\n<p>&nbsp;void SetBitmapIndex(UINT nBitmapIndex);<\/p>\n<p>protected:<br \/>&nbsp;DECLARE_MESSAGE_MAP()<\/p>\n<p>public:<br \/>&nbsp;afx_msg BOOL OnEraseBkgnd(CDC* pDC);<br \/>&nbsp;afx_msg void OnPaint();<\/p>\n<p>private:<br \/>&nbsp;UINT m_nBitmapIndex;&nbsp;\/\/ Bitmap index of resource<br \/>};<\/p>\n<p><font size=\"3\"><strong>.cpp\u6587\u4ef6\uff1a<br \/><\/strong><\/font>#include &quot;stdafx.h&quot;<br \/>#include &quot;TransparentPic.h&quot;<\/p>\n<p>IMPLEMENT_DYNAMIC(CTransparentPic, CStatic)<\/p>\n<p>CTransparentPic::CTransparentPic()<br \/>&nbsp;: m_nBitmapIndex(0)<br \/>{<br \/>}<\/p>\n<p>CTransparentPic::~CTransparentPic()<br \/>{<br \/>}<\/p>\n<p>BEGIN_MESSAGE_MAP(CTransparentPic, CStatic)<br \/>&nbsp;ON_WM_ERASEBKGND()<br \/>&nbsp;ON_WM_PAINT()<br \/>END_MESSAGE_MAP()<\/p>\n<p>void CTransparentPic::SetBitmapIndex(UINT nBitmapIndex)<br \/>{<br \/>&nbsp;ModifyStyle(SS_BITMAP, 0);&nbsp;&nbsp;\/\/ Remove bitmap style, use owner paint<\/p>\n<p>&nbsp;bool bForceRedraw = (m_nBitmapIndex != nBitmapIndex);<\/p>\n<p>&nbsp;m_nBitmapIndex = nBitmapIndex;<\/p>\n<p>&nbsp;\/\/ Force owner paint<br \/>&nbsp;if (::IsWindow(m_hWnd) &amp;&amp; bForceRedraw)<br \/>&nbsp;{<br \/>&nbsp;&nbsp;Invalidate();<br \/>&nbsp;}<br \/>}<\/p>\n<p>\/\/ CTransparentPic message handlers<br \/>BOOL CTransparentPic::OnEraseBkgnd(CDC* pDC)<br \/>{<br \/>&nbsp;return TRUE;<br \/>}<\/p>\n<p>void CTransparentPic::OnPaint()<br \/>{<br \/>&nbsp;CWnd::Default();&nbsp;\/\/ Calls the default window procedure<\/p>\n<p>&nbsp;CClientDC dc(this);<br \/>&nbsp;CBitmap bmp;<\/p>\n<p>&nbsp;\/\/ Try to load bitmap<br \/>&nbsp;if (bmp.LoadBitmap(m_nBitmapIndex))<br \/>&nbsp;{<br \/>&nbsp;&nbsp;CDC memDC;<\/p>\n<p>&nbsp;&nbsp;memDC.CreateCompatibleDC(NULL);<\/p>\n<p>&nbsp;&nbsp;CBitmap* pOldBmp = memDC.SelectObject(&amp;bmp);<br \/>&nbsp;&nbsp;BITMAP bitmap;<\/p>\n<p>&nbsp;&nbsp;bmp.GetBitmap(&amp;bitmap);<br \/>&nbsp;&nbsp;TransparentBlt(dc.m_hDC, 0, 0, bitmap.bmWidth, bitmap.bmHeight, <br \/>&nbsp;&nbsp;&nbsp;memDC.m_hDC, 0, 0, bitmap.bmWidth, bitmap.bmHeight, RGB(236, 233, 216));<\/p>\n<p>&nbsp;&nbsp;memDC.SelectObject(pOldBmp);<br \/>&nbsp;&nbsp;memDC.DeleteDC();<br \/>&nbsp;}<br \/>&nbsp;else<br \/>&nbsp;{<br \/>&nbsp;&nbsp;\/\/ Draw error information<br \/>&nbsp;&nbsp;dc.TextOut(1, 1, _T(&quot;ERROR!&quot;));<br \/>&nbsp;}<br \/>}<br \/><strong>\u8bf4\u660e\u4e00\u4e0b\uff1a<\/strong>\u4e0a\u9762\u7684RGB(236, 233, 216)\u6307\u7684\u662f\u5236\u4f5c\u56fe\u7247\u65f6\u4ee5\u8be5\u989c\u8272\u503c\u4f5c\u4e3a\u80cc\u666f\u8272\uff08\u8981\u6539\u4e00\u8d77\u6539\uff09\uff0cTransparentBit\u65b9\u6cd5\u5728\u5904\u7406\u65f6\u81ea\u52a8\u628a\u8fd9\u4e9b\u989c\u8272\u503c\u8fc7\u6ee4\u6389\uff0c\u770b\u8d77\u6765\u5c31\u662f\u900f\u660e\u7684\u3002<\/p>\n<p>\u7136\u540e\u7ed9Picture Control\u6307\u5b9a\u4e00\u4e2aID\uff0c\u5728\u5bf9\u8bdd\u6846\u7684.h\u6587\u4ef6\u4e2d\u5b9a\u4e49CTransparentPic\u5bf9\u8c61\uff1a<br \/>&nbsp;CTransparentPic m_ctrlPic1;<\/p>\n<p>\u63a5\u7740\u5728\u5bf9\u8bdd\u6846.cpp\u6587\u4ef6\u7684DoDataExchange\u65b9\u6cd5CDialog::DoDataExchange\u4e4b\u540e\u52a0\u4e00\u9879\u5b8c\u6210\u5173\u8054\uff1a<br \/>&nbsp;CDialog::DoDataExchange(pDX);<br \/>&nbsp;DDX_Control(pDX, IDC_BITMAP1, m_ctrlPic1);<\/p>\n<p>\u6700\u540e\u5728\u5bf9\u8bdd\u6846\u7684OnInitDialog\u52a0\u4e00\u9879\u8bbe\u7f6e\u56fe\u7247ID\u9879\uff1a<br \/>&nbsp;m_ctrlPic1.SetBitmapIndex(IDB_BITMAP1);<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728VC\u4e2d\u4f7f\u7528Picture Control\u6765\u653e\u7f6e\u56fe\u7247\u65f6\u60f3\u505a\u6210\u900f\u660e\u80cc\u666f\u7684\uff0c\u9009\u62e9Bitmap\u7c7b\u578b\u65f6\u662f\u56fe\u7247\u539f\u6837\u663e\u793a\u51fa [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[36],"class_list":["post-140","post","type-post","status-publish","format-standard","hentry","category-6","tag-cc"],"_links":{"self":[{"href":"https:\/\/lordong.xyz\/wp\/wp-json\/wp\/v2\/posts\/140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lordong.xyz\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lordong.xyz\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lordong.xyz\/wp\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/lordong.xyz\/wp\/wp-json\/wp\/v2\/comments?post=140"}],"version-history":[{"count":0,"href":"https:\/\/lordong.xyz\/wp\/wp-json\/wp\/v2\/posts\/140\/revisions"}],"wp:attachment":[{"href":"https:\/\/lordong.xyz\/wp\/wp-json\/wp\/v2\/media?parent=140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lordong.xyz\/wp\/wp-json\/wp\/v2\/categories?post=140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lordong.xyz\/wp\/wp-json\/wp\/v2\/tags?post=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}