MFC添加背景图片

1.在资源里导入一个bmp图片假设名称为IDB_BITMAP1

实现OnPaint方法

    CPaintDC dc(this); 
    CRect   rect;   
    GetClientRect(&rect);   
    CDC   dcMem;   
    dcMem.CreateCompatibleDC(&dc);   
    CBitmap   bmpBackground;   
    bmpBackground.LoadBitmap(IDB_BITMAP1);   
            //IDB_BITMAP是你自己的图对应的ID   
    BITMAP   bitmap;   
    bmpBackground.GetBitmap(&bitmap);   
    CBitmap   *pbmpOld=dcMem.SelectObject(&bmpBackground);   
    dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,   
    bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);  

posted @ 2014-06-09 11:29  li-peng  阅读(1562)  评论(0编辑  收藏  举报