| ///////////////////////////////////////////////////////////////////////////// // 获得窗体矩形 CRect rectWnd; this->GetWindowRect(rectWnd); // 读取"掩模"位图资源 CBitmap myBitmap,*pOldBitmap; myBitmap.LoadBitmap(nMaskId); // 创建"内存一致"设备 CDC memDC; memDC.CreateCompatibleDC(pDC); // 选择绘图设备 pOldBitmap = memDC.SelectObject(&myBitmap); // 创建窗体的初始区域 CRgn rgnWnd,rgnTemp; rgnWnd.CreateRectRgn(0,0,rectWnd.Width(),rectWnd.Height()); int nWidth,nHeight; COLORREF color; //下面的两层循环为检查背景位图象素颜色,进行透明区域处理; //当象素颜色为指定的透明值时,即将该点从区域中剪裁掉。 for (nWidth = 0;nWidth <= rectWnd.Width()-1;nWidth++) { for (nHeight = 0;nHeight <= rectWnd.Height();nHeight++) { color = memDC.GetPixel(nWidth,nHeight); // 当象素是白色时,去掉该点 if (color == RGB(255,255,255)) { //象素颜色为指定的透明色,创建透明"微区域" rgnTemp.CreateRectRgn(nWidth,nHeight,nWidth+1,nHeight+1); //"扣像",从完整的区域中"扣除"透明的"微区域" rgnWnd.CombineRgn(&rgnWnd,&rgnTemp,RGN_XOR); //删除刚创建的透明"微区域",释放系统资源 rgnTemp.DeleteObject(); } } } memDC.SelectObject(pOldBitmap); SetWindowRgn((HRGN)rgnWnd,TRUE); //用最终设定窗口的显示区域为指定区域 |
关注此文的读者还看过: