分类: C/C++
2008-08-08 11:28:08
第一步,我们先在CalphaCtrl类中增加几个Data
Member:CBitmap Bmp;
BOOL bCanPaint; UINT nBmpID; int nTimer;
第二步,在CalphaCtrl类中增加一个Member
Function:
void AlphaDisplay(CDC &pDC, CClientDC &dc, BLENDFUNCTION& rBlendProps, int width, int heigh, byte nLevel) { //nLevel是透明度,0表示不显示,255则完全显示 rBlendProps.SourceConstantAlpha = nLevel; AlphaBlend( dc.m_hDC, 0, 0, width, heigh, pDC.m_hDC, 0, 0, width, heigh, rBlendProps ); }
第三步,增加一个名为tdDisplay的全局函数,此函数为一个线程函数,用于位图的显示。
UINT tdDisplay(LPVOID lpParam) { CAlphaCtrl* AlphaCtrl = (CAlphaCtrl*)lpParam; CClientDC dc(AlphaCtrl); CDC pDC; pDC.CreateCompatibleDC(&dc); pDC.SelectObject(&AlphaCtrl->Bmp); BLENDFUNCTION rBlendProps; rBlendProps.BlendOp = AC_SRC_OVER; rBlendProps.BlendFlags = 0; rBlendProps.AlphaFormat = 0; BITMAP bmInfo; ::GetObject( AlphaCtrl->Bmp.m_hObject, sizeof(BITMAP), &bmInfo ); INT nWidth, nHeigh; nWidth = bmInfo.bmWidth; nHeigh = bmInfo.bmHeight;AlphaCtrl->SetWindowPos(NULL, 0, 0, nWidth, nHeigh, SWP_NOMOVE); int i = 0; while(i <= 255) { AlphaCtrl->AlphaDisplay(pDC, dc, rBlendProps, nWidth, nHeigh, i); i = 5; Sleep(AlphaCtrl->nTimer); } AlphaCtrl->bCanPaint = 1; //Make OnPaint Word AfxEndThread(0); return 0; }
第四步,现在万事俱备,加上初始化函数:
BOOL LoadAlphaBitmap(UINT uID, int iTimer) { int i = Bmp.LoadBitmap(uID); if(i) { AfxBeginThread(tdDisplay, this); nBmpID = uID; nTimer = iTimer; return 1; } else { TRACE("Load Bitmap Failed\n"); return 0; } return 1; }
最后,执行程序,打开你的对话框看一看那幅很酷的位图!