建立不规则窗体的主要代码

void Tranc(void)
{
    CDC MemDC,*pDC=NULL;//当前窗体设备和临时设备
    CRect rcWnd;//当前窗体矩形范围
    COLORREF bgColor,curColor;//背景色和当前指针处颜色
    int x,y;窗口矩形的行和列
    CBitmap bmp;    
    CRng WndRgn,tmpRgn;//窗体范围和临时范围变量

    pDC=this->GetDC();//取得当前窗体设备
    this->GetWindowRect(&rcWnd);//取得当前窗体的范围
    MemDC.CreateCompatibleDC(pDC);
    bmp.LoadBitmap(IDB_BACKGROUND);//载入背景图片
    bmp.SelectObject(&bmp);//载入图片对象
    bgColor=MemDC.GetPixel(0,0);//取得背景色
    WndRgn.CreateRectRgn(0,0,rcWnd.Width(),rcWnd.Height());
    
    for(x=0;x<rcWnd.Width();x++)
        for(y=0;y<rcWnd.Height();y++)
            {
            curColor=MemDC.GetPixel(x,y);
            if(curColor==bgColor)
                {
                tmpRgn.CreateRectRgn(x,y,x+1,y+1);//建立1*1的范围
                WndRgn.CombineRgn(&WndRgn,&tmpRgn,RGN_XOR);//异或,把颜色=底色的范围去掉
                tmpRgn.DeleteObject();
                }
            }
MemDC.DeleteDC();
bmp.DeleteObject();
this.SetWindowRgn(WndRgn,TRUE);//设置当前窗体区域
}

posted on 2005-11-10 11:13  痛并快乐着  阅读(497)  评论(0编辑  收藏  举报

导航