Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1589340
  • 博文数量: 441
  • 博客积分: 20087
  • 博客等级: 上将
  • 技术积分: 3562
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-19 15:35
文章分类

全部博文(441)

文章存档

2014年(1)

2012年(1)

2011年(8)

2010年(16)

2009年(15)

2008年(152)

2007年(178)

2006年(70)

分类: C/C++

2006-11-22 08:46:27

假设背景位图的ID为IDB_BITMAPBACKGROUND
void CDemoDialog::OnPaint()
{
    if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting
        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;
        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        /*++++++++++++++++++++++++++++++++++++++++++++*/
        /****         以下为添加的内容             ******/
        /*++++++++++++++++++++++++++++++++++++++++++++*/

        CPaintDC dc(this);
        CRect rect;
        GetClientRect(&rect);//得到窗体的大小
        CDC dcMem;
        dcMem.CreateCompatibleDC(&dc);
        CBitmap bmpBackground;
        bmpBackground.LoadBitmap(IDB_BITMAPBACKGROUND);//加载背景图片
        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);//把图贴上去,可以伸缩
        // dc.BitBlt(0, 0, bitMap.bmWidth, bitMap.bmHeight, &dcMem, 0, 0, SRCCOPY);
        // 不可以伸缩

      
/*++++++++++++++++++++++++++++++++++++++++++++*/
       /****            添加内容结束             ******/
       /*++++++++++++++++++++++++++++++++++++++++++++*/

       
      
//CDialog::OnPaint();//这一句不要
    }
}
阅读(916) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~