在VC下创建不规则窗口非常简单,无非就是创建一个HRGN,然后再调用SetWindowRgn就行了,如我们要创建一个原形的窗口只需要如下代码:

CRgn rgn;

rgn.CreateEllipticRgn( 100,100, 200, 200 );

SetWindowRgn((HRGN)rgn, TRUE);

本文中的例子为一个透明位图不规则窗口,其主要函数如下:

void CExampleDlg::SetupRegion(CDC *pDC)
{
       CDC                     memDC;
       CBitmap                &cBitmap=m_bmpDraw;
       CBitmap*              pOldMemBmp = NULL;
       COLORREF          col,colMask;
       CRect                    cRect;
       int                        x, y;
       CRgn                    wndRgn, rgnTemp;
       GetWindowRect(&cRect);
       CPoint ptOrg=cRect.TopLeft();
       BITMAP bmInfo;
       cBitmap.GetObject(sizeof(bmInfo),&bmInfo);
       CRect rcNewWnd=CRect(ptOrg,CSize(bmInfo.bmWidth,bmInfo.bmHeight));
       memDC.CreateCompatibleDC(pDC);
       pOldMemBmp = memDC.SelectObject(&cBitmap);
       colMask=memDC.GetPixel(0,0);
       wndRgn.CreateRectRgn(0, 0, rcNewWnd.Width(), rcNewWnd.Height());
       for(x=0; x<=rcNewWnd.Width(); x++)
       {
              for(y=0; y<=rcNewWnd.Height(); y++)
              {
                     col = memDC.GetPixel(x, y);
                     if(col == colMask)
                     {
                            rgnTemp.CreateRectRgn(x, y, x+1, y+1);
                            wndRgn.CombineRgn(&wndRgn, &rgnTemp, RGN_XOR);
                            rgnTemp.DeleteObject();      
                     }
              }
       }
       memDC.SelectObject(pOldMemBmp);
       SetWindowRgn((HRGN)wndRgn, TRUE);
}

相关文章:

  • 2021-06-22
  • 2021-07-15
  • 2022-12-23
  • 2022-12-23
  • 2021-07-01
  • 2022-12-23
  • 2021-12-19
  • 2021-11-21
猜你喜欢
  • 2021-12-12
  • 2022-01-02
  • 2022-12-23
  • 2021-07-05
  • 2022-12-23
  • 2022-01-16
相关资源
相似解决方案