VS2010中 为图片添加背景图片

来源:互联网 发布:拍照读取文字的软件 编辑:程序博客网 时间:2024/06/16 04:29
void CTestDlg::OnPaint(){if (IsIconic()){CPaintDC dc(this); // 用于绘制的设备上下文SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);// 使图标在工作区矩形中居中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;// 绘制图标dc.DrawIcon(x, y, m_hIcon);}else{CPaintDC dc(this);CRect rect;GetClientRect(&rect);//获取客户的的大小   CDC  memDC;CBitmap cBitmap;CBitmap* pOldMemBmp=NULL;cBitmap.LoadBitmap(IDB_BITMAP1);  memDC.CreateCompatibleDC(&dc);//创建一个设备对象上下文pOldMemBmp=memDC.SelectObject(&cBitmap);   BITMAP   bmp;   cBitmap.GetBitmap(&bmp);SetStretchBltMode(dc,STRETCH_HALFTONE);//据说能减少失真dc.StretchBlt(0,0,rect.Width(),rect.Height(),&memDC,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);  memDC.SelectObject(pOldMemBmp);CDialogEx::OnPaint();}}

原创粉丝点击