VS2010中 为图片添加背景图片_.NET_编程开发_程序员俱乐部
VS2010中 为图片添加背景图片
- 摘要:很简单的东西,嘿嘿voidCTestDlg::OnPaint(){if(IsIconic()){CPaintDCdc(this);//用于绘制的设备上下文SendMessage(WM_ICONERASEBKGND,reinterpret_cast<WPARAM>(dc.GetSafeHdc()),0);//使图标在工作区矩形中居中intcxIcon=GetSystemMetrics(SM_CXICON);intcyIcon=GetSystemMetrics(SM_CYICON)
- 标签:VS2010 2010 图片 为
很简单的东西,嘿嘿
class="dp-cpp" start="1">
- 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();
- }
- }
是不是很简单呢