Posted on 2010-08-11 15:54
S.l.e!ep.¢% 阅读(918)
评论(0) 编辑 收藏 引用 所属分类:
VC 、
DirectUI
void CSemiTransWnd::Update(long type,POINT *pTopLeft)
{
if(m_hWnd&&m_iWidth&&m_iHeight&&m_pdwRGBAData&&m_pDC&&m_pBmp)//指针正确
{ //获取屏幕DC
CDC dcScreen;
dcScreen.Attach(::GetDC(NULL)); //处理Alpha 通道
DealAlphaChannel();
CRect rectDlg;
GetWindowRect(m_hWnd,&rectDlg);
CPoint ptWindowScreenPosition(rectDlg.TopLeft());
if(pTopLeft)
{
ptWindowScreenPosition.x=pTopLeft->x;
ptWindowScreenPosition.y=pTopLeft->y;
} //刷新到屏幕上
CSize szWindow(m_iWidth, m_iHeight);
CPoint ptSrc(0,0);
int alpha;
switch(type)
{
case 2: //淡出
for(alpha=m_iWndSemiTransAlpha;alpha>=0;alpha--)
{
BLENDFUNCTION blendPixelFunction= { AC_SRC_OVER, 0, alpha,AC_SRC_ALPHA };
UpdateLayeredWindow(m_hWnd, dcScreen, &ptWindowScreenPosition, &szWindow, *m_pDC,&ptSrc, 0, &blendPixelFunction, ULW_ALPHA);
}
break;
case 1: //淡入
for(alpha=0;alpha<=m_iWndSemiTransAlpha;alpha++)
{
BLENDFUNCTION blendPixelFunction= { AC_SRC_OVER, 0, alpha,AC_SRC_ALPHA };
UpdateLayeredWindow(m_hWnd, dcScreen, &ptWindowScreenPosition, &szWindow, *m_pDC,&ptSrc, 0, &blendPixelFunction, ULW_ALPHA);
}
break;
case 0: //直接刷新
default:
BLENDFUNCTION blendPixelFunction= { AC_SRC_OVER, 0, m_iWndSemiTransAlpha,AC_SRC_ALPHA };
UpdateLayeredWindow(m_hWnd, dcScreen, &ptWindowScreenPosition, &szWindow, *m_pDC,&ptSrc, 0, &blendPixelFunction, ULW_ALPHA);
break;
}
}//end if } 空 气 15:12:25 // 处理Alpha通道 处理用户绘制部分的不透明度
void CSemiTransWnd::DealAlphaChannel(void)
{
if(m_pdwRGBAData&&m_pBmp) //指针正确
{ if(m_bSemiTransAlphaUpdate||m_bTransAlphaUpdate)//需要处理Alpha
{ //获取位图数据
BITMAP bmpInfo;
m_pBmp->GetBitmap(&bmpInfo);
BYTE *rgba = (BYTE*)bmpInfo.bmBits;
BYTE *rgbb = (BYTE*)m_pdwRGBAData;
long i;
for(i=0;i<bmpInfo.bmHeight*bmpInfo.bmWidth;i++)
{
if(rgba[0]!=rgbb[0]||rgba[1]!=rgbb[1]||rgba[2]!=rgbb[2]) //颜色不同
{
if((rgbb[3] == 0x00 && m_bTransAlphaUpdate)|| //透明Alpha值更新
(rgbb[3] != 0x00 && m_bSemiTransAlphaUpdate)) //半透明 Alpha值更新
{ //
rgba[3]=0xFF;
}
rgba+=4;
rgbb+=4;
}
}
}
}
}