Chinaunix首页 | 论坛 | 博客
  • 博客访问: 734205
  • 博文数量: 119
  • 博客积分: 137
  • 博客等级: 少校
  • 技术积分: 1582
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-28 16:39
文章分类

全部博文(119)

文章存档

2017年(3)

2016年(7)

2014年(1)

2013年(8)

2012年(20)

2011年(27)

2010年(53)

分类: C/C++

2010-04-30 08:59:52

1. 导入bitmap文件,生成ID  :IDB_BITMAP2
   导入时需要注意的是,只能导入bitmap的,可以将其他格式的图片转换成bmp的。
   转换时,选择24位位图,这样才能尽可能的保真,16色和256色的会严重丢失颜色。
2. h文件
protected:
    HICON m_hIcon;
// Generated message map functions
afx_msg void OnPaint();

3. cpp文件
1)
BEGIN_MESSAGE_MAP(类名, CDialog)
//{{AFX_MSG_MAP(CAutorunPacklist)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

2)void 类名::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_BITMAP2);   
                   //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);   

   CDialog::OnPaint();
}
}
阅读(2364) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-11-29 15:26:36

问题解决了,多谢